diff hgext/largefiles/lfcommands.py @ 16691:7d6a660ca151

largefiles: refactor downloading of all largefiles to generic function
author Na'Tosha Bard <natosha@unity3d.com>
date Sat, 12 May 2012 09:59:01 +0200
parents e34106fa0dc3
children 28001e8a5149
line wrap: on
line diff
--- a/hgext/largefiles/lfcommands.py	Sat May 12 20:06:04 2012 +0200
+++ b/hgext/largefiles/lfcommands.py	Sat May 12 09:59:01 2012 +0200
@@ -11,7 +11,8 @@
 import os
 import shutil
 
-from mercurial import util, match as match_, hg, node, context, error, cmdutil
+from mercurial import util, match as match_, hg, node, context, error, \
+    cmdutil, scmutil
 from mercurial.i18n import _
 
 import lfutil
@@ -400,6 +401,23 @@
 
     return ([], [])
 
+def downloadlfiles(ui, repo, rev=None):
+    matchfn = scmutil.match(repo[None],
+                            [repo.wjoin(lfutil.shortname)], {})
+    def prepare(ctx, fns):
+        pass
+    totalsuccess = 0
+    totalmissing = 0
+    for ctx in cmdutil.walkchangerevs(repo, matchfn, {'rev' : rev},
+                                      prepare):
+        success, missing = cachelfiles(ui, repo, 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 totalsuccess, totalmissing
+
 def updatelfiles(ui, repo, filelist=None, printmessage=True):
     wlock = repo.wlock()
     try: