Commit 3f9de99f9b4d3da34a06dfce54134ff891684df9

Stefan Sperling 2019-07-24T22:24:09

histedit: make folding work across dropped commits

diff --git a/got/got.c b/got/got.c
index 3dd118c..b5341e1 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4132,8 +4132,10 @@ get_folded_commits(struct got_histedit_list_entry *hle)
 	struct got_histedit_list_entry *prev, *folded = NULL;
 
 	prev = TAILQ_PREV(hle, got_histedit_list, entry);
-	while (prev && prev->cmd->code == GOT_HISTEDIT_FOLD) {
-		folded = prev;
+	while (prev && (prev->cmd->code == GOT_HISTEDIT_FOLD ||
+	    prev->cmd->code == GOT_HISTEDIT_DROP)) {
+		if (prev->cmd->code == GOT_HISTEDIT_FOLD)
+			folded = prev;
 		prev = TAILQ_PREV(prev, got_histedit_list, entry);
 	}
 
@@ -4158,6 +4160,10 @@ histedit_edit_logmsg(struct got_histedit_list_entry *hle,
 	folded = get_folded_commits(hle);
 	if (folded) {
 		while (folded != hle) {
+			if (folded->cmd->code == GOT_HISTEDIT_DROP) {
+				folded = TAILQ_NEXT(folded, entry);
+				continue;
+			}
 			err = append_folded_commit_msg(&new_msg, folded,
 			    logmsg, repo);
 			if (err)
diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh
index 98604e6..cafb3a5 100755
--- a/regress/cmdline/histedit.sh
+++ b/regress/cmdline/histedit.sh
@@ -338,6 +338,10 @@ function test_histedit_fold {
 	git_commit $testroot/repo -m "committing to zeta on master"
 	local old_commit2=`git_show_head $testroot/repo`
 
+	echo "modified delta on master" > $testroot/repo/gamma/delta
+	git_commit $testroot/repo -m "committing to delta on master"
+	local old_commit3=`git_show_head $testroot/repo`
+
 	got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
 	ret="$?"
 	if [ "$ret" != "0" ]; then
@@ -346,7 +350,8 @@ function test_histedit_fold {
 	fi
 
 	echo "fold $old_commit1" > $testroot/histedit-script
-	echo "pick $old_commit2" >> $testroot/histedit-script
+	echo "drop $old_commit2" >> $testroot/histedit-script
+	echo "pick $old_commit3" >> $testroot/histedit-script
 	echo "mesg committing folded changes" >> $testroot/histedit-script
 
 	(cd $testroot/wt && got histedit -F $testroot/histedit-script \
@@ -357,6 +362,7 @@ function test_histedit_fold {
 
 	local short_old_commit1=`trim_obj_id 28 $old_commit1`
 	local short_old_commit2=`trim_obj_id 28 $old_commit2`
+	local short_old_commit3=`trim_obj_id 28 $old_commit3`
 	local short_new_commit1=`trim_obj_id 28 $new_commit1`
 	local short_new_commit2=`trim_obj_id 28 $new_commit2`
 
@@ -365,8 +371,11 @@ function test_histedit_fold {
 	echo "A  epsilon/new" >> $testroot/stdout.expected
 	echo "$short_old_commit1 ->  fold commit: committing changes" \
 		>> $testroot/stdout.expected
-	echo "G  epsilon/zeta" >> $testroot/stdout.expected
-	echo -n "$short_old_commit2 -> $short_new_commit2: " \
+	echo -n "$short_old_commit2 ->  " >> $testroot/stdout.expected
+	echo "drop commit: committing to zeta on master" \
+		>> $testroot/stdout.expected
+	echo "G  gamma/delta" >> $testroot/stdout.expected
+	echo -n "$short_old_commit3 -> $short_new_commit2: " \
 		>> $testroot/stdout.expected
 	echo "committing folded changes" >> $testroot/stdout.expected
 	echo "Switching work tree to refs/heads/master" \