changeset 24678:fbcace19534f

archive: extract metadata() closure to module-level function This function will be reused in largefiles.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 08 Apr 2015 22:37:03 +0900
parents 9df7ffd706d1
children 422d3c0c7f33
files mercurial/archival.py
diffstat 1 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/archival.py	Wed Apr 08 22:31:04 2015 +0900
+++ b/mercurial/archival.py	Wed Apr 08 22:37:03 2015 +0900
@@ -54,6 +54,27 @@
             return kind
     return None
 
+def buildmetadata(ctx):
+    '''build content of .hg_archival.txt'''
+    repo = ctx.repo()
+    base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
+        repo[0].hex(), ctx.hex(), encoding.fromlocal(ctx.branch()))
+
+    tags = ''.join('tag: %s\n' % t for t in ctx.tags()
+                   if repo.tagtype(t) == 'global')
+    if not tags:
+        repo.ui.pushbuffer()
+        opts = {'template': '{latesttag}\n{latesttagdistance}',
+                'style': '', 'patch': None, 'git': None}
+        cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
+        ltags, dist = repo.ui.popbuffer().split('\n')
+        ltags = ltags.split(':')
+        changessince = len(repo.revs('only(.,%s)', ltags[0]))
+        tags = ''.join('latesttag: %s\n' % t for t in ltags)
+        tags += 'latesttagdistance: %s\n' % dist
+        tags += 'changessincelatesttag: %s\n' % changessince
+
+    return base + tags
 
 class tarit(object):
     '''write archive to tar file or stream.  can write uncompressed,
@@ -263,29 +284,9 @@
     archiver = archivers[kind](dest, mtime or ctx.date()[0])
 
     if repo.ui.configbool("ui", "archivemeta", True):
-        def metadata():
-            base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
-                repo[0].hex(), ctx.hex(), encoding.fromlocal(ctx.branch()))
-
-            tags = ''.join('tag: %s\n' % t for t in ctx.tags()
-                           if repo.tagtype(t) == 'global')
-            if not tags:
-                repo.ui.pushbuffer()
-                opts = {'template': '{latesttag}\n{latesttagdistance}',
-                        'style': '', 'patch': None, 'git': None}
-                cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
-                ltags, dist = repo.ui.popbuffer().split('\n')
-                ltags = ltags.split(':')
-                changessince = len(repo.revs('only(.,%s)', ltags[0]))
-                tags = ''.join('latesttag: %s\n' % t for t in ltags)
-                tags += 'latesttagdistance: %s\n' % dist
-                tags += 'changessincelatesttag: %s\n' % changessince
-
-            return base + tags
-
         name = '.hg_archival.txt'
         if not matchfn or matchfn(name):
-            write(name, 0644, False, metadata)
+            write(name, 0644, False, lambda: buildmetadata(ctx))
 
     if matchfn:
         files = [f for f in ctx.manifest().keys() if matchfn(f)]