git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] Chain squash!/fixup! commits on autosquash

From
Carlos Martín Nieto <cmn@elego.de>
Date
Apr 11, 2011, 15:34 UTC
Message-ID
<1302536064-3922-1-git-send-email-cmn@elego.de>
If one has the following commits
    5154127 fixup! fixup! one
    0d130d8 fixup! one
    0869d30 one

current code will only rearrange 0d130d8 because it thinks it has already checked for commits that modify it.

Separate the idea of an 'used' and an 'applied' line. Applied lines are the ones that have been moved to modify some commit whilst used lines are the ones for which we have tried to find modifications. ---

This supports the case I originally mentioned. It however breaks quite badly if one has two chains, such as

    0792561 fixup! squash! squash! six
    e72100f squash! squash! six
    90187b8 fixup! fixup! one
    6facd7d fixup! one
    4f48f55 one
    733844b squash! six
    e9de3cc six
    76990c9 five
    db0d525 one

because it will try to add 0792561 as a fixup to e72100f. However, as it has moved, it is made into a fixup of 90187b8, which is definitely bad (not that I think anybody would ever have such a chain in real life).

This should be fixable by modifying the loop a bit so it doesn't read the next line on each iteration so we can feed it the current line. Would you be interested in such a patch? For me this is a bit more elegant than removing the "fixup!" on commit (though my shell skills aren't that great).

 git-rebase--interactive.sh |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..a681f47 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -692,16 +692,22 @@ rearrange_squash () {
 	test -s "$1.sq" || return
 
 	used=
+	applied=
 	while read -r pick sha1 message
 	do
 		case " $used" in
 		*" $sha1 "*) continue ;;
 		esac
-		printf '%s\n' "$pick $sha1 $message"
+		# If it's been applied, we don't want to output the "pick" line
+		case " $applied" in
+			*" $sha1 "*) ;;
+			*) printf '%s\n' "$pick $sha1 $message";;
+		esac
 		used="$used$sha1 "
 		while read -r squash action msg
 		do
-			case " $used" in
+			# Ignore the commits we've already dealt with
+			case " $used $applied " in
 			*" $squash "*) continue ;;
 			esac
 			emit=0
@@ -716,7 +722,7 @@ rearrange_squash () {
 			esac
 			if test $emit = 1; then
 				printf '%s\n' "$action $squash $action! $msg"
-				used="$used$squash "
+				applied="$applied$squash "
 			fi
 		done <"$1.sq"
 	done >"$1.rearranged" <"$1"
-- 
1.7.4.1
Message 1 of 1 in “Chain squash!/fixup! commits on autosquash”
  1. Chain squash!/fixup! commits on autosquashCarlos Martín Nieto, Apr 11, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.