Patchwork D9624: extdiff: add --from/--to and deprecate -r, as was done for `hg diff`

login
register
mail settings
Submitter phabricator
Date Dec. 17, 2020, 7:13 a.m.
Message ID <differential-rev-PHID-DREV-ydyp2i2ijzzchzxvnljx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47922/
State Superseded
Headers show

Comments

phabricator - Dec. 17, 2020, 7:13 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9624

AFFECTED FILES
  hgext/extdiff.py
  tests/test-extdiff.t
  tests/test-extension.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -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
diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t
--- a/tests/test-extdiff.t
+++ b/tests/test-extdiff.t
@@ -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 ..
diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -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,