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

[PATCH 3/7] git-rebase--interactive: group all $preserve_merges code

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
Jul 18, 2012, 07:27 UTC
Message-ID
<1342596455-17046-4-git-send-email-martin.von.zweigbergk@gmail.com>
In-Reply-To
<1342596455-17046-3-git-send-email-martin.von.zweigbergk@gmail.com>
The code in git-rebase--interactive that creates the todo file
contains if-blocks that depend on whether $preserve_merges is
active. There is only a very small amount of code in between that is
shared with non-merge-preserving code path, so remove the repeated
conditions and duplicate the small amount of shared code instead.
---
 git-rebase--interactive.sh | 69 ++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 36 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index fa722b6..4bb8e3f 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -793,28 +793,6 @@ mkdir "$state_dir" || die "Could not create temporary $state_dir"
 
 : > "$state_dir"/interactive || die "Could not mark as interactive"
 write_basic_state
-if test t = "$preserve_merges"
-then
-	if test -z "$rebase_root"
-	then
-		mkdir "$rewritten" &&
-		for c in $(git merge-base --all $orig_head $upstream)
-		do
-			echo $onto > "$rewritten"/$c ||
-				die "Could not init rewritten commits"
-		done
-	else
-		mkdir "$rewritten" &&
-		echo $onto > "$rewritten"/root ||
-			die "Could not init rewritten commits"
-	fi
-	# No cherry-pick because our first pass is to determine
-	# parents to rewrite and skipping dropped commits would
-	# prematurely end our probe
-	merges_option=
-else
-	merges_option="--no-merges --cherry-pick"
-fi
 
 shorthead=$(git rev-parse --short $orig_head)
 shortonto=$(git rev-parse --short $onto)
@@ -839,16 +817,30 @@ add_pick_line () {
 	printf '%s\n' "${comment_out}pick $1 $2" >>"$todo"
 }
 
-git rev-list $merges_option --pretty=oneline --abbrev-commit \
-	--abbrev=7 --reverse --left-right --topo-order \
-	$revisions | \
-	sed -n "s/^>//p" |
-while read -r shortsha1 rest
-do
-	if test t != "$preserve_merges"
+if test t = "$preserve_merges"
+then
+	if test -z "$rebase_root"
 	then
-		add_pick_line $shortsha1 "$rest"
+		mkdir "$rewritten" &&
+		for c in $(git merge-base --all $orig_head $upstream)
+		do
+			echo $onto > "$rewritten"/$c ||
+				die "Could not init rewritten commits"
+		done
 	else
+		mkdir "$rewritten" &&
+		echo $onto > "$rewritten"/root ||
+			die "Could not init rewritten commits"
+	fi
+	# No cherry-pick because our first pass is to determine
+	# parents to rewrite and skipping dropped commits would
+	# prematurely end our probe
+	git rev-list --pretty=oneline --abbrev-commit \
+		--abbrev=7 --reverse --left-right --topo-order \
+		$revisions |
+	sed -n "s/^>//p" |
+	while read -r shortsha1 rest
+	do
 		sha1=$(git rev-parse $shortsha1)
 		if test -z "$rebase_root"
 		then
@@ -868,12 +860,8 @@ do
 			touch "$rewritten"/$sha1
 			add_pick_line $shortsha1 "$rest"
 		fi
-	fi
-done
-
-# Watch for commits that been dropped by --cherry-pick
-if test t = "$preserve_merges"
-then
+	done
+	# Watch for commits that been dropped by --cherry-pick
 	mkdir "$dropped"
 	# Save all non-cherry-picked changes
 	git rev-list $revisions --left-right --cherry-pick | \
@@ -895,6 +883,15 @@ then
 			rm "$rewritten"/$rev
 		fi
 	done
+else
+	git rev-list --no-merges --cherry-pick --pretty=oneline --abbrev-commit \
+		--abbrev=7 --reverse --left-right --topo-order \
+		$revisions |
+	sed -n "s/^>//p" |
+	while read -r shortsha1 rest
+	do
+		add_pick_line $shortsha1 "$rest"
+	done
 fi
 
 test -s "$todo" || echo noop >> "$todo"
-- 
1.7.11.1.104.ge7b44f1
Previous: Martin von ZweigbergkNext: Martin von Zweigbergk
Message 4 of 15 in “correctly calculate patches to rebase”
  1. 0/7 correctly calculate patches to rebaseMartin von Zweigbergk, Jul 18, 2012
  2. 1/7 git-rebase--am.sh: avoid special-casing --keep-emptyMartin von Zweigbergk, Jul 18, 2012
  3. 2/7 git-rebase--interactive.sh: extract function for adding "pick" lineMartin von Zweigbergk, Jul 18, 2012
  4. 3/7 git-rebase--interactive: group all $preserve_merges codeMartin von Zweigbergk, Jul 18, 2012
  5. 4/7 git-rebase--interactive.sh: look up subject in add_pick_lineMartin von Zweigbergk, Jul 18, 2012
  6. 5/7 rebase -p: use --cherry-mark for todo fileMartin von Zweigbergk, Jul 18, 2012
  7. 6/7 rebase -p: don't request --left-right only to ignore left sideMartin von Zweigbergk, Jul 18, 2012
  8. 7/7 rebase (without -p): correctly calculate patches to rebaseMartin von Zweigbergk, Jul 18, 2012
  9. Johannes SixtJul 20, 2012
  10. Martin von ZweigbergkJul 20, 2012
  11. Johannes SixtJul 20, 2012
  12. Martin von ZweigbergkJul 20, 2012
  13. Junio C HamanoJul 22, 2012
  14. Neil HormanJul 18, 2012
  15. Martin von ZweigbergkJul 18, 2012

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.