Mercurial > hg
changeset 16720:e825a89de5d7
context: add changectx.closesbranch() method
This removes the duplicated code for inspecting the 'close' extra field in
a changeset.
author | Brodie Rao <brodie@sf.io> |
---|---|
date | Sun, 13 May 2012 14:04:06 +0200 |
parents | e7bf09acd410 |
children | 3e6d59ae4dc2 |
files | mercurial/commands.py mercurial/context.py mercurial/hgweb/webcommands.py mercurial/localrepo.py mercurial/revset.py |
diffstat | 5 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Sun May 13 14:04:04 2012 +0200 +++ b/mercurial/commands.py Sun May 13 14:04:06 2012 +0200 @@ -1349,7 +1349,7 @@ 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: @@ -5414,7 +5414,7 @@ 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]):
--- a/mercurial/context.py Sun May 13 14:04:04 2012 +0200 +++ b/mercurial/context.py Sun May 13 14:04:06 2012 +0200 @@ -186,6 +186,8 @@ 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 @@ 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
--- a/mercurial/hgweb/webcommands.py Sun May 13 14:04:04 2012 +0200 +++ b/mercurial/hgweb/webcommands.py Sun May 13 14:04:06 2012 +0200 @@ -441,7 +441,7 @@ 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
--- a/mercurial/localrepo.py Sun May 13 14:04:04 2012 +0200 +++ b/mercurial/localrepo.py Sun May 13 14:04:06 2012 +0200 @@ -511,7 +511,7 @@ '''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 @@ -1555,8 +1555,7 @@ 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): @@ -2206,7 +2205,7 @@ 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:
--- a/mercurial/revset.py Sun May 13 14:04:04 2012 +0200 +++ b/mercurial/revset.py Sun May 13 14:04:06 2012 +0200 @@ -395,7 +395,7 @@ """ # 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)``