git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= <cmn@elego.de>
To: git@vger.kernel.org
Subject: [RFC PATCH v2] Chain squash!/fixup! commits on autosquash
Date: Tue, 19 Apr 2011 17:54:22 +0200	[thread overview]
Message-ID: <20110419155417.GA13042@bee.lab.cmartin.tk> (raw)

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. Applied lines are given priority when looking for
modifications. Thus, if one has these commits

    944f57d fixup! squash! six
    3512067 fixup! squash! squash! six
    49af780 fixup! fixup! one
    df6f708 fixup! one
    6ac57d9 one
    6e754da squash! squash! six
    733844b squash! six
    e9de3cc six
    76990c9 five

they will be correctly reordered to

    pick e9de3cc six
    squash 733844b squash! six
    squash 6e754da squash! squash! six
    fixup 944f57d fixup! squash! six
    fixup 3512067 fixup! squash! squash! six
    pick 6ac57d9 one
    fixup df6f708 fixup! one
    fixup 49af780 fixup! fixup! one
---

To be honest, I'm not sure if we want to support something like this,
but it seemed too crazy not to try.

This is an attempt to fix
http://thread.gmane.org/gmane.comp.version-control.git/170883 (rebase
autosquash doesn't recognise a chain of fixups, 2011-04-05)

Cheers,
   cmn

 git-rebase--interactive.sh |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..5e7b393 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -692,16 +692,28 @@ rearrange_squash () {
 	test -s "$1.sq" || return
 
 	used=
+	applied=
+	RE="$1.re"
+	skiplines=0
+	# Initialize the list with the first line from the input
+	head -n 1 "$1" > $RE
 	while read -r pick sha1 message
 	do
+		echo "dealing with $sha1 skiplines=$skiplines" >> "rebase.log"
 		case " $used" in
-		*" $sha1 "*) continue ;;
+		*" $sha1 "*) next_input_line "$skiplines" "$1" "$RE"; skiplines="$(expr $skiplines + 1)"; continue ;;
+		esac
+		# 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
-		printf '%s\n' "$pick $sha1 $message"
 		used="$used$sha1 "
+		emitted=0;
 		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
@@ -715,15 +727,29 @@ rearrange_squash () {
 				case "$message" in "$msg"*) emit=1;; esac ;;
 			esac
 			if test $emit = 1; then
+				emitted=1
 				printf '%s\n' "$action $squash $action! $msg"
-				used="$used$squash "
+				applied="$applied$squash "
+				echo "$action $squash $action! $msg" >> "$RE"
 			fi
 		done <"$1.sq"
-	done >"$1.rearranged" <"$1"
+
+		# If no lines were emitted, it means we don't need take an
+		# early look to any more lines, so put the next one from the input into the queue
+		if test "$emmited" != 1; then
+			next_input_line "$skiplines" "$1" "$RE"
+			skiplines="$(expr $skiplines + 1)"
+		fi
+
+	done >"$1.rearranged" <"$RE"
 	cat "$1.rearranged" >"$1"
 	rm -f "$1.sq" "$1.rearranged"
 }
 
+next_input_line () {
+	tail --lines="+$1" "$2" | head -n 1 >> "$3"
+}
+
 LF='
 '
 parse_onto () {
-- 
1.7.4.2.437.g4fc7e.dirty

                 reply	other threads:[~2011-04-19 15:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110419155417.GA13042@bee.lab.cmartin.tk \
    --to=cmn@elego.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).