[PATCH 2 of 5] archive: extract metadata() closure to module-level function
Yuya Nishihara
yuya at tcha.org
Thu Apr 9 12:57:14 UTC 2015
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1428500223 -32400
# Wed Apr 08 22:37:03 2015 +0900
# Node ID 4601887b449d56ea94d2f49be62d1219244871f6
# Parent d39ef2e2e7227fcd391346b4001556e561d42636
archive: extract metadata() closure to module-level function
This function will be reused in largefiles.
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -54,6 +54,27 @@ def guesskind(dest):
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 @@ def archive(repo, dest, node, kind, deco
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)]
More information about the Mercurial-devel
mailing list