[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Re: issue #785 (was Re: wanted: nibble-sized coding task)

From: Brian Denny <brian_at_briandenny.net>
Date: 2003-03-08 21:56:22 CET

Okay, here's my first stab at this issue. It passes 'make check',
new test included. (And i tried the new test without the merge-cmd
change to make sure it failed).

It probably should have more tests (i only tested one subcase, so far --
svn merge -rX:Y URL). But AFAICT the existing python tests aren't
super-agressive about testing every possible syntactic variation,
either... let me know what you think.

-brian

Log:

  Resolves issue #785:

  * merge-cmd.c
    (svn_cl__merge): If no target path was specified, try to infer it
    from the source path(s).

  * merge_tests.py
    (merge_without_target): New test function. Merges a file, specifying
    a revision range and source URL but no target path.

Index: subversion/clients/cmdline/merge-cmd.c
===================================================================
--- subversion/clients/cmdline/merge-cmd.c (revision 5216)
+++ subversion/clients/cmdline/merge-cmd.c (working copy)
@@ -126,6 +126,25 @@
         targetpath = "";
     }
 
+ /* If no targetpath was specified, see if we can infer it from the
+ sourcepaths. */
+ if (! strcmp (targetpath, ""))
+ {
+ char *sp1_basename, *sp2_basename;
+ sp1_basename = svn_path_basename (sourcepath1, pool);
+ sp2_basename = svn_path_basename (sourcepath2, pool);
+
+ if (! strcmp (sp1_basename, sp2_basename))
+ {
+ svn_node_kind_t kind;
+ SVN_ERR (svn_io_check_path (sp1_basename, &kind, pool));
+ if (kind == svn_node_file)
+ {
+ targetpath = sp1_basename;
+ }
+ }
+ }
+
   if (opt_state->start_revision.kind == svn_opt_revision_unspecified)
     opt_state->start_revision.kind = svn_opt_revision_head;
   if (opt_state->end_revision.kind == svn_opt_revision_unspecified)
Index: subversion/tests/clients/cmdline/merge_tests.py
===================================================================
--- subversion/tests/clients/cmdline/merge_tests.py (revision 5216)
+++ subversion/tests/clients/cmdline/merge_tests.py (working copy)
@@ -938,6 +938,97 @@
 
 #----------------------------------------------------------------------
 
+def merge_without_target (sbox):
+ "merging a file, with no explicitly specified target path"
+
+ if sbox.build():
+ return 1
+
+ wc_dir = sbox.wc_dir
+ # url = os.path.join(svntest.main.test_area_url, sbox.repo_dir)
+
+ # Change mu for revision 2
+ mu_path = os.path.join(wc_dir, 'A', 'mu')
+ mu_text = ""
+ for x in range(2,11):
+ mu_text = mu_text + '\nThis is line ' + `x` + ' in mu'
+ mu_text += "\n"
+ svntest.main.file_append(mu_path, mu_text)
+
+ # Create expected output tree for initial commit
+ expected_output = wc.State(wc_dir, {
+ 'A/mu' : Item(verb='Sending'),
+ })
+
+ # Create expected status tree; all local revisions should be at 1,
+ # but mu should be at revision 2.
+ expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
+ expected_status.tweak(wc_rev=1)
+ expected_status.tweak('A/mu', wc_rev=2)
+
+ # Initial commit.
+ if svntest.actions.run_and_verify_commit (wc_dir,
+ expected_output,
+ expected_status,
+ None,
+ None, None, None, None,
+ wc_dir):
+ return 1
+
+ # Make the "other" working copy
+ other_wc = wc_dir + '.other'
+ svntest.actions.duplicate_dir(wc_dir, other_wc)
+
+ # Now commit some more mods from the original working copy, to
+ # produce revision 3.
+ additional_mu_text = "" # saving mu text changes from previous commit
+ for x in range(2,11):
+ additional_mu_text = additional_mu_text \
+ + '\nThis is additional line ' + `x` + ' in mu'
+ additional_mu_text += "\n"
+ svntest.main.file_append(mu_path, additional_mu_text)
+
+ # Created expected output tree for 'svn ci'
+ expected_output = wc.State(wc_dir, {
+ 'A/mu' : Item(verb='Sending'),
+ })
+
+ # Create expected status tree.
+ expected_status = svntest.actions.get_virginal_state(wc_dir, 3)
+ expected_status.tweak(wc_rev=1)
+ expected_status.tweak('A/mu', wc_rev=3)
+
+ # Commit revision 3.
+ if svntest.actions.run_and_verify_commit(wc_dir,
+ expected_output,
+ expected_status,
+ None,
+ None, None, None, None,
+ wc_dir):
+ return 1
+
+ # Make local mods in wc.other
+ other_mu_path = os.path.join(other_wc, 'A', 'mu')
+ svntest.main.file_append(other_mu_path, additional_mu_text)
+
+ # Try the merge without an explicit target; it should succeed.
+ # Can't use run_and_verify_merge cuz it expects a directory argument.
+ # We don't care about the output anyway; that's tested elsewhere.
+ # If we don't get an error, all is well.
+ mu_url = os.path.join(svntest.main.current_repo_url, 'A', 'mu')
+ was_cwd = os.getcwd()
+ try:
+ os.chdir(os.path.join(other_wc, 'A'))
+ out, err = svntest.main.run_svn(0, 'merge', '-r', '1:3',
+ mu_url)
+ if err:
+ print err
+ return 1
+ finally:
+ os.chdir(was_cwd)
+
+#----------------------------------------------------------------------
+
 ########################################################################
 # Run the tests
 
@@ -948,6 +1039,7 @@
               add_with_history,
               delete_file_and_dir,
               simple_property_merges,
+ merge_without_target,
               # merge_one_file, # See issue #1150.
               # property_merges_galore, # Would be nice to have this.
               # tree_merges_galore, # Would be nice to have this.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Mar 8 22:01:13 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.