mbox series

[v4,0/5] cleanup ra/rebase-i-more-options

Message ID 20200527173356.47364-1-phillip.wood123@gmail.com (mailing list archive)
Headers show
Series cleanup ra/rebase-i-more-options | expand

Message

Phillip Wood May 27, 2020, 5:33 p.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Thanks to Danh for the review, I've updated the tests accordingly.

Phillip Wood (2):
  rebase -i: support --committer-date-is-author-date
  rebase -i: support --ignore-date

Rohit Ashiwal (3):
  rebase -i: add --ignore-whitespace flag
  sequencer: rename amend_author to author_to_free
  rebase: add --reset-author-date

 Documentation/git-rebase.txt           |  33 +++-
 builtin/rebase.c                       |  46 ++++--
 sequencer.c                            | 111 ++++++++++++-
 sequencer.h                            |   2 +
 t/t3422-rebase-incompatible-options.sh |   2 -
 t/t3436-rebase-more-options.sh         | 209 +++++++++++++++++++++++++
 6 files changed, 379 insertions(+), 24 deletions(-)
 create mode 100755 t/t3436-rebase-more-options.sh

Range-diff against v3:
1:  df8c4ed2e9 = 1:  df8c4ed2e9 rebase -i: add --ignore-whitespace flag
2:  df44a0bde6 ! 2:  ad21e5d8fb rebase -i: support --committer-date-is-author-date
    @@ t/t3436-rebase-more-options.sh: test_expect_success '--ignore-whitespace is reme
     +test_expect_success '--committer-date-is-author-date works with apply backend' '
     +	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
     +	git rebase --apply --committer-date-is-author-date HEAD^ &&
    -+	git log -1 --pretty="format:%ai" >authortime &&
    -+	git log -1 --pretty="format:%ci" >committertime &&
    ++	git log -1 --pretty=%ai >authortime &&
    ++	git log -1 --pretty=%ci >committertime &&
     +	test_cmp authortime committertime
     +'
     +
     +test_expect_success '--committer-date-is-author-date works with merge backend' '
     +	GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
     +	git rebase -m --committer-date-is-author-date HEAD^ &&
    -+	git log -1 --pretty="format:%ai" >authortime &&
    -+	git log -1 --pretty="format:%ci" >committertime &&
    ++	git log -1 --pretty=%ai >authortime &&
    ++	git log -1 --pretty=%ci >committertime &&
     +	test_cmp authortime committertime
     +'
     +
     +test_expect_success '--committer-date-is-author-date works with rebase -r' '
     +	git checkout side &&
     +	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
     +	git rebase -r --root --committer-date-is-author-date &&
    -+	git log --pretty="format:%ai" >authortime &&
    -+	git log --pretty="format:%ci" >committertime &&
    ++	git log --pretty=%ai >authortime &&
    ++	git log --pretty=%ci >committertime &&
     +	test_cmp authortime committertime
     +'
     +
     +test_expect_success '--committer-date-is-author-date works when forking merge' '
     +	git checkout side &&
     +	GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
     +	git rebase -r --root --strategy=resolve --committer-date-is-author-date &&
    -+	git log --pretty="format:%ai" >authortime &&
    -+	git log --pretty="format:%ci" >committertime &&
    ++	git log --pretty=%ai >authortime &&
    ++	git log --pretty=%ci >committertime &&
     +	test_cmp authortime committertime
     +
     +'
3:  fa3d4856b4 = 3:  af92e29cf9 sequencer: rename amend_author to author_to_free
4:  96657233d4 ! 4:  4399dc19b6 rebase -i: support --ignore-date
    @@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
     +test_expect_success '--ignore-date works with apply backend' '
     +	git commit --amend --date="$GIT_AUTHOR_DATE" &&
     +	git rebase --apply --ignore-date HEAD^ &&
    -+	git log -1 --pretty="format:%ai" >authortime &&
    ++	git log -1 --pretty=%ai >authortime &&
     +	grep "+0000" authortime
     +'
     +
     +test_expect_success '--ignore-date works with merge backend' '
     +	git commit --amend --date="$GIT_AUTHOR_DATE" &&
     +	git rebase --ignore-date -m HEAD^ &&
    -+	git log -1 --pretty="format:%ai" >authortime &&
    ++	git log -1 --pretty=%ai >authortime &&
     +	grep "+0000" authortime
     +'
     +
    @@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
     +	echo resolved >foo &&
     +	git add foo &&
     +	git rebase --continue &&
    -+	git log --pretty=%ai >authortime &&
    ++	git log -1 --pretty=%ai >authortime &&
     +	grep +0000 authortime
     +'
     +
5:  828155baba ! 5:  a11db78eb4 rebase: add --reset-author-date
    @@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
      	git commit --amend --date="$GIT_AUTHOR_DATE" &&
     -	git rebase --apply --ignore-date HEAD^ &&
     +	git rebase --apply --reset-author-date HEAD^ &&
    - 	git log -1 --pretty="format:%ai" >authortime &&
    + 	git log -1 --pretty=%ai >authortime &&
      	grep "+0000" authortime
      '
      
    @@ t/t3436-rebase-more-options.sh: test_expect_success '--committer-date-is-author-
      	git commit --amend --date="$GIT_AUTHOR_DATE" &&
     -	git rebase --ignore-date -m HEAD^ &&
     +	git rebase --reset-author-date -m HEAD^ &&
    - 	git log -1 --pretty="format:%ai" >authortime &&
    + 	git log -1 --pretty=%ai >authortime &&
      	grep "+0000" authortime
      '

Comments

Junio C Hamano May 27, 2020, 9:10 p.m. UTC | #1
Phillip Wood <phillip.wood123@gmail.com> writes:

>     -+	git log -1 --pretty="format:%ai" >authortime &&
>     ++	git log -1 --pretty=%ai >authortime &&

It probably wouldn't make too much of a difference in real life, but
I think "--format=%ai" is how the above is customary written.

Some history.

The --pretty="format:<string with per-cent placeholder>" came first,
with an explicit goal of giving us enough flexibility to mimick
canned "pretty print" formats like --pretty=medium, --pretty=short,
etc. (note: it was *not* part of the goal to actually replace the
implementation of canned formats with hardcoded set of placeholder
strings).

If you run "git log --pretty=medium -2", you'd observe that the
topmost commit is shown immediately without any preceding blank
line, then an extra blank line is shown, and then the second commit
is shown, and after that, the output ends without any extra blank
line.  With respect to the "extra blank line", we call this
"separator semantics"---an extra blank is given _between_ two items
that are shown.

Like "git log --pretty=medium", the "format:<custom>" pretty print
format uses the "separator semantics".  There is no "extra LF" after
showing the last item.

Of course, the "separator" behaviour was later found to be
cumbersome if we wanted to mimick "--pretty=oneline".  The payload
of each item in the oneline output format lacks the terminating LF,
so instead of an extra LF between two items, we want an extra LF
after every item.  This, in contrast to "separator" semantics, is
called "terminator" semantics and --pretty="tformat:<custom>" was
introduced to allow.

Later, when we introduced --format=<format>, we made it so that 

 (1) when <format> is equal to one of the canned format names,
     "--format=<format>" is equivalent to "--<format>".

 (2) otherwise, when <format> has placeholders, "--format=<format>"
     acts the same way as "--pretty=tformat:<format>".

as we found out that people are often using custom format that
consists of only one line of payload, quite often as a way to
extract a handful of "fields" from each commit object.

So given all of the above, the "let's grab the author-time in iso
format and nothing else from each commit object" in the above
excerpt from your test is the use case for which --format=%ai was
designed.