[PATCH 1 of 2] make changeset_templater use context
Alexander Solovyov
piranha at piranha.org.ua
Wed Feb 4 21:57:45 UTC 2009
# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1233784643 -7200
# Node ID 19a0120d6185e87f215a7c24f39f5c5b94897299
# Parent fff6e253e1f6eb7fa352617112bd48de7e39bd16
make changeset_templater use context
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -709,13 +709,18 @@
'''set template string to use'''
self.t.cache['changeset'] = t
+ def _meaningful_parentrevs(self, ctx):
+ """Return list of meaningful (or all if debug) parentrevs for rev.
+ """
+ parents = ctx.parents()
+ if len(parents) > 1:
+ return parents
+ if self.ui.debugflag:
+ return [parents[0], self.repo['null']]
+ return parents
+
def _show(self, ctx, copies, props):
'''show a single changeset or file revision'''
- changenode = ctx.node()
- rev = ctx.rev()
-
- log = self.repo.changelog
- changes = log.read(changenode)
def showlist(name, values, plural=None, **args):
'''expand set of values.
@@ -779,21 +784,21 @@
yield self.t(endname, **args)
def showbranches(**args):
- branch = changes[5].get("branch")
+ branch = ctx.branch()
if branch != 'default':
branch = util.tolocal(branch)
return showlist('branch', [branch], plural='branches', **args)
def showparents(**args):
- parents = [[('rev', p), ('node', hex(log.node(p)))]
- for p in self._meaningful_parentrevs(log, rev)]
+ parents = [[('rev', p.rev()), ('node', p.hex())]
+ for p in self._meaningful_parentrevs(ctx)]
return showlist('parent', parents, **args)
def showtags(**args):
- return showlist('tag', self.repo.nodetags(changenode), **args)
+ return showlist('tag', ctx.tags(), **args)
def showextras(**args):
- for key, value in util.sort(changes[5].items()):
+ for key, value in util.sort(ctx.extra().items()):
args = args.copy()
args.update(dict(key=key, value=value))
yield self.t('extra', **args)
@@ -805,11 +810,11 @@
files = []
def getfiles():
if not files:
- files[:] = self.repo.status(
- log.parents(changenode)[0], changenode)[:3]
+ files[:] = self.repo.status(ctx.parents()[0].node(),
+ ctx.node())[:3]
return files
def showfiles(**args):
- return showlist('file', changes[3], **args)
+ return showlist('file', ctx.files(), **args)
def showmods(**args):
return showlist('file_mod', getfiles()[0], **args)
def showadds(**args):
@@ -818,24 +823,24 @@
return showlist('file_del', getfiles()[2], **args)
def showmanifest(**args):
args = args.copy()
- args.update(dict(rev=self.repo.manifest.rev(changes[0]),
- node=hex(changes[0])))
+ args.update(dict(rev=self.repo.manifest.rev(ctx.changeset()[0]),
+ node=hex(ctx.changeset()[0])))
return self.t('manifest', **args)
defprops = {
- 'author': changes[1],
+ 'author': ctx.user(),
'branches': showbranches,
- 'date': changes[2],
- 'desc': changes[4].strip(),
+ 'date': ctx.date(),
+ 'desc': ctx.description().strip(),
'file_adds': showadds,
'file_dels': showdels,
'file_mods': showmods,
'files': showfiles,
'file_copies': showcopies,
'manifest': showmanifest,
- 'node': hex(changenode),
+ 'node': ctx.hex(),
'parents': showparents,
- 'rev': rev,
+ 'rev': ctx.rev(),
'tags': showtags,
'extras': showextras,
}
@@ -856,7 +861,7 @@
if key:
h = templater.stringify(self.t(key, **props))
if self.buffered:
- self.header[rev] = h
+ self.header[ctx.rev()] = h
else:
self.ui.write(h)
if self.ui.debugflag and 'changeset_debug' in self.t:
@@ -868,7 +873,7 @@
else:
key = 'changeset'
self.ui.write(templater.stringify(self.t(key, **props)))
- self.showpatch(changenode)
+ self.showpatch(ctx.node())
except KeyError, inst:
raise util.Abort(_("%s: no key named '%s'") % (self.t.mapfile,
inst.args[0]))
More information about the Mercurial-devel
mailing list