##// END OF EJS Templates
archive: extract metadata() closure to module-level function...
Yuya Nishihara -
r24678:fbcace19 default
parent child Browse files
Show More
@@ -54,6 +54,27 b' def guesskind(dest):'
54 return kind
54 return kind
55 return None
55 return None
56
56
57 def buildmetadata(ctx):
58 '''build content of .hg_archival.txt'''
59 repo = ctx.repo()
60 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
61 repo[0].hex(), ctx.hex(), encoding.fromlocal(ctx.branch()))
62
63 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
64 if repo.tagtype(t) == 'global')
65 if not tags:
66 repo.ui.pushbuffer()
67 opts = {'template': '{latesttag}\n{latesttagdistance}',
68 'style': '', 'patch': None, 'git': None}
69 cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
70 ltags, dist = repo.ui.popbuffer().split('\n')
71 ltags = ltags.split(':')
72 changessince = len(repo.revs('only(.,%s)', ltags[0]))
73 tags = ''.join('latesttag: %s\n' % t for t in ltags)
74 tags += 'latesttagdistance: %s\n' % dist
75 tags += 'changessincelatesttag: %s\n' % changessince
76
77 return base + tags
57
78
58 class tarit(object):
79 class tarit(object):
59 '''write archive to tar file or stream. can write uncompressed,
80 '''write archive to tar file or stream. can write uncompressed,
@@ -263,29 +284,9 b' def archive(repo, dest, node, kind, deco'
263 archiver = archivers[kind](dest, mtime or ctx.date()[0])
284 archiver = archivers[kind](dest, mtime or ctx.date()[0])
264
285
265 if repo.ui.configbool("ui", "archivemeta", True):
286 if repo.ui.configbool("ui", "archivemeta", True):
266 def metadata():
267 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
268 repo[0].hex(), ctx.hex(), encoding.fromlocal(ctx.branch()))
269
270 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
271 if repo.tagtype(t) == 'global')
272 if not tags:
273 repo.ui.pushbuffer()
274 opts = {'template': '{latesttag}\n{latesttagdistance}',
275 'style': '', 'patch': None, 'git': None}
276 cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
277 ltags, dist = repo.ui.popbuffer().split('\n')
278 ltags = ltags.split(':')
279 changessince = len(repo.revs('only(.,%s)', ltags[0]))
280 tags = ''.join('latesttag: %s\n' % t for t in ltags)
281 tags += 'latesttagdistance: %s\n' % dist
282 tags += 'changessincelatesttag: %s\n' % changessince
283
284 return base + tags
285
286 name = '.hg_archival.txt'
287 name = '.hg_archival.txt'
287 if not matchfn or matchfn(name):
288 if not matchfn or matchfn(name):
288 write(name, 0644, False, metadata)
289 write(name, 0644, False, lambda: buildmetadata(ctx))
289
290
290 if matchfn:
291 if matchfn:
291 files = [f for f in ctx.manifest().keys() if matchfn(f)]
292 files = [f for f in ctx.manifest().keys() if matchfn(f)]
General Comments 0
You need to be logged in to leave comments. Login now