mbox series

[v3,00/10] builtin/diff: learn --merge-base

Message ID cover.1600328335.git.liu.denton@gmail.com (mailing list archive)
Headers show
Series builtin/diff: learn --merge-base | expand

Message

Denton Liu Sept. 17, 2020, 7:44 a.m. UTC
The range-notation in `git diff` has been cited as a mistake since diff
compares two endpoints, not whole ranges.[0]  In fact, the ranges seem
to take on the opposite meanings when compared to range notation in
`git log`.

In an effort to reduce the use of range notation as much as possible,
introduce the `--merge-base` flag, slightly modified from a suggestion
by Jonathan Nieder.[1] This flag allows us to replace the first commit
given on the command-line with its merge base between the first and
second commits. This allows us to gently deprecate the `...` form
entirely, although that is left as an exercise to the reader ;)

One additional bonus is that this flag allows the "after" side to be not
just constrained to a commit (like with `...` notation). It can now be
the working tree or the index as well.

The `--merge-base` name isn't very satisfying. If anyone has any better
suggestions, please let me know.

Changes since v1:

* Implement Junio's documentation suggestions

* Update git diff's usage to include this option

Changes since v2:

* Teach diff-index and diff-tree the --merge-base option as well

[0]: https://lore.kernel.org/git/xmqqy2v26hu0.fsf@gitster-ct.c.googlers.com/
[1]: https://lore.kernel.org/git/20191223215928.GB38316@google.com/

Denton Liu (10):
  t4068: remove unnecessary >tmp
  git-diff-index.txt: make --cached description a proper sentence
  git-diff.txt: backtick quote command text
  contrib/completion: extract common diff/difftool options
  diff-lib: accept option flags in run_diff_index()
  diff-lib: define diff_get_merge_base()
  t4068: add --merge-base tests
  builtin/diff-index: learn --merge-base
  builtin/diff-tree: learn --merge-base
  contrib/completion: complete `git diff --merge-base`

 Documentation/git-diff-index.txt       |   9 +-
 Documentation/git-diff-tree.txt        |   7 +-
 Documentation/git-diff.txt             |  37 +++--
 builtin/diff-index.c                   |  10 +-
 builtin/diff-tree.c                    |  18 +++
 builtin/diff.c                         |  50 ++++---
 contrib/completion/git-completion.bash |  15 +-
 diff-lib.c                             |  65 ++++++++-
 diff.h                                 |   6 +-
 t/t4068-diff-symmetric-merge-base.sh   | 193 +++++++++++++++++++++++++
 t/t4068-diff-symmetric.sh              |  91 ------------
 11 files changed, 358 insertions(+), 143 deletions(-)
 create mode 100755 t/t4068-diff-symmetric-merge-base.sh
 delete mode 100755 t/t4068-diff-symmetric.sh

Range-diff against v2:
 1:  80e9066a59 =  1:  80e9066a59 t4068: remove unnecessary >tmp
 -:  ---------- >  2:  21b20281e6 git-diff-index.txt: make --cached description a proper sentence
 2:  8e72bd8fea =  3:  ca9568c2ea git-diff.txt: backtick quote command text
 3:  ea6717e7b3 <  -:  ---------- builtin/diff: parse --no-index using parse_options()
 4:  4f219cf0d1 <  -:  ---------- builtin/diff: learn --merge-base
 -:  ---------- >  4:  1ac8459541 contrib/completion: extract common diff/difftool options
 -:  ---------- >  5:  496908ac10 diff-lib: accept option flags in run_diff_index()
 -:  ---------- >  6:  6aac57ca02 diff-lib: define diff_get_merge_base()
 -:  ---------- >  7:  c9225a0440 t4068: add --merge-base tests
 -:  ---------- >  8:  1e4f805e57 builtin/diff-index: learn --merge-base
 -:  ---------- >  9:  c0d27b125e builtin/diff-tree: learn --merge-base
 -:  ---------- > 10:  42a8c9b665 contrib/completion: complete `git diff --merge-base`