##// END OF EJS Templates
archive: use a templater to build the metadata file...
Matt Harbison -
r33544:4c4e95ca default
parent child Browse files
Show More
@@ -18,9 +18,8 b' import zlib'
18 from .i18n import _
18 from .i18n import _
19
19
20 from . import (
20 from . import (
21 cmdutil,
22 encoding,
23 error,
21 error,
22 formatter,
24 match as matchmod,
23 match as matchmod,
25 util,
24 util,
26 vfs as vfsmod,
25 vfs as vfsmod,
@@ -80,30 +79,42 b' def _rootctx(repo):'
80 def buildmetadata(ctx):
79 def buildmetadata(ctx):
81 '''build content of .hg_archival.txt'''
80 '''build content of .hg_archival.txt'''
82 repo = ctx.repo()
81 repo = ctx.repo()
83 hex = ctx.hex()
82
84 if ctx.rev() is None:
83 default = (
85 hex = ctx.p1().hex()
84 r'repo: {root}\n'
86 if ctx.dirty(missing=True):
85 r'node: {ifcontains(rev, revset("wdir()"),'
87 hex += '+'
86 r'"{p1node}{dirty}", "{node}")}\n'
87 r'branch: {branch|utf8}\n'
88
88
89 base = 'repo: %s\nnode: %s\nbranch: %s\n' % (
89 # {tags} on ctx includes local tags and 'tip', with no current way to
90 _rootctx(repo).hex(), hex, encoding.fromlocal(ctx.branch()))
90 # limit that to global tags. Therefore, use {latesttag} as a substitute
91 # when the distance is 0, since that will be the list of global tags on
92 # ctx.
93 r'{ifeq(latesttagdistance, 0, latesttag % "tag: {tag}\n",'
94 r'"{latesttag % "latesttag: {tag}\n"}'
95 r'latesttagdistance: {latesttagdistance}\n'
96 r'changessincelatesttag: {changessincelatesttag}\n")}'
97 )
91
98
92 tags = ''.join('tag: %s\n' % t for t in ctx.tags()
99 opts = {
93 if repo.tagtype(t) == 'global')
100 'template': default
94 if not tags:
101 }
95 repo.ui.pushbuffer()
102
96 opts = {'template': '{latesttag}\n{latesttagdistance}\n'
103 out = util.stringio()
97 '{changessincelatesttag}',
98 'style': '', 'patch': None, 'git': None}
99 cmdutil.show_changeset(repo.ui, repo, opts).show(ctx)
100 ltags, dist, changessince = repo.ui.popbuffer().split('\n')
101 ltags = ltags.split(':')
102 tags = ''.join('latesttag: %s\n' % t for t in ltags)
103 tags += 'latesttagdistance: %s\n' % dist
104 tags += 'changessincelatesttag: %s\n' % changessince
105
104
106 return base + tags
105 fm = formatter.formatter(repo.ui, out, 'archive', opts)
106 fm.startitem()
107 fm.context(ctx=ctx)
108 fm.data(root=_rootctx(repo).hex())
109
110 if ctx.rev() is None:
111 dirty = ''
112 if ctx.dirty(missing=True):
113 dirty = '+'
114 fm.data(dirty=dirty)
115 fm.end()
116
117 return out.getvalue()
107
118
108 class tarit(object):
119 class tarit(object):
109 '''write archive to tar file or stream. can write uncompressed,
120 '''write archive to tar file or stream. can write uncompressed,
General Comments 0
You need to be logged in to leave comments. Login now