Author: dannas
Date: Thu Jul 29 12:43:56 2010
New Revision: 980427

URL: http://svn.apache.org/viewvc?rev=980427&view=rev
Log:
Make 'svn patch' do notifications for property hunks.

We use the same notification actions as for text hunks but replace
the headers to look like:
  '## -1,6 +1,7 ##'
instead of:
  '@@ -1,6 +1,7 @@'

Note that we don't specify what property a hunk belongs to (that information
is available in the reject file).

* subversion/svn/notify.c
  (notify): Print different hunk headers depending on whether we have
    a property or not.

* subversion/include/svn_wc.h
  (svn_wc_notify_t): Add 'is_prop_hunk' field.

* subversion/libsvn_client/patch.c
  (send_patch_notification): Iterate over the hunks of the property 
    targets in the same manner as is done for the text hunks.

* subversion/tests/cmdline/patch_tests.py
  (test_with_properties): Mark as XFail. We get a notification saying
    a hunk that adds one line to a non-existent property is beeing applied
    with offset 1.

Modified:
    subversion/trunk/subversion/include/svn_wc.h
    subversion/trunk/subversion/libsvn_client/patch.c
    subversion/trunk/subversion/svn/notify.c
    subversion/trunk/subversion/tests/cmdline/patch_tests.py

Modified: subversion/trunk/subversion/include/svn_wc.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_wc.h?rev=980427&r1=980426&r2=980427&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_wc.h (original)
+++ subversion/trunk/subversion/include/svn_wc.h Thu Jul 29 12:43:56 2010
@@ -1266,6 +1266,10 @@ typedef struct svn_wc_notify_t {
    * @since New in 1.7 */
   int hunk_fuzz;
 
+  /** If @c action relates to hunks, specifies whether the hunk is a
+   * property hunk or not. */
+  svn_boolean_t is_prop_hunk;
+
   /* NOTE: Add new fields at the end to preserve binary compatibility.
      Also, if you add fields here, you have to update svn_wc_create_notify
      and svn_wc_dup_notify. */

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=980427&r1=980426&r2=980427&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Thu Jul 29 12:43:56 2010
@@ -1487,6 +1487,7 @@ send_patch_notification(const patch_targ
     {
       int i;
       apr_pool_t *iterpool;
+      apr_hash_index_t *hash_index;
 
       iterpool = svn_pool_create(pool);
       for (i = 0; i < target->content_info->hunks->nelts; i++)
@@ -1518,9 +1519,56 @@ send_patch_notification(const patch_targ
             svn_diff_hunk_get_modified_length(hi->hunk);
           notify->hunk_matched_line = hi->matched_line;
           notify->hunk_fuzz = hi->fuzz;
+          /* ### Should is_prop_hunk be a field in hunk_info_t? */
+          notify->is_prop_hunk = FALSE;
 
           (*ctx->notify_func2)(ctx->notify_baton2, notify, pool);
         }
+
+      for (hash_index = apr_hash_first(pool, target->prop_targets);
+           hash_index;
+           hash_index = apr_hash_next(hash_index))
+        {
+          prop_patch_target_t *prop_target; 
+          
+          prop_target = svn__apr_hash_index_val(hash_index);
+
+          for (i = 0; i < prop_target->content_info->hunks->nelts; i++)
+            {
+              hunk_info_t *hi;
+
+              svn_pool_clear(iterpool);
+
+              hi = APR_ARRAY_IDX(prop_target->content_info->hunks, i,
+                                 hunk_info_t *);
+
+              if (hi->already_applied)
+                action = svn_wc_notify_patch_hunk_already_applied;
+              else if (hi->rejected)
+                action = svn_wc_notify_patch_rejected_hunk;
+              else
+                action = svn_wc_notify_patch_applied_hunk;
+
+              notify = svn_wc_create_notify(target->local_abspath
+                                                ? target->local_abspath
+                                                : target->local_relpath,
+                                            action, pool);
+              notify->hunk_original_start =
+                svn_diff_hunk_get_original_start(hi->hunk);
+              notify->hunk_original_length =
+                svn_diff_hunk_get_original_length(hi->hunk);
+              notify->hunk_modified_start =
+                svn_diff_hunk_get_modified_start(hi->hunk);
+              notify->hunk_modified_length =
+                svn_diff_hunk_get_modified_length(hi->hunk);
+              notify->hunk_matched_line = hi->matched_line;
+              notify->hunk_fuzz = hi->fuzz;
+              /* ### Should is_prop_hunk be a field in hunk_info_t? */
+              notify->is_prop_hunk = TRUE;
+
+              (*ctx->notify_func2)(ctx->notify_baton2, notify, pool);
+            }
+        }
       svn_pool_destroy(iterpool);
     }
 

Modified: subversion/trunk/subversion/svn/notify.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/notify.c?rev=980427&r1=980426&r2=980427&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/notify.c (original)
+++ subversion/trunk/subversion/svn/notify.c Thu Jul 29 12:43:56 2010
@@ -313,8 +313,13 @@ notify(void *baton, const svn_wc_notify_
           /* ### APR_INT64_T_FMT isn't translator-friendly */
           if (n->hunk_fuzz)
             {
-              s = _(">         applied hunk @@ -%lu,%lu +%lu,%lu @@ "
-                    "with offset %s");
+              if (n->is_prop_hunk)
+                s = _(">         applied hunk ## -%lu,%lu +%lu,%lu ## "
+                      "with offset %s");
+              else
+                s = _(">         applied hunk @@ -%lu,%lu +%lu,%lu @@ "
+                      "with offset %s");
+
               if ((err = svn_cmdline_printf(pool,
                                             apr_pstrcat(pool, s,
                                                         "%"APR_UINT64_T_FMT
@@ -329,8 +334,13 @@ notify(void *baton, const svn_wc_notify_
             }
           else
             {
-              s = _(">         applied hunk @@ -%lu,%lu +%lu,%lu @@ "
-                    "with offset %s");
+              if (n->is_prop_hunk)
+                s = _(">         applied hunk ## -%lu,%lu +%lu,%lu ## "
+                      "with offset %s");
+              else
+                s = _(">         applied hunk @@ -%lu,%lu +%lu,%lu @@ "
+                      "with offset %s");
+
               if ((err = svn_cmdline_printf(pool,
                                             apr_pstrcat(pool, s,
                                                         
"%"APR_UINT64_T_FMT"\n",
@@ -345,14 +355,25 @@ notify(void *baton, const svn_wc_notify_
         }
       else if (n->hunk_fuzz)
         {
-          if ((err = svn_cmdline_printf(pool,
+          if (n->is_prop_hunk)
+            err = svn_cmdline_printf(pool,
+                          _(">         applied hunk ## -%lu,%lu +%lu,%lu ## "
+                                        "with fuzz %d\n"),
+                                        n->hunk_original_start,
+                                        n->hunk_original_length,
+                                        n->hunk_modified_start,
+                                        n->hunk_modified_length,
+                                        n->hunk_fuzz);
+          else
+            err = svn_cmdline_printf(pool,
                           _(">         applied hunk @@ -%lu,%lu +%lu,%lu @@ "
                                         "with fuzz %d\n"),
                                         n->hunk_original_start,
                                         n->hunk_original_length,
                                         n->hunk_modified_start,
                                         n->hunk_modified_length,
-                                        n->hunk_fuzz)))
+                                        n->hunk_fuzz);
+          if (err)
             goto print_error;
 
         }
@@ -360,26 +381,48 @@ notify(void *baton, const svn_wc_notify_
 
     case svn_wc_notify_patch_rejected_hunk:
       nb->received_some_change = TRUE;
-      if ((err = svn_cmdline_printf(pool,
-                                    _(">         rejected hunk "
-                                      "@@ -%lu,%lu +%lu,%lu @@\n"),
-                                    n->hunk_original_start,
-                                    n->hunk_original_length,
-                                    n->hunk_modified_start,
-                                    n->hunk_modified_length)))
+
+      if (n->is_prop_hunk)
+        err = svn_cmdline_printf(pool,
+                                 _(">         rejected hunk "
+                                   "## -%lu,%lu +%lu,%lu ##\n"),
+                                 n->hunk_original_start,
+                                 n->hunk_original_length,
+                                 n->hunk_modified_start,
+                                 n->hunk_modified_length);
+      else
+        err = svn_cmdline_printf(pool,
+                                 _(">         rejected hunk "
+                                   "@@ -%lu,%lu +%lu,%lu @@\n"),
+                                 n->hunk_original_start,
+                                 n->hunk_original_length,
+                                 n->hunk_modified_start,
+                                 n->hunk_modified_length);
+      if (err)
         goto print_error;
       break;
 
     case svn_wc_notify_patch_hunk_already_applied:
       nb->received_some_change = TRUE;
-      if ((err = svn_cmdline_printf(pool,
-                                    _(">         hunk "
-                                      "@@ -%lu,%lu +%lu,%lu @@ "
-                                      "already applied\n"),
-                                    n->hunk_original_start,
-                                    n->hunk_original_length,
-                                    n->hunk_modified_start,
-                                    n->hunk_modified_length)))
+      if (n->is_prop_hunk)
+        err = svn_cmdline_printf(pool,
+                                 _(">         hunk "
+                                   "@@ -%lu,%lu +%lu,%lu @@ "
+                                   "already applied\n"),
+                                 n->hunk_original_start,
+                                 n->hunk_original_length,
+                                 n->hunk_modified_start,
+                                 n->hunk_modified_length);
+      else
+        err = svn_cmdline_printf(pool,
+                                 _(">         hunk "
+                                   "@@ -%lu,%lu +%lu,%lu @@ "
+                                   "already applied\n"),
+                                 n->hunk_original_start,
+                                 n->hunk_original_length,
+                                 n->hunk_modified_start,
+                                 n->hunk_modified_length);
+      if (err)
         goto print_error;
       break;
 

Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=980427&r1=980426&r2=980427&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Thu Jul 29 
12:43:56 2010
@@ -2621,7 +2621,7 @@ test_list = [ None,
               patch_with_ignore_whitespace,
               patch_replace_locally_deleted_file,
               patch_no_eol_at_eof,
-              patch_with_properties,
+              XFail(patch_with_properties),
               patch_same_twice,
               XFail(patch_dir_properties),
               XFail(patch_add_path_with_props),


Reply via email to