[PATCH 2 of 3] context: add changectx.closesbranch() method
Brodie Rao
brodie at sf.io
Sun May 13 07:20:39 CDT 2012
# HG changeset patch
# User Brodie Rao <brodie at sf.io>
# Date 1336910646 -7200
# Node ID 43d75fdda09a7edd987cb084e2464eb268a3cc46
# Parent ce831f34e136d6d2ae459a9617b6d3fc9d0428f8
context: add changectx.closesbranch() method
This removes the duplicated code for inspecting the 'close' extra field in
a changeset.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1349,7 +1349,7 @@ def commit(ui, repo, *pats, **opts):
if not opts.get('close_branch'):
for r in parents:
- if r.extra().get('close') and r.branch() == branch:
+ if r.closesbranch() and r.branch() == branch:
ui.status(_('reopening closed branch head %d\n') % r)
if ui.debugflag:
@@ -5375,7 +5375,7 @@ def summary(ui, repo, **opts):
t += _(' (merge)')
elif branch != parents[0].branch():
t += _(' (new branch)')
- elif (parents[0].extra().get('close') and
+ elif (parents[0].closesbranch() and
pnode in repo.branchheads(branch, closed=True)):
t += _(' (head closed)')
elif not (st[0] or st[1] or st[2] or st[3] or st[4] or st[9]):
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -186,6 +186,8 @@ class changectx(object):
return self._changeset[4]
def branch(self):
return encoding.tolocal(self._changeset[5].get("branch"))
+ def closesbranch(self):
+ return 'close' in self._changeset[5]
def extra(self):
return self._changeset[5]
def tags(self):
@@ -895,6 +897,8 @@ class workingctx(changectx):
return self._clean
def branch(self):
return encoding.tolocal(self._extra['branch'])
+ def closesbranch(self):
+ return 'close' in self._extra
def extra(self):
return self._extra
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -441,7 +441,7 @@ def branches(web, req, tmpl):
tips = (web.repo[n] for t, n in web.repo.branchtags().iteritems())
heads = web.repo.heads()
parity = paritygen(web.stripecount)
- sortkey = lambda ctx: ('close' not in ctx.extra(), ctx.rev())
+ sortkey = lambda ctx: (not ctx.closesbranch(), ctx.rev())
def entries(limit, **map):
count = 0
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -503,7 +503,7 @@ class localrepository(repo.repository):
'''return the tipmost branch head in heads'''
tip = heads[-1]
for h in reversed(heads):
- if 'close' not in self.changelog.read(h)[5]:
+ if not self[h].closesbranch():
tip = h
break
return tip
@@ -1501,8 +1501,7 @@ class localrepository(repo.repository):
fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
bheads = [h for h in bheads if h in fbheads]
if not closed:
- bheads = [h for h in bheads if
- ('close' not in self.changelog.read(h)[5])]
+ bheads = [h for h in bheads if not self[h].closesbranch()]
return bheads
def branches(self, nodes):
@@ -2152,7 +2151,7 @@ class localrepository(repo.repository):
heads = cl.heads()
dh = len(heads) - len(oldheads)
for h in heads:
- if h not in oldheads and 'close' in self[h].extra():
+ if h not in oldheads and self[h].closesbranch():
dh -= 1
htext = ""
if dh:
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -395,7 +395,7 @@ def closed(repo, subset, x):
"""
# i18n: "closed" is a keyword
getargs(x, 0, 0, _("closed takes no arguments"))
- return [r for r in subset if repo[r].extra().get('close')]
+ return [r for r in subset if repo[r].closesbranch()]
def contains(repo, subset, x):
"""``contains(pattern)``
More information about the Mercurial-devel
mailing list