diff hgext/largefiles/overrides.py @ 16578:43fb170a23bd

largefiles: make archive -S store largefiles instead of standins This is essentially a copy of largefile's override of archive() in the archival class, adapted for overriding hgsubrepo's archive(). That means decoding isn't taken into consideration, nor is .hg_archival.txt generated (the same goes for regular subrepos). Unlike subrepos, but consistent with largefile's handling of the top repo, ui.progress() is *not* called. This should probably be refactored at some point, but at least this generates the archives properly for now. Previously, the standins were ignored and the largefiles were archived only for the top level repo. Long term, it would probably be most desirable to figure out how to tweak archival's archive() if necessary such that largefiles doesn't need to override it completely just to special case the translating of standins to the real files. Largefiles will already return a context with the true largefiles instead of the standins if lfilesrepo's lfstatus is True- perhaps this can be leveraged?
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 03 May 2012 21:32:57 -0400
parents 597ddcb41b32
children 5cf18921bb7b
line wrap: on
line diff
--- a/hgext/largefiles/overrides.py	Thu May 03 16:12:52 2012 -0500
+++ b/hgext/largefiles/overrides.py	Thu May 03 21:32:57 2012 -0400
@@ -781,6 +781,47 @@
 
     archiver.done()
 
+def hgsubrepoarchive(orig, repo, ui, archiver, prefix):
+    rev = repo._state[1]
+    ctx = repo._repo[rev]
+
+    lfcommands.cachelfiles(ui, repo._repo, ctx.node())
+
+    def write(name, mode, islink, getdata):
+        if lfutil.isstandin(name):
+            return
+        data = getdata()
+
+        archiver.addfile(prefix + repo._path + '/' + name, mode, islink, data)
+
+    for f in ctx:
+        ff = ctx.flags(f)
+        getdata = ctx[f].data
+        if lfutil.isstandin(f):
+            path = lfutil.findfile(repo._repo, getdata().strip())
+            if path is None:
+                raise util.Abort(
+                    _('largefile %s not found in repo store or system cache')
+                    % lfutil.splitstandin(f))
+            f = lfutil.splitstandin(f)
+
+            def getdatafn():
+                fd = None
+                try:
+                    fd = open(os.path.join(prefix, path), 'rb')
+                    return fd.read()
+                finally:
+                    if fd:
+                        fd.close()
+
+            getdata = getdatafn
+
+        write(f, 'x' in ff and 0755 or 0644, 'l' in ff, getdata)
+
+    for subpath in ctx.substate:
+        sub = ctx.sub(subpath)
+        sub.archive(repo.ui, archiver, prefix)
+
 # If a largefile is modified, the change is not reflected in its
 # standin until a commit. cmdutil.bailifchanged() raises an exception
 # if the repo has uncommitted changes. Wrap it to also check if