archive: extract metadata() closure to module-level function
This function will be reused in largefiles.
--- 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)]