Skip to content

Commit ca3d446

Browse files
winksavillegitster
authored andcommitted
rebase: remove unused code paths from git_rebase__interactive__preserve_merges
Since git_rebase__interactive__preserve_merges is now always called with $preserve_merges = t we can remove the unused code paths. Signed-off-by: Wink Saville <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c04549b commit ca3d446

File tree

1 file changed

+69
-83
lines changed

1 file changed

+69
-83
lines changed

git-rebase--interactive.sh

Lines changed: 69 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -982,100 +982,86 @@ git_rebase__interactive__preserve_merges () {
982982
setup_reflog_action
983983
init_basic_state
984984

985-
if test t = "$preserve_merges"
985+
if test -z "$rebase_root"
986986
then
987-
if test -z "$rebase_root"
988-
then
989-
mkdir "$rewritten" &&
990-
for c in $(git merge-base --all $orig_head $upstream)
991-
do
992-
echo $onto > "$rewritten"/$c ||
993-
die "$(gettext "Could not init rewritten commits")"
994-
done
995-
else
996-
mkdir "$rewritten" &&
997-
echo $onto > "$rewritten"/root ||
987+
mkdir "$rewritten" &&
988+
for c in $(git merge-base --all $orig_head $upstream)
989+
do
990+
echo $onto > "$rewritten"/$c ||
998991
die "$(gettext "Could not init rewritten commits")"
999-
fi
1000-
# No cherry-pick because our first pass is to determine
1001-
# parents to rewrite and skipping dropped commits would
1002-
# prematurely end our probe
1003-
merges_option=
992+
done
1004993
else
1005-
merges_option="--no-merges --cherry-pick"
994+
mkdir "$rewritten" &&
995+
echo $onto > "$rewritten"/root ||
996+
die "$(gettext "Could not init rewritten commits")"
1006997
fi
1007998

999+
# No cherry-pick because our first pass is to determine
1000+
# parents to rewrite and skipping dropped commits would
1001+
# prematurely end our probe
1002+
merges_option=
1003+
10081004
init_revisions_and_shortrevisions
10091005

1010-
if test t != "$preserve_merges"
1011-
then
1012-
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
1013-
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
1014-
die "$(gettext "Could not generate todo list")"
1015-
else
1016-
format=$(git config --get rebase.instructionFormat)
1017-
# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
1018-
git rev-list $merges_option --format="%m%H ${format:-%s}" \
1019-
--reverse --left-right --topo-order \
1020-
$revisions ${restrict_revision+^$restrict_revision} | \
1021-
sed -n "s/^>//p" |
1022-
while read -r sha1 rest
1023-
do
1006+
format=$(git config --get rebase.instructionFormat)
1007+
# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
1008+
git rev-list $merges_option --format="%m%H ${format:-%s}" \
1009+
--reverse --left-right --topo-order \
1010+
$revisions ${restrict_revision+^$restrict_revision} | \
1011+
sed -n "s/^>//p" |
1012+
while read -r sha1 rest
1013+
do
10241014

1025-
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
1026-
then
1027-
comment_out="$comment_char "
1028-
else
1029-
comment_out=
1030-
fi
1015+
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
1016+
then
1017+
comment_out="$comment_char "
1018+
else
1019+
comment_out=
1020+
fi
10311021

1032-
if test -z "$rebase_root"
1033-
then
1034-
preserve=t
1035-
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
1036-
do
1037-
if test -f "$rewritten"/$p
1038-
then
1039-
preserve=f
1040-
fi
1041-
done
1042-
else
1043-
preserve=f
1044-
fi
1045-
if test f = "$preserve"
1046-
then
1047-
touch "$rewritten"/$sha1
1048-
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
1049-
fi
1050-
done
1051-
fi
1022+
if test -z "$rebase_root"
1023+
then
1024+
preserve=t
1025+
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
1026+
do
1027+
if test -f "$rewritten"/$p
1028+
then
1029+
preserve=f
1030+
fi
1031+
done
1032+
else
1033+
preserve=f
1034+
fi
1035+
if test f = "$preserve"
1036+
then
1037+
touch "$rewritten"/$sha1
1038+
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
1039+
fi
1040+
done
10521041

10531042
# Watch for commits that been dropped by --cherry-pick
1054-
if test t = "$preserve_merges"
1055-
then
1056-
mkdir "$dropped"
1057-
# Save all non-cherry-picked changes
1058-
git rev-list $revisions --left-right --cherry-pick | \
1059-
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
1060-
# Now all commits and note which ones are missing in
1061-
# not-cherry-picks and hence being dropped
1062-
git rev-list $revisions |
1063-
while read rev
1064-
do
1065-
if test -f "$rewritten"/$rev &&
1066-
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
1067-
then
1068-
# Use -f2 because if rev-list is telling us this commit is
1069-
# not worthwhile, we don't want to track its multiple heads,
1070-
# just the history of its first-parent for others that will
1071-
# be rebasing on top of it
1072-
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
1073-
sha1=$(git rev-list -1 $rev)
1074-
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1075-
rm "$rewritten"/$rev
1076-
fi
1077-
done
1078-
fi
1043+
mkdir "$dropped"
1044+
# Save all non-cherry-picked changes
1045+
git rev-list $revisions --left-right --cherry-pick | \
1046+
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
1047+
# Now all commits and note which ones are missing in
1048+
# not-cherry-picks and hence being dropped
1049+
git rev-list $revisions |
1050+
while read rev
1051+
do
1052+
if test -f "$rewritten"/$rev &&
1053+
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
1054+
then
1055+
# Use -f2 because if rev-list is telling us this commit is
1056+
# not worthwhile, we don't want to track its multiple heads,
1057+
# just the history of its first-parent for others that will
1058+
# be rebasing on top of it
1059+
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
1060+
sha1=$(git rev-list -1 $rev)
1061+
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1062+
rm "$rewritten"/$rev
1063+
fi
1064+
done
10791065

10801066
complete_action
10811067
}

0 commit comments

Comments
 (0)