largefiles: add --all-largefiles flag to clone (issue3188)
authorNa'Tosha Bard <natosha@unity3d.com>
Fri, 11 May 2012 23:11:43 +0200
changeset 16644 98a9266db803
parent 16643 24dbef11f477
child 16645 9a21fc2c7d32
largefiles: add --all-largefiles flag to clone (issue3188)
hgext/largefiles/overrides.py
hgext/largefiles/uisetup.py
tests/test-largefiles.t
--- a/hgext/largefiles/overrides.py	Fri May 04 16:00:33 2012 -0500
+++ b/hgext/largefiles/overrides.py	Fri May 11 23:11:43 2012 +0200
@@ -697,6 +697,33 @@
         ui.status(_("%d largefiles cached\n") % numcached)
     return result
 
+def overrideclone(orig, ui, source, dest=None, **opts):
+    result = hg.clone(ui, opts, source, dest,
+                      pull=opts.get('pull'),
+                      stream=opts.get('uncompressed'),
+                      rev=opts.get('rev'),
+                      update=True, # required for successful walkchangerevs
+                      branch=opts.get('branch'))
+    if result is None:
+        return True
+    totalsuccess = 0
+    totalmissing = 0
+    if opts.get('all_largefiles'):
+        sourcerepo, destrepo = result
+        matchfn = scmutil.match(destrepo[None],
+                                [destrepo.wjoin(lfutil.shortname)], {})
+        def prepare(ctx, fns):
+            pass
+        for ctx in cmdutil.walkchangerevs(destrepo, matchfn, {'rev' : None},
+                                          prepare):
+            success, missing = lfcommands.cachelfiles(ui, destrepo, ctx.node())
+            totalsuccess += len(success)
+            totalmissing += len(missing)
+        ui.status(_("%d additional largefiles cached\n") % totalsuccess)
+        if totalmissing > 0:
+            ui.status(_("%d largefiles failed to download\n") % totalmissing)
+    return totalmissing != 0
+
 def overriderebase(orig, ui, repo, **opts):
     repo._isrebasing = True
     try:
--- a/hgext/largefiles/uisetup.py	Fri May 04 16:00:33 2012 -0500
+++ b/hgext/largefiles/uisetup.py	Fri May 11 23:11:43 2012 +0200
@@ -70,6 +70,12 @@
                                    overrides.overrideupdate)
     entry = extensions.wrapcommand(commands.table, 'pull',
                                    overrides.overridepull)
+    entry = extensions.wrapcommand(commands.table, 'clone',
+                                   overrides.overrideclone)
+    cloneopt = [('', 'all-largefiles', None,
+                 _('download all versions of all largefiles'))]
+
+    entry[1].extend(cloneopt)
     entry = extensions.wrapcommand(commands.table, 'cat',
                                    overrides.overridecat)
     entry = extensions.wrapfunction(merge, '_checkunknownfile',
--- a/tests/test-largefiles.t	Fri May 04 16:00:33 2012 -0500
+++ b/tests/test-largefiles.t	Fri May 11 23:11:43 2012 +0200
@@ -432,11 +432,21 @@
   large11
   $ cat sub/large2
   large22
+  $ cd ..
+
+Test cloning with --all-largefiles flag
+
+  $ rm -Rf ${USERCACHE}/*
+  $ hg clone --all-largefiles a a-backup
+  updating to branch default
+  5 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  getting changed largefiles
+  3 largefiles updated, 0 removed
+  8 additional largefiles cached
 
 Rebasing between two repositories does not revert largefiles to old
 revisions (this was a very bad bug that took a lot of work to fix).
 
-  $ cd ..
   $ hg clone a d
   updating to branch default
   5 files updated, 0 files merged, 0 files removed, 0 files unresolved