Mercurial > public > mercurial-scm > hg
comparison hgext/graphlog.py @ 16180:46a96cc830c2
graphlog: implement --copies
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Sun, 26 Feb 2012 16:56:32 +0100 |
parents | 0a73c4bd9f47 |
children | 1fd352aa08fc |
comparison
equal
deleted
inserted
replaced
16178:828fe2ca7cbb | 16180:46a96cc830c2 |
---|---|
15 from mercurial.cmdutil import show_changeset | 15 from mercurial.cmdutil import show_changeset |
16 from mercurial.commands import templateopts | 16 from mercurial.commands import templateopts |
17 from mercurial.i18n import _ | 17 from mercurial.i18n import _ |
18 from mercurial.node import nullrev | 18 from mercurial.node import nullrev |
19 from mercurial import cmdutil, commands, extensions, scmutil | 19 from mercurial import cmdutil, commands, extensions, scmutil |
20 from mercurial import hg, util, graphmod | 20 from mercurial import hg, util, graphmod, templatekw |
21 | 21 |
22 cmdtable = {} | 22 cmdtable = {} |
23 command = cmdutil.command(cmdtable) | 23 command = cmdutil.command(cmdtable) |
24 | 24 |
25 ASCIIDATA = 'ASC' | 25 ASCIIDATA = 'ASC' |
235 return (max(revs), min(revs)) | 235 return (max(revs), min(revs)) |
236 else: | 236 else: |
237 return (len(repo) - 1, 0) | 237 return (len(repo) - 1, 0) |
238 | 238 |
239 def check_unsupported_flags(pats, opts): | 239 def check_unsupported_flags(pats, opts): |
240 for op in ["copies", "newest_first"]: | 240 for op in ["newest_first"]: |
241 if op in opts and opts[op]: | 241 if op in opts and opts[op]: |
242 raise util.Abort(_("-G/--graph option is incompatible with --%s") | 242 raise util.Abort(_("-G/--graph option is incompatible with --%s") |
243 % op.replace("_", "-")) | 243 % op.replace("_", "-")) |
244 | 244 |
245 def revset(repo, pats, opts): | 245 def revset(repo, pats, opts): |
348 revset = '(' + ' and '.join(revset) + ')' | 348 revset = '(' + ' and '.join(revset) + ')' |
349 else: | 349 else: |
350 revset = 'all()' | 350 revset = 'all()' |
351 return revset | 351 return revset |
352 | 352 |
353 def generate(ui, dag, displayer, showparents, edgefn): | 353 def generate(ui, dag, displayer, showparents, edgefn, getrenamed=None): |
354 seen, state = [], asciistate() | 354 seen, state = [], asciistate() |
355 for rev, type, ctx, parents in dag: | 355 for rev, type, ctx, parents in dag: |
356 char = ctx.node() in showparents and '@' or 'o' | 356 char = ctx.node() in showparents and '@' or 'o' |
357 displayer.show(ctx) | 357 copies = None |
358 if getrenamed and ctx.rev(): | |
359 copies = [] | |
360 for fn in ctx.files(): | |
361 rename = getrenamed(fn, ctx.rev()) | |
362 if rename: | |
363 copies.append((fn, rename[0])) | |
364 displayer.show(ctx, copies=copies) | |
358 lines = displayer.hunk.pop(rev).split('\n')[:-1] | 365 lines = displayer.hunk.pop(rev).split('\n')[:-1] |
359 displayer.flush(rev) | 366 displayer.flush(rev) |
360 edges = edgefn(type, char, lines, seen, rev, parents) | 367 edges = edgefn(type, char, lines, seen, rev, parents) |
361 for type, char, lines, coldata in edges: | 368 for type, char, lines, coldata in edges: |
362 ascii(ui, state, type, char, lines, coldata) | 369 ascii(ui, state, type, char, lines, coldata) |
385 limit = cmdutil.loglimit(opts) | 392 limit = cmdutil.loglimit(opts) |
386 if limit is not None: | 393 if limit is not None: |
387 revs = revs[:limit] | 394 revs = revs[:limit] |
388 revdag = graphmod.dagwalker(repo, revs) | 395 revdag = graphmod.dagwalker(repo, revs) |
389 | 396 |
397 getrenamed = None | |
398 if opts.get('copies'): | |
399 endrev = None | |
400 if opts.get('rev'): | |
401 endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 | |
402 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) | |
390 displayer = show_changeset(ui, repo, opts, buffered=True) | 403 displayer = show_changeset(ui, repo, opts, buffered=True) |
391 showparents = [ctx.node() for ctx in repo[None].parents()] | 404 showparents = [ctx.node() for ctx in repo[None].parents()] |
392 generate(ui, revdag, displayer, showparents, asciiedges) | 405 generate(ui, revdag, displayer, showparents, asciiedges, getrenamed) |
393 | 406 |
394 def graphrevs(repo, nodes, opts): | 407 def graphrevs(repo, nodes, opts): |
395 limit = cmdutil.loglimit(opts) | 408 limit = cmdutil.loglimit(opts) |
396 nodes.reverse() | 409 nodes.reverse() |
397 if limit is not None: | 410 if limit is not None: |