Merge branch 'js/get-short-oid-drop-cache'

A corner-case object name ambiguity while the sequencer machinery
is working (e.g. "rebase -i -x") has been (half) fixed.

* js/get-short-oid-drop-cache:
  get_oid(): when an object was not found, try harder
  sequencer: move stale comment into correct location
  sequencer: improve error message when an OID could not be parsed
  rebase -i: demonstrate obscure loose object cache bug
This commit is contained in:
Junio C Hamano 2019-04-16 19:28:06 +09:00
commit e197980eb2
3 changed files with 37 additions and 2 deletions

View file

@ -2137,7 +2137,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
item->arg_len = (int)(eol - item->arg);
if (status < 0)
return -1;
return error(_("could not parse '%.*s'"),
(int)(end_of_object_name - bol), bol);
item->commit = lookup_commit_reference(r, &commit_oid);
return !item->commit;
@ -3640,7 +3641,6 @@ static int pick_commits(struct repository *r,
res = do_exec(r, item->arg);
*end_of_arg = saved;
/* Reread the todo file if it has changed. */
if (res) {
if (opts->reschedule_failed_exec)
reschedule = 1;
@ -3648,6 +3648,7 @@ static int pick_commits(struct repository *r,
res = error_errno(_("could not stat '%s'"),
get_todo_path(opts));
else if (match_stat_data(&todo_list->stat, &st)) {
/* Reread the todo file if it has changed. */
todo_list_release(todo_list);
if (read_populate_todo(r, todo_list, opts))
res = -1; /* message was printed */

View file

@ -442,6 +442,18 @@ static enum get_oid_result get_short_oid(const char *name, int len,
find_short_packed_object(&ds);
status = finish_object_disambiguation(&ds, oid);
/*
* If we didn't find it, do the usual reprepare() slow-path,
* since the object may have recently been added to the repository
* or migrated from loose to packed.
*/
if (status == MISSING_OBJECT) {
reprepare_packed_git(the_repository);
find_short_object_filename(&ds);
find_short_packed_object(&ds);
status = finish_object_disambiguation(&ds, oid);
}
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
struct oid_array collect = OID_ARRAY_INIT;

View file

@ -11,4 +11,26 @@ test_expect_success 'rebase exec modifies rebase-todo' '
test -e F
'
test_expect_success SHA1 'loose object cache vs re-reading todo list' '
GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
export GIT_REBASE_TODO &&
write_script append-todo.sh <<-\EOS &&
# For values 5 and 6, this yields SHA-1s with the same first two digits
echo "pick $(git rev-parse --short \
$(printf "%s\\n" \
"tree $EMPTY_TREE" \
"author A U Thor <author@example.org> $1 +0000" \
"committer A U Thor <author@example.org> $1 +0000" \
"" \
"$1" |
git hash-object -t commit -w --stdin))" >>$GIT_REBASE_TODO
shift
test -z "$*" ||
echo "exec $0 $*" >>$GIT_REBASE_TODO
EOS
git rebase HEAD -x "./append-todo.sh 5 6"
'
test_done