[PATCH 1 of 7] graphlog: implement --copies
Patrick Mezard
patrick at mezard.eu
Sun Feb 26 16:14:24 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1330271792 -3600
# Node ID 2e26db08efc13b8c264c759276f0851efd238749
# Parent 0bb0b9f22cd76281cf8664aae85e2e53c43acd96
graphlog: implement --copies
diff --git a/hgext/graphlog.py b/hgext/graphlog.py
--- a/hgext/graphlog.py
+++ b/hgext/graphlog.py
@@ -17,7 +17,7 @@
from mercurial.i18n import _
from mercurial.node import nullrev
from mercurial import cmdutil, commands, extensions, scmutil
-from mercurial import hg, util, graphmod
+from mercurial import hg, util, graphmod, templatekw
cmdtable = {}
command = cmdutil.command(cmdtable)
@@ -237,7 +237,7 @@
return (len(repo) - 1, 0)
def check_unsupported_flags(pats, opts):
- for op in ["copies", "newest_first"]:
+ for op in ["newest_first"]:
if op in opts and opts[op]:
raise util.Abort(_("-G/--graph option is incompatible with --%s")
% op.replace("_", "-"))
@@ -350,11 +350,18 @@
revset = 'all()'
return revset
-def generate(ui, dag, displayer, showparents, edgefn):
+def generate(ui, dag, displayer, showparents, edgefn, getrenamed=None):
seen, state = [], asciistate()
for rev, type, ctx, parents in dag:
char = ctx.node() in showparents and '@' or 'o'
- displayer.show(ctx)
+ copies = None
+ if getrenamed and ctx.rev():
+ copies = []
+ for fn in ctx.files():
+ rename = getrenamed(fn, ctx.rev())
+ if rename:
+ copies.append((fn, rename[0]))
+ displayer.show(ctx, copies=copies)
lines = displayer.hunk.pop(rev).split('\n')[:-1]
displayer.flush(rev)
edges = edgefn(type, char, lines, seen, rev, parents)
@@ -387,9 +394,15 @@
revs = revs[:limit]
revdag = graphmod.dagwalker(repo, revs)
+ getrenamed = None
+ if opts.get('copies'):
+ endrev = None
+ if opts.get('rev'):
+ endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1
+ getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
displayer = show_changeset(ui, repo, opts, buffered=True)
showparents = [ctx.node() for ctx in repo[None].parents()]
- generate(ui, revdag, displayer, showparents, asciiedges)
+ generate(ui, revdag, displayer, showparents, asciiedges, getrenamed)
def graphrevs(repo, nodes, opts):
limit = cmdutil.loglimit(opts)
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1642,3 +1642,21 @@
o | 5 add another e
| |
+Test --copies
+
+ $ hg log -G --copies --template "{rev} {desc|firstline} \
+ > copies: {file_copies_switch}\n"
+ @ 6 merge 5 and 4 copies:
+ |\
+ | o 5 add another e copies:
+ | |
+ o | 4 mv dir/b e copies: e (dir/b)
+ |/
+ o 3 mv a b; add d copies: b (a)g (f)
+ |
+ o 2 mv b dir/b copies: dir/b (b)
+ |
+ o 1 copy a b copies: b (a)g (f)
+ |
+ o 0 add a copies:
+
More information about the Mercurial-devel
mailing list