Deprecating git diff ..; dealing with other ranges
Hello all,
I was in the process of deprecating git diff <commit>..<commit> as discussed here[1]. However, I ran into a weird case that I'm not sure how to deal with.
In t3430-rebase-merges.sh:382, we have the following test case which invokes git diff:
test_expect_success 'with --autosquash and --exec' ' git checkout -b with-exec H && echo Booh >B.t && test_tick && git commit --fixup B B.t && write_script show.sh <<-\EOF && subject="$(git show -s --format=%s HEAD)" => content="$(git diff HEAD^! | tail -n 1)" echo "$subject: $content" EOF test_tick && git rebase -ir --autosquash --exec ./show.sh A >actual && grep "B: +Booh" actual && grep "E: +Booh" actual && grep "G: +G" actual '
It gets caught in my attempt to only deprecate ..'s. Technically, it's undocumented behaviour and it only happens to work because git-diff accept ranges but it doesn't operate in an intuitive way.
I was just wondering what we should do about this case? Should we deprecate all invocations of git diff <range> except for the special case of git diff <commit>...<commit>, or should we _only_ deprecate git diff <commit>..<commit> and allow all other forms of ranges, even though it was undocumented behaviour?
Thanks,
Denton
Hi Denton,
Quoted 24 lines · Denton Liu
I was in the process of deprecating
git diff <commit>..<commit>as discussed here[1]. However, I ran into a weird case that I'm not sure how to deal with.In t3430-rebase-merges.sh:382, we have the following test case which invokes git diff:
test_expect_success 'with --autosquash and --exec' ' git checkout -b with-exec H && echo Booh >B.t && test_tick && git commit --fixup B B.t && write_script show.sh <<-\EOF && subject="$(git show -s --format=%s HEAD)" => content="$(git diff HEAD^! | tail -n 1)" echo "$subject: $content" EOF test_tick && git rebase -ir --autosquash --exec ./show.sh A >actual && grep "B: +Booh" actual && grep "E: +Booh" actual && grep "G: +G" actual '
Quoted 3 lines
It gets caught in my attempt to only deprecate ..'s. Technically, it's undocumented behaviour and it only happens to work because git-diff accept ranges but it doesn't operate in an intuitive way.
I beg to differ. git diff <commit>^! does exactly what I want: it shows the diff between the commit's first parent and the commit.
And I would not necessarily call this a "range". It is a short-hand. Can't you allow short-hands in git diff, and disallow only ranges that have an explicit .. in them? You might need to record that somewhere, but I think that should be easy enough.
Ciao,
Johannes
Quoted 13 lines
I was just wondering what we should do about this case? Should we deprecate all invocations of
git diff <range>except for the special case ofgit diff <commit>...<commit>, or should we _only_ deprecategit diff <commit>..<commit>and allow all other forms of ranges, even though it was undocumented behaviour?Thanks,
Denton
Hi,
Quoted 31 lines · Denton Liu
Hello all,
I was in the process of deprecating
git diff <commit>..<commit>as discussed here[1]. However, I ran into a weird case that I'm not sure how to deal with.In t3430-rebase-merges.sh:382, we have the following test case which invokes git diff:
test_expect_success 'with --autosquash and --exec' ' git checkout -b with-exec H && echo Booh >B.t && test_tick && git commit --fixup B B.t && write_script show.sh <<-\EOF && subject="$(git show -s --format=%s HEAD)" => content="$(git diff HEAD^! | tail -n 1)" echo "$subject: $content" EOF test_tick && git rebase -ir --autosquash --exec ./show.sh A >actual && grep "B: +Booh" actual && grep "E: +Booh" actual && grep "G: +G" actual 'It gets caught in my attempt to only deprecate ..'s. Technically, it's undocumented behaviour and it only happens to work because git-diff accept ranges but it doesn't operate in an intuitive way.
Quoted 5 lines
I was just wondering what we should do about this case? Should we deprecate all invocations of
git diff <range>except for the special case ofgit diff <commit>...<commit>, or should we _only_ deprecategit diff <commit>..<commit>and allow all other forms of ranges, even though it was undocumented behaviour?
There's a few angles I can think of to view this from:
First, commit^! is somewhat of a degenerate "range"; it includes only one commit and for non-merge commits, is equal to both commit~1..commit and commit~1...commit. The fact that those ranges are equal means that "git diff commit~1..commit" and "git diff commit~1...commit" will also give equal results, i.e. that this is not a case where confusion between '..' and '...' will cause any problems for the user. (Admittedly, I'm ignoring usage of ^! with a merge commit here; I've never seen anyone use it in such a case.)
Second, ^! is unlikely to cause confusion for users the way '..' vs '...' will, because the syntax makes no sense with diff anyway. It's totally magical, and when I came across it being used with diff instead of log, I had to test it out to determine what it did. (I do now find it handy and use it occasionally.) It's fairly difficult to explain to beginners -- I tried once and quickly gave up and used longer but more straightforward alternatives. So, IMO, this is only a convenience syntax for experts, and a syntax that won't be confused with other syntax out there, so there's no need to deprecate it.
Third, we have good reason to deprecate explicit usage of '..' with git diff, but even with those reasons some folks probably aren't convinced it's worth the effort. I want to avoid expanding scope, for fear of moving some people from the sidelines of "not worth the effort" to "this is a bad idea". So if there are other range syntax cases used in the wild (maybe 'git diff merge_commit^@' ?!?), we should just leave them be and allow them to continue working.
Hope that helps,
Elijah
Quoted 4 lines · Denton Liu
I was in the process of deprecating
git diff <commit>..<commit>as discussed here[1].
I didn't (and don't) advocate such a deprecation, FWIW, in that message. I simply do not think it is worth the cost.
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Quoted 8 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diff
I.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Am 12.03.19 um 22:01 schrieb Ævar Arnfjörð Bjarmason:
Quoted 19 lines · Andreas Schwab
Quoted 9 lines · Junio C Hamano
Quoted 4 lines
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diff
Quoted 6 lines
I.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Still, your and Andreas's use-case is reason enough *not* to deprecate diff A..B, IMO.
We wouldn't be able to remove .. wholesale anyway because diff A.. and diff ..B, where the missing endpoints are filled in with HEAD would have to live on.
-- Hannes
Quoted 17 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diff
Quoted 6 lines
I.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Doesn't this somewhat imply that although you use diff A..B here for convenience, that it's actually wrong since what you really want is A...B? Or said another way, the end goal of deprecating "diff "A..B" then later reinstating "diff A..B" to mean the same thing as "diff A...B" would actually be better even for your usecase?
Of course, switching to the removal period may just be too painful for too many folks since there are obviously people that use it, but I just want to see if I'm understanding correctly here.
Quoted 26 lines · On Mon, 18 Mar 2019 10:07:08 -0700 Elijah Newren <[email protected]> wrote:
Quoted 17 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diffQuoted 6 lines
I.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Quoted 5 lines
Doesn't this somewhat imply that although you use diff A..B here for convenience, that it's actually wrong since what you really want is A...B? Or said another way, the end goal of deprecating "diff "A..B" then later reinstating "diff A..B" to mean the same thing as "diff A...B" would actually be better even for your usecase?
I usually mean diff A..B in this case.
Thanks
Michal
Quoted 30 lines · Michal Suchánek
Quoted 26 lines · On Mon, 18 Mar 2019 10:07:08 -0700 Elijah Newren <[email protected]> wrote:
Quoted 23 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diffI.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Quoted 7 lines
Quoted 5 lines
Doesn't this somewhat imply that although you use diff A..B here for convenience, that it's actually wrong since what you really want is A...B? Or said another way, the end goal of deprecating "diff "A..B" then later reinstating "diff A..B" to mean the same thing as "diff A...B" would actually be better even for your usecase?
I usually mean diff A..B in this case.
Thanks for the feedback; somewhat odd that you and Ævar have the same usecase but want the opposite meaning, but good to know nonetheless.
Quoted 22 lines · Elijah Newren
Quoted 20 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
Not to shoot down this effort, just to add another similar thing I do regularly for ff-branches:
1. Copy/paste A..B fetch output
2. git log A..B
3. ^log^diffI.e. I just need to tell my terminal to re-run the same "log" command with "diff" instead of "log".
Quoted 7 lines
Quoted 3 lines
Of course as covered in the linked thread it doesn't work for some (non-ff) cases, and I'll sometimes end up cursing it and swapping around ".." for "..." with log/diff.
Doesn't this somewhat imply that although you use diff A..B here for convenience, that it's actually wrong since what you really want is A...B?
Yeah "..." would be more correct, but usually when I do this it's for things where the LHS hasn't diverged.
Quoted 3 lines
Or said another way, the end goal of deprecating "diff "A..B" then later reinstating "diff A..B" to mean the same thing as "diff A...B" would actually be better even for your usecase?
Yeah, it would be. Sometimes I need to go back and tweak it to be "..." instead of ".." now. When the two have different behavior I usually want the former.
Quoted 3 lines
Of course, switching to the removal period may just be too painful for too many folks since there are obviously people that use it, but I just want to see if I'm understanding correctly here.
I think we'd ideally migrate, but the conversion might be too painful. Junio doesn't seem excited in <[email protected]>
I'm not claiming that this ^log^diff use-case is common or anything, just noting a use-case I do use occasionally and mostly works now.
Quoted 9 lines · Andreas Schwab
Quoted 3 lines · Junio C Hamano
I however think it may be worth making sure that our docs do not encourage "diff A..B" and teach "diff A B" when comparing two endpoints. That can be done without changing anything in the code.
The nice thing about "diff A..B" is that you can c&p the output from the fetch run without the need to edit it.
I do this copy&paste too though I think in this case we could improve something to not copy&paste in the first place.
A..B from fetch is the same as branch@{1}..branch. If we have some shortcut similar to ^! but for reflog, that would be perfect (the branch part does not require much typing with tab completion).
Signature · 1 line
Duy
Quoted 3 lines · Duy Nguyen
A..B from fetch is the same as branch@{1}..branch. If we have some shortcut similar to ^! but for reflog, that would be perfect (the branch part does not require much typing with tab completion).
Tab completion is much slower than c&p, especially if the completion is ambigous.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Quoted 5 lines · Denton Liu
=> content="$(git diff HEAD^! | tail -n 1)"
...
It gets caught in my attempt to only deprecate ..'s. Technically, it's undocumented behaviour and it only happens to work because git-diff accept ranges but it doesn't operate in an intuitive way.
It reuses the same notation as that is used for ranges, but makes the notation mean something entirely different from ranges, because "diff" is about two endpoints.
And "git diff ^A B" (or "git diff B ^A") works like "git diff A B". So does "git diff A^!", for a single-parent commit A, work like "git diff A^ A".