Giovanni Bajo wrote:
Yes, your last version is fine. You're still missing a comment near "False" for
"help" though: it's needed because a bare False really doesn't mean anything.
You also want to update the usage line of integrated and avail in their help
screen: they say [PATH] but should now say [PATH or URL].

Send me an updated version and I will commit it.


I have been thinking some more about your suggestion to make the "accepts url" flag a bit more descriptive and have another version of the patch for you all to take a look at. It s quite similar, but now the information about the command accepting an URL as argument or not is contained in a string array in the command table. Right now this flag array can contain the values "WC" and/or "URL" (help's array is empty). This flag array, while being more descriptive, also might be used in the future for other command characteristics.

The patch and commit message are attached to this message.

:.:: mattias
Index: svnmerge_test.py
===================================================================
--- svnmerge_test.py    (revision 19720)
+++ svnmerge_test.py    (working copy)
@@ -485,6 +485,23 @@
         self.svnmerge("block", error=True, match=r"working dir")
         self.svnmerge("unblock", error=True, match=r"working dir")
 
+    def testAcceptsURL(self):
+        url = self.test_repo_url + "/branches/test-branch"
+        self.svnmerge("init")
+        self.launch("svn commit -F svnmerge-commit-message.txt",
+                    match=r"Committed revision")
+        self.svnmerge("avail", error=False, match=r"^9-10$")
+        self.svnmerge("avail " + url, error=False, match=r"^9-10$")
+        self.svnmerge("integrated", error=False, match=r"^3-6$")
+        self.svnmerge("integrated " + url, error=False, match=r"^3-6$")
+
+        self.svnmerge("merge " + url, error=True, \
+                      match=r"is not a subversion working directory")
+        self.svnmerge("block " + url, error=True, \
+                      match=r"is not a subversion working directory")
+        self.svnmerge("unblock " + url, error=True, \
+                      match=r"is not a subversion working directory")
+        
     def testCheckNoIntegrationInfo(self):
         self.svnmerge("avail", error=True, match=r"no integration")
         self.svnmerge("integrated", error=True, match=r"no integration")
Index: svnmerge.py
===================================================================
--- svnmerge.py (revision 19720)
+++ svnmerge.py (working copy)
@@ -262,6 +262,24 @@
     if out and out[0].strip():
         error('"%s" has local modifications; it must be clean' % dir)
 
+def validate_branch(branch, flags):
+    """Check that branch is either a subversion working copy or URL,
+    depending on what flags are set."""
+    branch_ok = False
+    if "WC" in flags:
+        branch_ok = is_wc(branch)
+    if not branch_ok and "URL" in flags:
+        branch_ok = is_url(branch)
+
+    if not branch_ok:
+        if "WC" in flags and "URL" in flags:
+            error('"%s" is not a subversion working directory or URL'
+                  % branch)
+        elif "WC" in flags:
+            error('"%s" is not a subversion working directory' % branch)
+        elif "URL" in flags:
+            error('"%s" is not a subversion URL' % branch)
+
 class RevisionLog:
     """
     A log of the revisions which affected a given URL between two
@@ -1302,7 +1320,8 @@
 class CommandOpts:
     class Cmd:
         def __init__(self, *args):
-            self.name, self.func, self.usage, self.help, self.opts = args
+            self.name, self.func, self.usage, self.help, self.flags, \
+            self.opts = args
         def short_help(self):
             return self.help.split(".")[0]
         def __str__(self):
@@ -1339,6 +1358,7 @@
             "help [COMMAND]",
             "Display help for a specific command. If COMMAND is omitted, "
             "display brief command description.",
+            [], # no flags
             [])
 
     def _cmd_help(self, cmd=None, *args):
@@ -1575,13 +1595,14 @@
     current working directory (searching back for the branch point); in this
     case, %s assumes that no revision has been integrated yet since
     the branch point (unless you teach it with --revision).""" % NAME,
+    ["WC"], # only accepts working copy
     [
         "-f", "-r", # import common opts
     ]),
 
     "avail": (action_avail,
-    "avail [OPTION...] [PATH]",
-    """Show unmerged revisions available for PATH as a revision list.
+    "avail [OPTION...] [PATH or URL]",
+    """Show unmerged revisions available for PATH (or URL) as a revision list.
     If --revision is given, the revisions shown will be limited to those
     also specified in the option.
 
@@ -1593,6 +1614,7 @@
     originated in the branch itself!).  svnmerge can not show these
     so-called "reflected" revisions if you specify the --bidirectional
     or -b command line option.""",
+    ["WC", "URL"], # accepts URL and working copy
     [
         Option("-A", "--all",
                dest="avail-showwhat",
@@ -1619,10 +1641,11 @@
     ]),
 
     "integrated": (action_integrated,
-    "integrated [OPTION...] [PATH]",
-    """Show merged revisions available for PATH as a revision list.
+    "integrated [OPTION...] [PATH or URL]",
+    """Show merged revisions available for PATH (or URL) as a revision list.
     If --revision is given, the revisions shown will be limited to
     those also specified in the option.""",
+    ["WC", "URL"], # accepts URL and working copy
     [
         Option("-d", "--diff",
                dest="integrated-display",
@@ -1657,6 +1680,7 @@
     already happened, so that it can record it and not offer that
     revision for merge anymore.  Conversely, when there are revisions
     which should not be merged, use '%s block'.""" % (NAME, NAME),
+    ["WC"], # only accepts working copy
     [
         "-b", "-f", "-r", "-S", "-M", # import common opts
     ]),
@@ -1671,6 +1695,7 @@
     into the branch.  Instead, use '%s merge --record-only', which
     records that a merge happened (as opposed to a merge which should
     not happen).""" % NAME,
+    ["WC"], # only accepts working copy
     [
         "-f", "-r", "-S", # import common opts
     ]),
@@ -1679,6 +1704,7 @@
     "unblock [OPTION...] [PATH]",
     """Revert the effect of '%s block'. If --revision is omitted, all the
     blocked revisions are unblocked""" % NAME,
+    ["WC"], # only accepts working copy
     [
         "-f", "-r", "-S", # import common opts
     ]),
@@ -1690,12 +1716,12 @@
     are multiple heads, use --head to indicate which head you want to forget
     about.
     """,
+    ["WC"], # only accepts working copy
     [
         "-f", "-S", # import common opts
     ]),
 }
-
-
+    
 def main(args):
     global opts
 
@@ -1728,9 +1754,7 @@
     else:
         assert False, "command not handled: %s" % cmd
 
-    # Validate branch_dir
-    if not is_wc(branch_dir):
-        error('"%s" is not a subversion working directory' % branch_dir)
+    validate_branch(branch_dir, cmd.flags)
 
     # Extract the integration info for the branch_dir
     branch_props = get_merge_props(branch_dir)
Sub-commands avail and integrated now accept either URL or
working-copy path as argument.

* contrib/client-side/svnmerge.py:
  (command_table): Added a new member to the tuple. This member is an 
  array containing flags describing the command. This point the flags
  are the strings WC and URL, telling us what kind of branch argument it
  accepts. The documentation has also been updated to reflect the changes
  of this patch.

  (CommandOpts#__init__): This ctor now accepts an extra argument containing
  the flags of the command

  (CommandOpts#_add_builtins): When command help is added to the command
  table we need to also provide an empty flags array.

  (validate_branch): This function validates a branch argument based on
  what flags are set for the command.

  (main): Calls the new function validate_branch() instead of having that
  code inline.

* contrib/client-side/svnmerge_test.py:
  (TestCase_TestRepo#testAcceptsURL): Added test case for this feature.
_______________________________________________
Svnmerge mailing list
[email protected]
http://www.orcaware.com/mailman/listinfo/svnmerge

Reply via email to