Author: julianfoad
Date: Tue Apr 21 11:15:37 2015
New Revision: 1675093

URL: http://svn.apache.org/r1675093
Log:
On the 'move-tracking-2' branch: In an 'svnmover diff' branch header line,
if the left and right sides are the same branch (which is common), say it
only once, for brevity.

Before:  --- diff branch B2 at /trunk : B2 at /trunk
After:   --- diff branch B2 at /trunk

* subversion/svnmover/svnmover.c
  (branch_id_and_path): New function, factored out...
  (svn_branch_diff_r): ... from here. Display the 'left' and 'right' branch
    ids and paths only once if they're the same.

* subversion/tests/cmdline/svnmover_tests.py
  (reported_br_diff): Allow specifying either the same or different branches
    for the left and right sides.
  (merge_edits_with_move,
   subbranches1,
   merge_deleted_subbranch,
   merge_added_subbranch,
   branch_to_subbranch_of_self): Adjust calls to reported_br_diff(): pass
    only one argument when the same branch is expected on both left and
    right sides.

Modified:
    subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c
    
subversion/branches/move-tracking-2/subversion/tests/cmdline/svnmover_tests.py

Modified: subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c?rev=1675093&r1=1675092&r2=1675093&view=diff
==============================================================================
--- subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c 
(original)
+++ subversion/branches/move-tracking-2/subversion/svnmover/svnmover.c Tue Apr 
21 11:15:37 2015
@@ -1151,6 +1151,16 @@ svn_branch_diff_func_t(svn_editor3_t *ed
                        const char *header,
                        apr_pool_t *scratch_pool);
 
+/*  */
+static char *
+branch_id_and_path(svn_branch_instance_t *branch,
+                   apr_pool_t *result_pool)
+{
+  return apr_psprintf(result_pool, "%s at /%s",
+                      svn_branch_instance_get_id(branch, result_pool),
+                      svn_branch_get_root_rrpath(branch, result_pool));
+}
+
 /* Display differences, referring to paths, recursing into sub-branches */
 static svn_error_t *
 svn_branch_diff_r(svn_editor3_t *editor,
@@ -1167,27 +1177,33 @@ svn_branch_diff_r(svn_editor3_t *editor,
   if (!left)
     {
       header = apr_psprintf(scratch_pool,
-                 "--- added branch %s at /%s\n",
-                 svn_branch_instance_get_id(right->branch, scratch_pool),
-                 svn_branch_get_root_rrpath(right->branch, scratch_pool));
+                 "--- added branch %s\n",
+                 branch_id_and_path(right->branch, scratch_pool));
       printf("%s%s", prefix, header);
     }
   else if (!right)
     {
       header = apr_psprintf(scratch_pool,
-                 "--- deleted branch %s at /%s\n",
-                 svn_branch_instance_get_id(left->branch, scratch_pool),
-                 svn_branch_get_root_rrpath(left->branch, scratch_pool));
+                 "--- deleted branch %s\n",
+                 branch_id_and_path(left->branch, scratch_pool));
       printf("%s%s", prefix, header);
     }
   else
     {
-      header = apr_psprintf(scratch_pool,
-                 "--- diff branch %s at /%s : %s at /%s\n",
-                 svn_branch_instance_get_id(left->branch, scratch_pool),
-                 svn_branch_get_root_rrpath(left->branch, scratch_pool),
-                 svn_branch_instance_get_id(right->branch, scratch_pool),
-                 svn_branch_get_root_rrpath(right->branch, scratch_pool));
+      if (strcmp(branch_id_and_path(left->branch, scratch_pool),
+                 branch_id_and_path(right->branch, scratch_pool)) == 0)
+        {
+          header = apr_psprintf(
+                     scratch_pool, "--- diff branch %s\n",
+                     branch_id_and_path(left->branch, scratch_pool));
+        }
+      else
+        {
+          header = apr_psprintf(
+                     scratch_pool, "--- diff branch %s : %s\n",
+                     branch_id_and_path(left->branch, scratch_pool),
+                     branch_id_and_path(right->branch, scratch_pool));
+        }
       SVN_ERR(diff_func(editor, left, right, prefix, header, scratch_pool));
     }
 

Modified: 
subversion/branches/move-tracking-2/subversion/tests/cmdline/svnmover_tests.py
URL: 
http://svn.apache.org/viewvc/subversion/branches/move-tracking-2/subversion/tests/cmdline/svnmover_tests.py?rev=1675093&r1=1675092&r2=1675093&view=diff
==============================================================================
--- 
subversion/branches/move-tracking-2/subversion/tests/cmdline/svnmover_tests.py 
(original)
+++ 
subversion/branches/move-tracking-2/subversion/tests/cmdline/svnmover_tests.py 
Tue Apr 21 11:15:37 2015
@@ -539,12 +539,16 @@ def reported_br_params(path1, path2):
     subbranch_fullpath = path1 + '/' + path2
   return subbranch_rpath, subbranch_fullpath
 
-def reported_br_diff(path1, path2):
+def reported_br_diff(path1, path2=None):
   """Return expected header lines for diff of a branch, or subtree in a branch.
 
      PATH1 is the 'left' and PATH2 the 'right' side path. Both are full paths
-     from the repo root.
+     from the repo root. If PATH2 is None, the branch ids and paths are
+     expected to be *the same* on both sides; otherwise the branch ids and/or
+     paths are expected to be *different* on each side.
   """
+  if path2 is None:
+    return [r'--- diff branch B[0-9.]+ at /%s' % (re.escape(path1),)]
   return [r'--- diff branch B[0-9.]+ at /%s : B[0-9.]+ at /%s' % (
            re.escape(path1), re.escape(path2))]
 
@@ -651,7 +655,7 @@ def merge_edits_with_move(sbox):
 
   # on trunk: make edits under 'foo' (r4)
   test_svnmover2(sbox, 'trunk',
-                 reported_br_diff('trunk', 'trunk') +
+                 reported_br_diff('trunk') +
                  reported_del('lib/foo/x') +
                  reported_move('lib/foo/y', 'lib/foo/y2') +
                  reported_add('lib/foo/z'),
@@ -661,19 +665,19 @@ def merge_edits_with_move(sbox):
 
   # on branch: move/rename 'foo' (r5)
   test_svnmover2(sbox, 'branches/br1',
-                 reported_br_diff('branches/br1', 'branches/br1') +
+                 reported_br_diff('branches/br1') +
                  reported_move('lib/foo', 'bar'),
                 'mv lib/foo bar')
 
   # merge the move to trunk (r6)
   test_svnmover2(sbox, '',
-                 reported_br_diff('trunk', 'trunk') +
+                 reported_br_diff('trunk') +
                  reported_move('lib/foo', 'bar'),
                 'merge branches/br1@5 trunk trunk@2')
 
   # merge the edits in trunk (excluding the merge r6) to branch (r7)
   test_svnmover2(sbox, '',
-                 reported_br_diff('branches/br1', 'branches/br1') +
+                 reported_br_diff('branches/br1') +
                  reported_del('bar/x') +
                  reported_move('bar/y', 'bar/y2') +
                  reported_add('bar/z'),
@@ -819,7 +823,7 @@ def move_branch_within_same_parent_branc
 
   # move trunk
   test_svnmover2(sbox, '',
-                   reported_br_diff('', '') +
+                   reported_br_diff('') +
                    reported_add('D') +
                    reported_add('D/E') +
                    reported_br_move('trunk', 'D/E/trunk2'),
@@ -829,7 +833,7 @@ def move_branch_within_same_parent_branc
 
   # move trunk and also modify it
   test_svnmover2(sbox, '',
-                   reported_br_diff('', '') +
+                   reported_br_diff('') +
                    reported_del('D') +
                    reported_del('D/E') +
                    reported_br_move('D/E/trunk2', 'trunk') +
@@ -841,7 +845,7 @@ def move_branch_within_same_parent_branc
 
   # move a subbranch of trunk
   test_svnmover2(sbox, 'trunk',
-                 reported_br_diff('trunk', 'trunk') +
+                 reported_br_diff('trunk') +
                  reported_br_move('sub', 'sub2'),
                 'mv sub sub2'
                 )
@@ -901,7 +905,7 @@ def restructure_repo_ttb_projects_to_pro
 
   # merge the branch to trunk (r7)
   test_svnmover2(sbox, '',
-                 reported_br_diff('trunk', 'trunk') +
+                 reported_br_diff('trunk') +
                  reported_move('proj1/lib/foo', 'proj1/bar') +
                  reported_add('proj2') +
                  reported_add('proj2/bar') +
@@ -910,7 +914,7 @@ def restructure_repo_ttb_projects_to_pro
 
   # merge the edits in trunk (excluding the merge r6) to branch (r7)
   test_svnmover2(sbox, '',
-                 reported_br_diff('branches/br1', 'branches/br1') +
+                 reported_br_diff('branches/br1') +
                  reported_del('proj1/bar/x') +
                  reported_move('proj1/bar/y', 'proj1/bar/y2') +
                  reported_add('proj1/bar/z'),
@@ -925,7 +929,7 @@ def restructure_repo_ttb_projects_to_pro
                 )
   # Rearrange: {t,t,b}/{proj} => {proj}/{t,t,b}
   test_svnmover2(sbox, '',
-                 reported_br_diff('', '') +
+                 reported_br_diff('') +
                  reported_br_add('proj1/trunk') +
                  reported_br_add('proj2/trunk') +
                  reported_br_add('proj1/branches/br1') +
@@ -937,7 +941,7 @@ def restructure_repo_ttb_projects_to_pro
                 )
   # Delete the remaining root dir of the old trunk and branches
   test_svnmover2(sbox, '',
-                 reported_br_diff('', '') +
+                 reported_br_diff('') +
                  reported_del('branches') +
                  reported_br_del('branches/br1') +
                  reported_br_del('trunk'),
@@ -996,7 +1000,7 @@ def restructure_repo_projects_ttb_to_ttb
 
     # merge trunk to branch
     test_svnmover2(sbox, proj,
-                   reported_br_diff(proj + '/branches/br1', proj + 
'/branches/br1') +
+                   reported_br_diff(proj + '/branches/br1') +
                    reported_del('bar/x') +
                    reported_move('bar/y', 'bar/y2') +
                    reported_add('bar/z'),
@@ -1020,9 +1024,9 @@ def restructure_repo_projects_ttb_to_ttb
   # of the 'mv' command, where it performs moving by 'branch-and-delete'.
   for proj in ['proj1', 'proj2']:
     test_svnmover2(sbox, '',
-                   reported_br_diff('', '') +
+                   reported_br_diff('') +
                    reported_br_del(proj + '/trunk') +
-                   reported_br_diff('trunk', 'trunk') +
+                   reported_br_diff('trunk') +
                    reported_add(proj) +
                    reported_add(proj + '/README') +
                    reported_add(proj + '/lib') +
@@ -1034,9 +1038,9 @@ def restructure_repo_projects_ttb_to_ttb
                    'rm', proj + '/trunk',
                    )
     test_svnmover2(sbox, '',
-                   reported_br_diff('', '') +
+                   reported_br_diff('') +
                    reported_br_del(proj + '/branches/br1') +
-                   reported_br_diff('branches/br1', 'branches/br1') +
+                   reported_br_diff('branches/br1') +
                    reported_add(proj) +
                    reported_add(proj + '/README') +
                    reported_add(proj + '/bar') +
@@ -1106,17 +1110,17 @@ def subbranches1(sbox):
 
   # merge 'branches/foo' to 'trunk'
   test_svnmover2(sbox, '',
-                 reported_br_diff('trunk', 'trunk') +
+                 reported_br_diff('trunk') +
                  reported_add('docs') +
                  reported_move('libsvn_fs_fs/file.c', 'libsvn_fs_fs/file2.c') +
-                 reported_br_diff('trunk/libsvn_fs_x', 'trunk/libsvn_fs_x') +
+                 reported_br_diff('trunk/libsvn_fs_x') +
                  reported_add('reps') +
                  reported_move('file.c', 'reps/file.c'),
                  'merge branches/foo trunk trunk@4')
 
   # merge 'trunk/libsvn_fs_fs' to 'trunk/libsvn_fs_x'
   test_svnmover2(sbox, '',
-                 reported_br_diff('trunk/libsvn_fs_x', 'trunk/libsvn_fs_x') +
+                 reported_br_diff('trunk/libsvn_fs_x') +
                  reported_move('reps/file.c', 'reps/file2.c'),
                  'merge trunk/libsvn_fs_fs trunk/libsvn_fs_x 
trunk/libsvn_fs_fs@4')
 
@@ -1143,7 +1147,7 @@ def merge_deleted_subbranch(sbox):
   #
   # This should delete the subbranch 'lib2'
   test_svnmover2(sbox, '',
-                 reported_br_diff('branches/foo', 'branches/foo') +
+                 reported_br_diff('branches/foo') +
                  reported_br_del('branches/foo', 'lib2'),
                  'merge trunk branches/foo trunk@' + str(yca_rev))
 
@@ -1166,7 +1170,7 @@ def merge_added_subbranch(sbox):
   #
   # This should add the subbranch 'lib2'
   test_svnmover2(sbox, '',
-                 reported_br_diff('branches/foo', 'branches/foo') +
+                 reported_br_diff('branches/foo') +
                  reported_br_add('branches/foo', 'lib2'),
                  'merge trunk branches/foo trunk@' + str(yca_rev))
 
@@ -1190,7 +1194,7 @@ def branch_to_subbranch_of_self(sbox):
   #
   # This should not recurse infinitely
   test_svnmover2(sbox, '',
-                 reported_br_diff('trunk/foo/lib2', 'trunk/foo/lib2') +
+                 reported_br_diff('trunk/foo/lib2') +
                  reported_br_add('trunk/foo/lib2', 'x') +
                  reported_br_nested_add('trunk/foo/lib2/x', 'foo') +
                  reported_br_nested_add('trunk/foo/lib2/x/foo', 'lib2'),


Reply via email to