[PATCH 2 of 2] all users of changeset_printer updated to use contexts if appropriate
Alexander Solovyov
piranha at piranha.org.ua
Mon Oct 13 16:20:44 CDT 2008
# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1223932821 -10800
# Node ID 871eef5fb5c6fd4d6ee54267547fc8a03a820c12
# Parent 7894368aef0c5f2dd5c927b7ff1dac3b68292aab
all users of changeset_printer updated to use contexts if appropriate
diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py
--- a/hgext/bugzilla.py
+++ b/hgext/bugzilla.py
@@ -291,8 +291,7 @@
tmpl = templater.parsestring(tmpl, quoted=False)
t.use_template(tmpl)
self.ui.pushbuffer()
- t.show(changenode=ctx.node(), changes=ctx.changeset(),
- bug=str(bugid),
+ t.show(ctx=ctx, bug=str(bugid),
hgweb=self.ui.config('web', 'baseurl'),
root=self.repo.root,
webroot=webroot(self.repo.root))
diff --git a/hgext/children.py b/hgext/children.py
--- a/hgext/children.py
+++ b/hgext/children.py
@@ -23,13 +23,14 @@
"""
rev = opts.get('rev')
if file_:
- ctx = repo.filectx(file_, changeid=rev)
+ children = [c.changectx() for c in
+ repo.filectx(file_, changeid=rev).children()]
else:
- ctx = repo[rev]
+ children = repo[rev].children()
displayer = cmdutil.show_changeset(ui, repo, opts)
- for node in [cp.node() for cp in ctx.children()]:
- displayer.show(changenode=node)
+ for cp in children:
+ displayer.show(ctx=cp)
cmdtable = {
diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -65,7 +65,7 @@
tmpl = maketemplater(ui, repo, tmpl)
def getkey(ctx):
ui.pushbuffer()
- tmpl.show(changenode=ctx.node())
+ tmpl.show(ctx=ctx)
return ui.popbuffer()
count = pct = 0
diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -229,7 +229,7 @@
# log_strings is the list of all log strings to draw alongside
# the graph.
ui.pushbuffer()
- cs_printer.show(rev, node)
+ cs_printer.show(changenode=node)
log_strings = ui.popbuffer().split("\n")[:-1]
if n_columns_diff == -1:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1776,37 +1776,14 @@
endrev = max(cmdutil.revrange(repo, opts['rev'])) + 1
else:
endrev = len(repo)
- rcache = {}
- ncache = {}
- def getrenamed(fn, rev):
- '''looks up all renames for a file (up to endrev) the first
- time the file is given. It indexes on the changerev and only
- parses the manifest if linkrev != changerev.
- Returns rename info for fn at changerev rev.'''
- if fn not in rcache:
- rcache[fn] = {}
- ncache[fn] = {}
- fl = repo.file(fn)
- for i in fl:
- node = fl.node(i)
- lr = fl.linkrev(node)
- renamed = fl.renamed(node)
- rcache[fn][lr] = renamed
- if renamed:
- ncache[fn][node] = renamed
- if lr >= endrev:
- break
- if rev in rcache[fn]:
- return rcache[fn][rev]
- # If linkrev != rev (i.e. rev not found in rcache) fallback to
- # filectx logic.
-
- try:
- return repo[rev][fn].renamed()
- except revlog.LookupError:
- pass
- return None
+ def getrenamed(ctx):
+ for f in ctx.files():
+ if not f in ctx.manifest():
+ continue
+ cp = ctx.filectx(f).renamed()
+ if cp:
+ yield (f, cp[0])
df = False
if opts["date"]:
@@ -1817,43 +1794,31 @@
displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
for st, rev, fns in changeiter:
if st == 'add':
- changenode = repo.changelog.node(rev)
- parents = [p for p in repo.changelog.parentrevs(rev)
- if p != nullrev]
- if opts['no_merges'] and len(parents) == 2:
+ ctx = repo[rev]
+ if opts['no_merges'] and len(ctx.parents()) == 2:
continue
- if opts['only_merges'] and len(parents) != 2:
+ if opts['only_merges'] and len(ctx.parents()) != 2:
continue
- if only_branches:
- revbranch = get(rev)[5]['branch']
- if revbranch not in only_branches:
- continue
+ if only_branches and ctx.branch() not in only_branches:
+ continue
- if df:
- changes = get(rev)
- if not df(changes[2][0]):
- continue
+ if df and not df(ctx.date()[0]):
+ continue
if opts['keyword']:
- changes = get(rev)
miss = 0
for k in [kw.lower() for kw in opts['keyword']]:
- if not (k in changes[1].lower() or
- k in changes[4].lower() or
- k in " ".join(changes[3]).lower()):
+ if not (k in ctx.user().lower() or
+ k in ctx.description().lower() or
+ k in " ".join(ctx.files()).lower()):
miss = 1
break
if miss:
continue
- copies = []
- if opts.get('copies') and rev:
- for fn in get(rev)[3]:
- rename = getrenamed(fn, rev)
- if rename:
- copies.append((fn, rename[0]))
- displayer.show(rev, changenode, copies=copies)
+ copies = opts.get('copies') and getrenamed(ctx) or []
+ displayer.show(ctx=ctx, copies=copies)
elif st == 'iter':
if count == limit: break
if displayer.flush(rev):
@@ -1962,11 +1927,11 @@
for n in o:
if count >= limit:
break
- parents = [p for p in repo.changelog.parents(n) if p != nullid]
- if opts['no_merges'] and len(parents) == 2:
+ ctx = repo[n]
+ if opts['no_merges'] and len(ctx.parents()) == 2:
continue
count += 1
- displayer.show(changenode=n)
+ displayer.show(ctx=ctx)
def parents(ui, repo, file_=None, **opts):
"""show the parents of the working dir or revision
@@ -1999,14 +1964,14 @@
if not filenodes:
raise util.Abort(_("'%s' not found in manifest!") % file_)
fl = repo.file(file_)
- p = [repo.lookup(fl.linkrev(fn)) for fn in filenodes]
+ p = [repo[fl.linkrev(fn)] for fn in filenodes]
else:
- p = [cp.node() for cp in ctx.parents()]
+ p = ctx.parents()
displayer = cmdutil.show_changeset(ui, repo, opts)
- for n in p:
- if n != nullid:
- displayer.show(changenode=n)
+ for c in p:
+ if c.node() != nullid:
+ displayer.show(ctx=c)
def paths(ui, repo, search=None):
"""show definition of symbolic path names
@@ -2785,7 +2750,7 @@
that repository becomes the current tip. The "tip" tag is special
and cannot be renamed or assigned to a different changeset.
"""
- cmdutil.show_changeset(ui, repo, opts).show(len(repo) - 1)
+ cmdutil.show_changeset(ui, repo, opts).show(ctx=repo['tip'])
def unbundle(ui, repo, fname1, *fnames, **opts):
"""apply one or more changegroup files
diff --git a/tests/test-mq.out b/tests/test-mq.out
--- a/tests/test-mq.out
+++ b/tests/test-mq.out
@@ -299,8 +299,8 @@
2 qtip bar tip
% bad node in status
Now at: foo
+mq status file refers to unknown node
changeset: 0:cb9a9f314b8b
-mq status file refers to unknown node
tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
diff --git a/tests/test-tags.out b/tests/test-tags.out
--- a/tests/test-tags.out
+++ b/tests/test-tags.out
@@ -29,11 +29,11 @@
localtags, line 1: tag 'invalid' refers to unknown node
tip 8:4ca6f1b1a68c
first 0:0acdaf898367
-changeset: 8:4ca6f1b1a68c
.hgtags at c071f74ab5eb, line 2: cannot parse entry
.hgtags at c071f74ab5eb, line 4: node 'foo' is not well formed
.hgtags at 4ca6f1b1a68c, line 2: node 'x' is not well formed
localtags, line 1: tag 'invalid' refers to unknown node
+changeset: 8:4ca6f1b1a68c
tag: tip
parent: 3:b2ef3841386b
user: test
More information about the Mercurial-devel
mailing list