From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
This is v2 of my attempt at keeping commits with no-parents-being-rewritten off
the rebase-i-p todo list. This was prompted by Avi Kivity's request to squash
commits on either side of a merge, but is something I had wanted as well without
fully realizing it.
Stephan Beyer pointed out his git sequencer branch already does this, contrary
to my incorrect reading of it. His rewrite of rebase-i-p changed how todo was
generated to follow these semantics, and nicely, too, so I replaced my initial
hacky algorithm for "only include commits with rewritten parents" with his.
The better implementation aside, I found Stephan's matching semantics
encouraging as if Avi, myself, and Stephan (plus others/the list involved in
past git sequencer discussions) all expect rebase-i-p to drop non-rewritten
commits, then the semantics should be intuitive and what most users expect.
Also, even though git sequencer has these semantics (and more), I'd like to see
this patch reviewed and applied anyway as I think it is a nice solution to the
current rebase-i-p shortcomings. And, assuming its approved, it can be applied
now instead of waiting for git sequencer to be finished, reviewed, and applied.
This is also my first patch series. I started a new thread--I'm not sure if I
was supposed to use Avi's original message id or not. Also, I cheated and put
the tests in the first commit instead of starting them as test_expect_failure
and gradually changing them to test_expect_success.
Stephen Haberman (7):
rebase-i-p: test to exclude commits from todo based on its parents
rebase-i-p: use HEAD for updating the ref instead of mapping OLDHEAD
rebase-i-p: delay saving current-commit to REWRITTEN if squashing
rebase-i-p: fix 'no squashing merges' tripping up non-merges
rebase-i-p: only list commits that require rewriting in todo
rebase-i-p: do not include non-first-parent commits touching UPSTREAM
rebase-i-p: if todo was reordered use HEAD as the rewritten parent
git-rebase--interactive.sh | 80 ++++++++++++------
t/t3411-rebase-preserve-around-merges.sh | 136 ++++++++++++++++++++++++++++++
2 files changed, 190 insertions(+), 26 deletions(-)
create mode 100644 t/t3411-rebase-preserve-around-merges.sh
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
If OLDHEAD was reordered in the todo, and its mapped NEWHEAD was used to set the
ref, commits reordered after OLDHEAD in the todo would should up as un-committed
changes.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 15 +--------------
1 files changed, 1 insertions(+), 14 deletions(-)
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
The first case was based off a script from Avi Kivity [off-list ref].
The second case includes a merge-of-a-merge to ensure both are included in todo.
Signed-off-by: Stephen Haberman <redacted>
---
t/t3411-rebase-preserve-around-merges.sh | 136 ++++++++++++++++++++++++++++++
1 files changed, 136 insertions(+), 0 deletions(-)
create mode 100644 t/t3411-rebase-preserve-around-merges.sh
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
If the current-commit was dumped to REWRITTEN, but then we squash the next
commit in to it, we have invalidated the HEAD was just written to REWRITTEN.
Instead, append the squash hash to current-commit and save both of them the next
time around.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
@@ -159,13 +159,18 @@ pick_one_preserving_merges () {iftest-f"$DOTEST"/current-committhen-current_commit=$(cat"$DOTEST"/current-commit)&&-gitrev-parseHEAD>"$REWRITTEN"/$current_commit&&-rm"$DOTEST"/current-commit||-die"Cannot write current commit's replacement sha1"+if["$fast_forward"=="t"]+then+cat"$DOTEST"/current-commit|whilereadcurrent_commit+do+gitrev-parseHEAD>"$REWRITTEN"/$current_commit+done+rm"$DOTEST"/current-commit||+die"Cannot write current commit's replacement sha1"+fifi-echo$sha1>"$DOTEST"/current-commit+echo$sha1>>"$DOTEST"/current-commit# rewrite parents; if none were rewritten, we can fast-forward.new_parents=
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
This seems like the best guess we can make until git sequencer marks are
available. That being said, within the context of re-ordering a commit before
its parent in todo, I think applying it on top of the current commit seems like
a reasonable assumption of what the user intended.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
@@ -179,6 +179,15 @@ pick_one_preserving_merges () {iftest-f"$REWRITTEN"/$pthennew_p=$(cat"$REWRITTEN"/$p)++# If the todo reordered commits, and our parent is marked for+# rewriting, but hasn't been gotten to yet, assume the user meant to+# drop it on top of the current HEAD+iftest-z"$new_p"+then+new_p=$(gitrev-parseHEAD)+fi+test$p!=$new_p&&fast_forward=fcase"$new_parents"in*$new_p*)
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
This is heavily based on Stephan Beyer's git sequencer rewrite of rebase-i-p.
Each commit is still found by rev-list UPSTREAM..HEAD, but a commit is only
included in todo if at least one its parents has been marked for rewriting.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 26 ++++++++++++++++++++++++--
1 files changed, 24 insertions(+), 2 deletions(-)
@@ -561,9 +561,31 @@ first and then run 'git rebase --continue' again."SHORTHEAD=$(gitrev-parse--short$HEAD)SHORTONTO=$(gitrev-parse--short$ONTO)gitrev-list$MERGES_OPTION--pretty=oneline--abbrev-commit\---abbrev=7--reverse--left-right--cherry-pick\+--abbrev=7--reverse--left-right--cherry-pick--topo-order\$UPSTREAM...$HEAD|\-sed-n"s/^>/pick /p">"$TODO"+sed-n"s/^>//p"|whilereadshortsha1rest+do+iftestt!="$PRESERVE_MERGES"+then+echo"pick $shortsha1$rest">>"$TODO"+else+sha1=$(gitrev-parse$shortsha1)+preserve=t+forpin$(gitrev-list--parents-1$sha1|cut-d' '-f2-)+do+iftest-f"$REWRITTEN"/$p+then+preserve=f+fi+done+iftestf="$preserve"+then+touch"$REWRITTEN/$sha1"+echo"pick $shortsha1$rest">>"$TODO"+fi+fi+done+cat>>"$TODO"<<EOF# Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
This covers an odd boundary case found by Avi Kivity's script where a branch
coming off of UPSTREAM is merged into HEAD. Initially it show up in
UPSTREAM..HEAD, but technically UPSTREAM is not moving, the rest of head is, so
we should not need to rewrite the merge.
This adds a check saying we can keep `preserve=t` if `p=UPSTREAM`...unless this
is the first first-parent commit in our UPSTREAM..HEAD rev-list, which could
very well point to UPSTREAM, but we still need to consider it as rewritten so we
start pulling in the rest of the UPSTREAM..HEAD commits that point to it.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
@@ -553,6 +553,7 @@ first and then run 'git rebase --continue' again."die"Could not init rewritten commits"doneMERGES_OPTION=+first_after_upstream="$(gitrev-list--reverse--first-parent$UPSTREAM..$HEAD|head-n1)"elseMERGES_OPTION=--no-mergesfi
@@ -573,7 +574,7 @@ first and then run 'git rebase --continue' again."preserve=tforpin$(gitrev-list--parents-1$sha1|cut-d' '-f2-)do-iftest-f"$REWRITTEN"/$p+iftest-f"$REWRITTEN"/$p-a\($p!=$UPSTREAM-o$sha1=$first_after_upstream\)thenpreserve=ffi
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
Also only check out the first parent if this commit if not a squash--if it is a
squash, we want to explicitly ignore the parent and leave the wc as is, as
cherry-pick will apply the squash on top of it.
Signed-off-by: Stephen Haberman <redacted>
---
git-rebase--interactive.sh | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
@@ -198,15 +198,19 @@ pick_one_preserving_merges () {die"Cannot fast forward to $sha1";;f)-test"a$1"=a-n&&die"Refusing to squash a merge: $sha1"-first_parent=$(expr"$new_parents":' \([^ ]*\)')-# detach HEAD to current parent-outputgitcheckout$first_parent2>/dev/null||-die"Cannot move HEAD to $first_parent"++if["$1"!="-n"]+then+# detach HEAD to current parent+outputgitcheckout$first_parent2>/dev/null||+die"Cannot move HEAD to $first_parent"+ficase"$new_parents"in' '*' '*)+test"a$1"=a-n&&die"Refusing to squash a merge: $sha1"+# redo mergeauthor_script=$(get_author_ident_from_commit$sha1)eval"$author_script"
From: Stephen Haberman <hidden> Date: 2016-06-15 22:45:27
This is v2 of my attempt at keeping commits with
no-parents-being-rewritten off the rebase-i-p todo list.
I forgot to mention, this series almost certainly conflicts with pu's
sh/maint-rebase3. Given that pu is not next, I think I did the right
thing by keeping this series separate, but I can merge them into one
series if that is preferable.
Thanks,
Stephen