[PATCH] fix graphlog to work with revsets correctly
Alexander Solovyov
alexander at solovyov.net
Wed Dec 15 11:35:40 CST 2010
# HG changeset patch
# User Alexander Solovyov <alexander at solovyov.net>
# Date 1292329089 -3600
# Branch stable
# Node ID 20459ee367b78fb4e66c825a5ccf06f976dbb4b1
# Parent dbc546811dd6eb672756f9266d432bb9c1101adb
fix graphlog to work with revsets correctly
diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -16,7 +16,6 @@ import os
from mercurial.cmdutil import revrange, show_changeset
from mercurial.commands import templateopts
from mercurial.i18n import _
-from mercurial.node import nullrev
from mercurial import cmdutil, commands, extensions
from mercurial import hg, util, graphmod
@@ -206,15 +205,6 @@ def ascii(ui, state, type, char, text, c
state[0] = coldiff
state[1] = idx
-def get_revs(repo, rev_opt):
- if rev_opt:
- revs = revrange(repo, rev_opt)
- if len(revs) == 0:
- return (nullrev, nullrev)
- return (max(revs), min(revs))
- else:
- return (len(repo) - 1, 0)
-
def check_unsupported_flags(opts):
for op in ["follow", "follow_first", "date", "copies", "keyword", "remove",
"only_merges", "user", "branch", "only_branch", "prune",
@@ -245,18 +235,20 @@ def graphlog(ui, repo, path=None, **opts
check_unsupported_flags(opts)
limit = cmdutil.loglimit(opts)
- start, stop = get_revs(repo, opts["rev"])
- if start == nullrev:
+ revs = revrange(repo, opts.get('rev') or ['tip:null'])
+ if -1 in revs:
+ revs.remove(-1)
+ if not revs:
return
if path:
path = util.canonpath(repo.root, os.getcwd(), path)
if path: # could be reset in canonpath
- revdag = graphmod.filerevs(repo, path, start, stop, limit)
+ revdag = graphmod.filerevs(repo, path, revs, limit)
else:
if limit is not None:
- stop = max(stop, start - limit + 1)
- revdag = graphmod.revisions(repo, start, stop)
+ revs = revs[:limit]
+ revdag = graphmod.revisions(repo, revs)
displayer = show_changeset(ui, repo, opts, buffered=True)
showparents = [ctx.node() for ctx in repo[None].parents()]
diff --git a/mercurial/graphmod.py b/mercurial/graphmod.py
--- a/mercurial/graphmod.py
+++ b/mercurial/graphmod.py
@@ -21,35 +21,37 @@ from mercurial.node import nullrev
CHANGESET = 'C'
-def revisions(repo, start, stop):
+def revisions(repo, revs):
"""cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
- This generator function walks through the revision history from revision
- start to revision stop (which must be less than or equal to start). It
- returns a tuple for each node. The node and parent ids are arbitrary
- integers which identify a node in the context of the graph returned.
+ This generator function walks through revisions (which should be ordered
+ from bigger to lesser). It returns a tuple for each node. The node and
+ parent ids are arbitrary integers which identify a node in the context of
+ the graph returned.
"""
- cur = start
- while cur >= stop:
- ctx = repo[cur]
+ if not revs:
+ return
+ if revs[0] < revs[-1]:
+ revs = reversed(revs)
+ for rev in revs:
+ ctx = repo[rev]
parents = set([p.rev() for p in ctx.parents() if p.rev() != nullrev])
- yield (cur, CHANGESET, ctx, sorted(parents))
- cur -= 1
+ yield (rev, CHANGESET, ctx, sorted(parents))
-def filerevs(repo, path, start, stop, limit=None):
+def filerevs(repo, path, revs, limit=None):
"""file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
This generator function walks through the revision history of a single
- file from revision start down to revision stop.
+ file in revisions.
"""
filerev = len(repo.file(path)) - 1
- rev = stop + 1
+ rev = revs[-1]
count = 0
- while filerev >= 0 and rev > stop:
+ while filerev >= 0 and rev in revs:
fctx = repo.filectx(path, fileid=filerev)
parents = set([f.linkrev() for f in fctx.parents() if f.path() == path])
rev = fctx.rev()
- if rev <= start:
+ if rev in revs:
yield (rev, CHANGESET, fctx.changectx(), sorted(parents))
count += 1
if count == limit:
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -12,7 +12,7 @@ from mercurial.node import short, hex
from mercurial.util import binary
from common import paritygen, staticfile, get_contact, ErrorResponse
from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
-from mercurial import graphmod
+from mercurial import cmdutil, graphmod
from mercurial import help as helpmod
from mercurial.i18n import _
@@ -706,7 +706,8 @@ def graph(web, req, tmpl):
count = len(web.repo)
changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
- dag = graphmod.revisions(web.repo, rev, downrev)
+ dag = graphmod.revisions(web.repo, cmdutil.revrange(
+ web.repo, ['%s:%s' % (rev, downrev)]))
tree = list(graphmod.colored(dag))
canvasheight = (len(tree) + 1) * bg_height - 27
data = []
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -923,3 +923,26 @@ Do not crash or produce strange graphs i
| | | date: Thu Jan 01 00:00:32 1970 +0000
| | | summary: (32) expand
| | |
+
+Work correctly with revsets:
+
+ $ hg glog -r 27::34
+ o changeset: 34:fea3ac5810e0
+ | parent: 32:d06dffa21a31
+ | user: test
+ | date: Thu Jan 01 00:00:34 1970 +0000
+ | summary: (34) head
+ |
+ o changeset: 32:d06dffa21a31
+ |\ parent: 27:886ed638191b
+ | | parent: 31:621d83e11f67
+ | | user: test
+ | | date: Thu Jan 01 00:00:32 1970 +0000
+ | | summary: (32) expand
+ | |
+ o | changeset: 27:886ed638191b
+ | | parent: 21:d42a756af44d
+ | | user: test
+ | | date: Thu Jan 01 00:00:27 1970 +0000
+ | | summary: (27) collapse
+ | |
More information about the Mercurial-devel
mailing list