largefiles: delegate to the wrapped clone command stable
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 09 Sep 2012 12:43:24 -0400
branchstable
changeset 17601 6e2ab601be3f
parent 17600 3a1c6b64e052
child 17602 ccd28eca37f6
child 17628 133d13e44544
child 17656 587c353beac1
largefiles: delegate to the wrapped clone command This allows the wrapped command's validation code to run (which is currently only to ensure 'noupdate' and 'updaterev' aren't both specified), the copy/pasted unpacking of hg.clone() args to be removed, and any future changes to the base command (however unlikely) to be inherited by largefiles. Unfortunately, the command override can't be swapped entirely for an hg.clone() override because the extra --all-largefiles arg needs to be injected. It also isn't enough to call the wrapped clone command and leave the caching code after it, because the file caching code needs access to the destination repo, which is only available from hg.clone(). An alternative would be to use the dest path in the clone command override to re-obtain a reference to the repo. A slight deviation from the regular hg.clone() function is that the repo is NOT deleted if the caching fails, but that was also the previous behavior. Maybe it should for consistency?
hgext/largefiles/overrides.py
hgext/largefiles/uisetup.py
tests/test-largefiles.t
--- a/hgext/largefiles/overrides.py	Sun Sep 09 12:09:53 2012 -0400
+++ b/hgext/largefiles/overrides.py	Sun Sep 09 12:43:24 2012 -0400
@@ -727,15 +727,13 @@
             raise util.Abort(_(
             '--all-largefiles is incompatible with non-local destination %s' %
             d))
-    result = hg.clone(ui, opts, source, dest,
-                      pull=opts.get('pull'),
-                      stream=opts.get('uncompressed'),
-                      rev=opts.get('rev'),
-                      update=opts.get('updaterev') or not opts.get('noupdate'),
-                      branch=opts.get('branch'))
-    if result is None:
-        return True
-    if opts.get('all_largefiles'):
+
+    return orig(ui, source, dest, **opts)
+
+def hgclone(orig, ui, opts, *args, **kwargs):
+    result = orig(ui, opts, *args, **kwargs)
+
+    if result is not None and opts.get('all_largefiles'):
         sourcerepo, destrepo = result
         repo = destrepo.local()
 
@@ -750,8 +748,11 @@
         # Caching is implicitly limited to 'rev' option, since the dest repo was
         # truncated at that point.
         success, missing = lfcommands.downloadlfiles(ui, repo, None)
-        return missing != 0
-    return result is None
+
+        if missing != 0:
+            return None
+
+    return result
 
 def overriderebase(orig, ui, repo, **opts):
     repo._isrebasing = True
--- a/hgext/largefiles/uisetup.py	Sun Sep 09 12:09:53 2012 -0400
+++ b/hgext/largefiles/uisetup.py	Sun Sep 09 12:43:24 2012 -0400
@@ -77,8 +77,9 @@
                                    overrides.overrideclone)
     cloneopt = [('', 'all-largefiles', None,
                  _('download all versions of all largefiles'))]
+    entry[1].extend(cloneopt)
+    entry = extensions.wrapfunction(hg, 'clone', overrides.hgclone)
 
-    entry[1].extend(cloneopt)
     entry = extensions.wrapcommand(commands.table, 'cat',
                                    overrides.overridecat)
     entry = extensions.wrapfunction(merge, '_checkunknownfile',
--- a/tests/test-largefiles.t	Sun Sep 09 12:09:53 2012 -0400
+++ b/tests/test-largefiles.t	Sun Sep 09 12:43:24 2012 -0400
@@ -717,6 +717,12 @@
   3 largefiles updated, 0 removed
   $ cd ..
 
+Ensure base clone command argument validation
+
+  $ hg clone -U -u 0 a a-clone-failure
+  abort: cannot specify both --noupdate and --updaterev
+  [255]
+
   $ hg clone --all-largefiles a ssh://localhost/a
   abort: --all-largefiles is incompatible with non-local destination ssh://localhost/a
   [255]