changeset 46133:0a4d47f4337b

extdiff: add --from/--to and deprecate -r, as was done for `hg diff` I recently replaced `hg diff`'s `-r` flag by `--from` and `--to` and then deprecated the `-r` flag. This patch repeats that for `hg extdiff`. Differential Revision: https://phab.mercurial-scm.org/D9624
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 16 Dec 2020 21:06:29 -0800
parents dfe2760db2a6
children cc6faec62cb7
files hgext/extdiff.py tests/test-extdiff.t tests/test-extension.t
diffstat 3 files changed, 25 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/extdiff.py	Wed Dec 16 22:30:07 2020 -0800
+++ b/hgext/extdiff.py	Wed Dec 16 21:06:29 2020 -0800
@@ -552,12 +552,21 @@
 
     cmdutil.check_at_most_one_arg(opts, b'rev', b'change')
     revs = opts.get(b'rev')
+    from_rev = opts.get(b'from')
+    to_rev = opts.get(b'to')
     change = opts.get(b'change')
     do3way = b'$parent2' in cmdline
 
     if change:
         ctx2 = scmutil.revsingle(repo, change, None)
         ctx1a, ctx1b = ctx2.p1(), ctx2.p2()
+    elif from_rev or to_rev:
+        repo = scmutil.unhidehashlikerevs(
+            repo, [from_rev] + [to_rev], b'nowarn'
+        )
+        ctx1a = scmutil.revsingle(repo, from_rev, None)
+        ctx1b = repo[nullid]
+        ctx2 = scmutil.revsingle(repo, to_rev, None)
     else:
         ctx1a, ctx2 = scmutil.revpair(repo, revs)
         if not revs:
@@ -615,7 +624,9 @@
             _(b'pass option to comparison program'),
             _(b'OPT'),
         ),
-        (b'r', b'rev', [], _(b'revision'), _(b'REV')),
+        (b'r', b'rev', [], _(b'revision (DEPRECATED)'), _(b'REV')),
+        (b'', b'from', b'', _(b'revision to diff from'), _(b'REV1')),
+        (b'', b'to', b'', _(b'revision to diff to'), _(b'REV2')),
         (b'c', b'change', b'', _(b'change made by revision'), _(b'REV')),
         (
             b'',
@@ -659,11 +670,8 @@
     additional options to the program, use -o/--option. These will be
     passed before the names of the directories or files to compare.
 
-    When two revision arguments are given, then changes are shown
-    between those revisions. If only one revision is specified then
-    that revision is compared to the working directory, and, when no
-    revisions are specified, the working directory files are compared
-    to its parent.
+    The --from, --to, and --change options work the same way they do for
+    :hg:`diff`.
 
     The --per-file option runs the external program repeatedly on each
     file to diff, instead of once on two directories. By default,
--- a/tests/test-extdiff.t	Wed Dec 16 22:30:07 2020 -0800
+++ b/tests/test-extdiff.t	Wed Dec 16 21:06:29 2020 -0800
@@ -50,7 +50,8 @@
   options ([+] can be repeated):
   
    -o --option OPT [+]      pass option to comparison program
-   -r --rev REV [+]         revision
+      --from REV1           revision to diff from
+      --to REV2             revision to diff to
    -c --change REV          change made by revision
       --per-file            compare each file instead of revision snapshots
       --confirm             prompt user before each external program invocation
@@ -68,14 +69,14 @@
 
 Should diff cloned files directly:
 
-  $ hg falabala -r 0:1
+  $ hg falabala --from 0 --to 1
   diffing "*\\extdiff.*\\a.8a5febb7f867\\a" "a.34eed99112ab\\a" (glob) (windows !)
   diffing */extdiff.*/a.8a5febb7f867/a a.34eed99112ab/a (glob) (no-windows !)
   [1]
 
 Can show diff from working copy:
   $ echo c >> a
-  $ hg falabala -r 'wdir()' -r 1
+  $ hg falabala --to 1
   diffing "*\\extdiff.*\\a" "a.34eed99112ab\\a" (glob) (windows !)
   diffing */extdiff.*/a a.34eed99112ab/a (glob) (no-windows !)
   [1]
@@ -139,7 +140,7 @@
   $ hg ci -Sm "adding subrepo"
   $ echo > .hgsub
   $ hg ci -m "removing subrepo"
-  $ hg falabala -r 4 -r 5 -S
+  $ hg falabala --from 4 --to 5 -S
   diffing a.398e36faf9c6 a.5ab95fb166c4
   [1]
 
@@ -292,7 +293,7 @@
   > kdiff3.diffargs=--L1 \$plabel1 --L2 \$clabel \$parent \$child
   > EOF
 
-  $ hg --debug kdiff3 -r0 | grep '^running'
+  $ hg --debug kdiff3 --from 0 | grep '^running'
   running 'echo --L1 "@0" --L2 "" a.8a5febb7f867 a' in * (glob) (windows !)
   running "echo --L1 '@0' --L2 '' a.8a5febb7f867 a" in * (glob) (no-windows !)
 
@@ -496,7 +497,7 @@
   $ echo a >> a
   $ ln -s missing linka
   $ hg add linka
-  $ hg falabala -r 0 --traceback
+  $ hg falabala --from 0 --traceback
   diffing testsymlinks.07f494440405 testsymlinks
   [1]
   $ cd ..
--- a/tests/test-extension.t	Wed Dec 16 22:30:07 2020 -0800
+++ b/tests/test-extension.t	Wed Dec 16 21:06:29 2020 -0800
@@ -836,10 +836,8 @@
       program, use -o/--option. These will be passed before the names of the
       directories or files to compare.
   
-      When two revision arguments are given, then changes are shown between
-      those revisions. If only one revision is specified then that revision is
-      compared to the working directory, and, when no revisions are specified,
-      the working directory files are compared to its parent.
+      The --from, --to, and --change options work the same way they do for 'hg
+      diff'.
   
       The --per-file option runs the external program repeatedly on each file to
       diff, instead of once on two directories. By default, this happens one by
@@ -859,7 +857,8 @@
   
    -p --program CMD         comparison program to run
    -o --option OPT [+]      pass option to comparison program
-   -r --rev REV [+]         revision
+      --from REV1           revision to diff from
+      --to REV2             revision to diff to
    -c --change REV          change made by revision
       --per-file            compare each file instead of revision snapshots
       --confirm             prompt user before each external program invocation