diff --git a/hgext/graphlog.py b/hgext/graphlog.py --- a/hgext/graphlog.py +++ b/hgext/graphlog.py @@ -17,7 +17,7 @@ from mercurial.commands import templateo 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 @@ def get_revs(repo, rev_opt): 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 @@ def revset(repo, pats, opts): 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 @@ def graphlog(ui, repo, *pats, **opts): 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 @@ Cannot compare with log --follow-first F 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: +