Skip to content

Commit 2d6ca6e

Browse files
drafnelgitster
authored andcommitted
git-rebase--interactive.sh: rework skip_unnecessary_picks
Commit cd035b1 introduced the exec command to interactive rebase. In doing so, it modified the way that skip_unnecessary_picks iterates through the list of rebase commands so that it avoided collapsing multiple spaces into a single space. This is necessary for example if the argument to the exec command contains a path with multiple spaces in it. The way it did this was by reading each line of rebase commands into a single variable, and then breaking the individual components out using echo, sed, and cut. It used the individual broken-out components for decision making, and was still able to write the original line to the output file from the variable it had saved it in. But, since we only really need to look at anything other than the first element of the line when a 'pick' command is encountered, and even that is only necessary when we are still searching for "unnecessary" picks, and since newer rebase commands like 'exec' may not even require a sha1 field, let's make our read statement parse its input into a "command" variable, and a "rest" variable, and then only break out the sha1 from $rest, and call git-rev-parse, when absolutely necessary. I think this future proofs this subroutine, avoids calling git-rev-parse unnecessarily, and possibly with bogus arguments, and still accomplishes the goal of not mangling the $rest of the rebase command. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2caf20c commit 2d6ca6e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

git-rebase--interactive.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,25 +619,30 @@ do_rest () {
619619
# skip picking commits whose parents are unchanged
620620
skip_unnecessary_picks () {
621621
fd=3
622-
while read -r line
622+
while read -r command rest
623623
do
624-
command=$(echo "$line" | sed 's/ */ /' | cut -d ' ' -f 1)
625-
sha1=$(echo "$line" | sed 's/ */ /' | cut -d ' ' -f 2)
626-
rest=$(echo "$line" | sed 's/ */ /' | cut -d ' ' -f 3-)
627624
# fd=3 means we skip the command
628-
case "$fd,$command,$(git rev-parse --verify --quiet "$sha1"^)" in
629-
3,pick,"$ONTO"*|3,p,"$ONTO"*)
625+
case "$fd,$command" in
626+
3,pick|3,p)
630627
# pick a commit whose parent is current $ONTO -> skip
631-
ONTO=$sha1
628+
sha1=$(echo "$rest" | cut -d ' ' -f 1)
629+
case "$(git rev-parse --verify --quiet "$sha1"^)" in
630+
"$ONTO"*)
631+
ONTO=$sha1
632+
;;
633+
*)
634+
fd=1
635+
;;
636+
esac
632637
;;
633-
3,#*|3,,*)
638+
3,#*|3,)
634639
# copy comments
635640
;;
636641
*)
637642
fd=1
638643
;;
639644
esac
640-
echo "$line" >&$fd
645+
echo "$command${rest:+ }$rest" >&$fd
641646
done <"$TODO" >"$TODO.new" 3>>"$DONE" &&
642647
mv -f "$TODO".new "$TODO" &&
643648
case "$(peek_next_command)" in

0 commit comments

Comments
 (0)