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; 56895038 (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>

Kirill A. Shutemov committed Jan 22, 2015 at 13:50 UTC edb72d551128f798f5f43292789cb7c731d1e01f
2 files changed +15 -9
git-rebase--interactive.sh
+8 -9
@@ -961,14 +961,13 @@ else
961 revisions=$onto...$orig_head
962 shortrevisions=$shorthead
963 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 \
965 $revisions ${restrict_revision+^$restrict_revision} | \
966 sed -n "s/^>//p" |
968 -while read -r shortsha1 rest
967 +while read -r sha1 rest
968 do
969
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
971 then
972 comment_out="$comment_char "
973 else
@@ -977,9 +976,8 @@ do
976
977 if test t != "$preserve_merges"
978 then
980 - printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
979 + printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
980 else
982 - sha1=$(git rev-parse $shortsha1)
981 if test -z "$rebase_root"
982 then
983 preserve=t
@@ -996,7 +994,7 @@ do
994 if test f = "$preserve"
995 then
996 touch "$rewritten"/$sha1
999 - printf '%s\n' "${comment_out}pick $shortsha1 $rest" >>"$todo"
997 + printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
998 fi
999 fi
1000 done
@@ -1020,8 +1018,8 @@ then
1018 # just the history of its first-parent for others that will
1019 # be rebasing on top of it
1020 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"
1023 rm "$rewritten"/$rev
1024 fi
1025 done
@@ -1052,6 +1050,7 @@ has_action "$todo" ||
1050 return 2
1051
1052 cp "$todo" "$todo".backup
1053 +collapse_todo_ids
1054 git_sequence_editor "$todo" ||
1055 die_abort "Could not execute editor"
1056
t/t3404-rebase-interactive.sh
+7
@@ -1039,4 +1039,11 @@ test_expect_success 'short SHA-1 collide' '
1039 )
1040 '
1041
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 +
1049 test_done