Mercurial > public > mercurial-scm > hg-stable
diff mercurial/commands.py @ 46088:64292addbe67
diff: add --from and --to flags as clearer alternative to -r -r
I think it was mistake to let the `-r` flag accept two revisions in
`hg diff` in 98633e60067c (Support for 0, 1, or 2 diff revs,
2005-05-07). The command clearly acts on two revisions and having a
single flag to indicate which those are is unclear. It got worse when
it started accepting revsets as input.
This patch introduces `--from` and `--to` flags, each taking a single
revision and each defaulting to the working copy. That means that `hg
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 09 Dec 2020 18:31:19 -0800 |
parents | 7a2b67e6b680 |
children | 8837498ae6e0 |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Dec 03 17:18:49 2020 +0530 +++ b/mercurial/commands.py Wed Dec 09 18:31:19 2020 -0800 @@ -2456,6 +2456,8 @@ b'diff', [ (b'r', b'rev', [], _(b'revision'), _(b'REV')), + (b'', b'from', b'', _(b'revision to diff from'), _(b'REV')), + (b'', b'to', b'', _(b'revision to diff to'), _(b'REV')), (b'c', b'change', b'', _(b'change made by revision'), _(b'REV')), ] + diffopts @@ -2530,13 +2532,23 @@ opts = pycompat.byteskwargs(opts) revs = opts.get(b'rev') change = opts.get(b'change') + from_rev = opts.get(b'from') + to_rev = opts.get(b'to') stat = opts.get(b'stat') reverse = opts.get(b'reverse') + cmdutil.check_incompatible_arguments(opts, b'from', [b'rev', b'change']) + cmdutil.check_incompatible_arguments(opts, b'to', [b'rev', b'change']) if change: repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn') ctx2 = scmutil.revsingle(repo, change, None) ctx1 = ctx2.p1() + elif from_rev or to_rev: + repo = scmutil.unhidehashlikerevs( + repo, [from_rev] + [to_rev], b'nowarn' + ) + ctx1 = scmutil.revsingle(repo, from_rev, None) + ctx2 = scmutil.revsingle(repo, to_rev, None) else: repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn') ctx1, ctx2 = scmutil.revpair(repo, revs)