Skip to content

Commit edb72d5

Browse files
kirylgitster
authored andcommitted
rebase -i: use full object name internally throughout the script
In earlier days, the abbreviated commit object name shown to the end users were generated with hardcoded --abbrev=7; 5689503 (rebase -i: respect core.abbrev, 2013-09-28) tried to make it honor the user specified core.abbrev, but it missed the very initial invocation of the editor. These days, we try to use the full 40-hex object names internally to avoid ambiguity that can arise after rebase starts running. Newly created objects during the rebase may share the same prefix with existing commits listed in the insn sheet. These object names are shortened just before invoking the sequence editor to present the insn sheet to the end user, and then expanded back to full object names when the editor returns. But the code still used the shortened names when preparing the insn sheet for the very first time, resulting "7 hexdigits or more" output to the user. Change the code to use full 40-hex commit object names from the very beginning to make things more uniform. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3c84ac8 commit edb72d5

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

git-rebase--interactive.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -961,14 +961,13 @@ else
961961
revisions=$onto...$orig_head
962962
shortrevisions=$shorthead
963963
fi
964-
git rev-list $merges_option --pretty=oneline --abbrev-commit \
965-
--abbrev=7 --reverse --left-right --topo-order \
964+
git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
966965
$revisions ${restrict_revision+^$restrict_revision} | \
967966
sed -n "s/^>//p" |
968-
while read -r shortsha1 rest
967+
while read -r sha1 rest
969968
do
970969

971-
if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
970+
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
972971
then
973972
comment_out="$comment_char "
974973
else
@@ -977,9 +976,8 @@ do
977976

978977
if test t != "$preserve_merges"
979978
then
980-
printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
979+
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
981980
else
982-
sha1=$(git rev-parse $shortsha1)
983981
if test -z "$rebase_root"
984982
then
985983
preserve=t
@@ -996,7 +994,7 @@ do
996994
if test f = "$preserve"
997995
then
998996
touch "$rewritten"/$sha1
999-
printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
997+
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
1000998
fi
1001999
fi
10021000
done
@@ -1020,8 +1018,8 @@ then
10201018
# just the history of its first-parent for others that will
10211019
# be rebasing on top of it
10221020
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
1023-
short=$(git rev-list -1 --abbrev-commit --abbrev=7 $rev)
1024-
sane_grep -v "^[a-z][a-z]* $short" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
1021+
sha1=$(git rev-list -1 $rev)
1022+
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
10251023
rm "$rewritten"/$rev
10261024
fi
10271025
done
@@ -1052,6 +1050,7 @@ has_action "$todo" ||
10521050
return 2
10531051

10541052
cp "$todo" "$todo".backup
1053+
collapse_todo_ids
10551054
git_sequence_editor "$todo" ||
10561055
die_abort "Could not execute editor"
10571056

t/t3404-rebase-interactive.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,4 +1039,11 @@ test_expect_success 'short SHA-1 collide' '
10391039
)
10401040
'
10411041

1042+
test_expect_success 'respect core.abbrev' '
1043+
git config core.abbrev 12 &&
1044+
set_cat_todo_editor &&
1045+
test_must_fail git rebase -i HEAD~4 >todo-list &&
1046+
test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1047+
'
1048+
10421049
test_done

0 commit comments

Comments
 (0)