[PATCH v2 04/13] Teach rebase interactive the mark command

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jörg Sommer
Date: Sunday, April 13, 2008 - 5:21 pm

This new command can be used to set symbolic marks for an commit while
doing a rebase. This symbolic name can later be used for merges or
resets.

The decision to use references for the marks and not files like done with
the rewritten commits for preserve merges was made to ensure no commit
objects get lost if prune is started while (a long term) rebase is
running. This also unifies the checking of the validity of marks and
references by using rev-parse for it.

The usage of : as the sign for marks conforms with the tag sign of
fast-export and fast-import.

Signed-off-by: Jörg Sommer <joerg@alea.gnuu.de>
---
 git-rebase--interactive.sh    |   37 ++++++++++++++++++++++++++++++++++++-
 t/t3404-rebase-interactive.sh |   17 +++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 531ee94..6ac316a 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -35,6 +35,8 @@ mark the corrected paths with 'git add <paths>', and
 run 'git rebase --continue'"
 export GIT_CHERRY_PICK_HELP
 
+mark_prefix=refs/rebase-marks/
+
 warn () {
 	echo "$*" >&2
 }
@@ -105,7 +107,13 @@ die_with_patch () {
 }
 
 cleanup_before_quit () {
-	rm -rf "$DOTEST"
+	rm -rf "$DOTEST" &&
+	for ref in "$GIT_DIR/$mark_prefix"*
+	do
+		test "$ref" = "$GIT_DIR/$mark_prefix*" && continue
+		git update-ref -d "${ref#$GIT_DIR/}" "${ref#$GIT_DIR/}" || \
+			return 1
+	done
 }
 
 die_abort () {
@@ -244,6 +252,19 @@ peek_next_command () {
 	sed -n "1s/ .*$//p" < "$TODO"
 }
 
+mark_to_ref () {
+	case "$1" in
+	:[!/]*)
+		# :/SOMETHING is a reference for the last commit whose
+                # message starts with SOMETHING
+		echo "$mark_prefix${1#:}"
+		;;
+	*)
+		echo "$1"
+		;;
+	esac
+}
+
 do_next () {
 	rm -f "$DOTEST"/message "$DOTEST"/author-script \
 		"$DOTEST"/amend || exit
@@ -321,6 +342,15 @@ do_next () {
 			die_with_patch $sha1 ""
 		fi
 		;;
+	mark)
+		mark_action_done
+
+		mark=$(mark_to_ref :${sha1#:})
+		git rev-parse --verify "$mark" > /dev/null 2>&1 && \
+			warn "mark $sha1 already exist; overwriting it"
+
+		git update-ref "$mark" HEAD || die "update-ref failed"
+		;;
 	*)
 		warn "Unknown command: $command $sha1 $rest"
 		die_with_patch $sha1 "Please fix this in the file $TODO."
@@ -533,10 +563,15 @@ do
 
 # Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
 #
+# In the todo insn whenever you need to refer to a commit, in addition
+# to the usual commit object name, you can use ':mark' syntax to refer
+# to a commit previously marked with the 'mark' insn.
+#
 # Commands:
 #  pick = use commit
 #  edit = use commit, but stop for amending
 #  squash = use commit, but meld into previous commit
+#  mark :mark = mark the current HEAD for later reference
 #
 # If you remove a line here THAT COMMIT WILL BE LOST.
 # However, if you remove everything, the rebase will be aborted.
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 8d29878..fa3560e 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -82,6 +82,9 @@ for line in $FAKE_LINES; do
 	case $line in
 	squash|edit)
 		action="$line";;
+	mark*)
+		echo "mark ${line#mark}"
+		echo "mark ${line#mark}" >> "$1";;
 	*)
 		echo sed -n "${line}s/^pick/$action/p"
 		sed -n "${line}p" < "$1".tmp
@@ -189,6 +192,20 @@ test_expect_success '-p handles "no changes" gracefully' '
 	test $HEAD = $(git rev-parse HEAD)
 '
 
+test_expect_success 'setting marks works' '
+	git checkout master &&
+	FAKE_LINES="mark:0 2 1 mark:42 3 edit 4" git rebase -i HEAD~4 &&
+	marks_dir=.git/refs/rebase-marks &&
+	test -d $marks_dir &&
+	test $(ls $marks_dir | wc -l) -eq 2 &&
+	test "$(git rev-parse HEAD~4)" = \
+		"$(git rev-parse refs/rebase-marks/0)" &&
+	test "$(git rev-parse HEAD~2)" = \
+		"$(git rev-parse refs/rebase-marks/42)" &&
+	git rebase --abort &&
+	ls $marks_dir | wc -l | grep -Fx 0
+'
+
 test_expect_success 'preserve merges with -p' '
 	git checkout -b to-be-preserved master^ &&
 	: > unrelated-file &&
-- 
1.5.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/4] Move redo merge code in a function, Jörg Sommer, (Sun Mar 23, 2:42 pm)
[PATCH 2/4] Rework redo_merge, Jörg Sommer, (Sun Mar 23, 2:42 pm)
Re: [PATCH 1/4] Move redo merge code in a function, Johannes Schindelin, (Sun Mar 23, 3:26 pm)
Re: [PATCH 2/4] Rework redo_merge, Johannes Schindelin, (Sun Mar 23, 3:29 pm)
Re: [PATCH 3/4] Add a function for get the parents of a commit, Johannes Schindelin, (Sun Mar 23, 3:33 pm)
Re: [PATCH 4/4] git-rebase -i: New option to support rebas ..., Johannes Schindelin, (Sun Mar 23, 3:41 pm)
Re: [PATCH 4/4] git-rebase -i: New option to support rebas ..., Johannes Schindelin, (Mon Mar 24, 6:08 am)
[PATCH/RFC 04/10] Move redo merge code in a function, Jörg Sommer, (Wed Apr 9, 4:58 pm)
[PATCH/RFC 05/10] Rework redo_merge, Jörg Sommer, (Wed Apr 9, 4:58 pm)
[PATCH/RFC 09/10] Select all lines with fake-editor, Jörg Sommer, (Wed Apr 9, 4:58 pm)
[PATCH v2 04/13] Teach rebase interactive the mark command, Jörg Sommer, (Sun Apr 13, 5:21 pm)
[PATCH v2 06/13] Move redo merge code in a function, Jörg Sommer, (Sun Apr 13, 5:21 pm)
[PATCH v2 09/13] Select all lines with fake-editor, Jörg Sommer, (Sun Apr 13, 5:21 pm)
[PATCH v2 11/13] Add option --first-parent, Jörg Sommer, (Sun Apr 13, 5:21 pm)
[PATCH v2 13/13] Add option --preserve-tags, Jörg Sommer, (Sun Apr 13, 5:21 pm)
[PATCH v2.1] Teach rebase interactive the mark command, Jörg Sommer, (Mon Apr 14, 3:39 am)
Re: [PATCH v2.1] Teach rebase interactive the mark command, Shawn O. Pearce, (Mon Apr 14, 4:29 pm)
mark parsing in fast-import, Jörg, (Sun Apr 20, 4:44 pm)
Re: mark parsing in fast-import, Shawn O. Pearce, (Sun Apr 20, 5:26 pm)
Re: mark parsing in fast-import, Jörg, (Mon Apr 21, 1:41 am)
Re: mark parsing in fast-import, Shawn O. Pearce, (Mon Apr 21, 4:59 pm)
Re: [PATCH v2 04/13] Teach rebase interactive the mark command, Johannes Schindelin, (Tue Apr 22, 1:52 am)
Re: mark parsing in fast-import, Jörg, (Tue Apr 22, 2:39 am)
Re: [PATCH v2 04/13] Teach rebase interactive the mark command, Johannes Schindelin, (Tue Apr 22, 3:31 am)
Re: mark parsing in fast-import, Shawn O. Pearce, (Tue Apr 22, 4:15 pm)
[PATCH v2] Make mark parsing much more restrictive, Jörg Sommer, (Fri Apr 25, 2:04 am)
[PATCH v2.2] Teach rebase interactive the mark command, Jörg Sommer, (Fri Apr 25, 2:44 am)
Re: [PATCH v2.2] Teach rebase interactive the mark command, Junio C Hamano, (Sat Apr 26, 11:13 pm)