Skip to content

Commit e197980

Browse files
committed
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
2 parents 8b71503 + 6d67a99 commit e197980

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

sequencer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
21372137
item->arg_len = (int)(eol - item->arg);
21382138

21392139
if (status < 0)
2140-
return -1;
2140+
return error(_("could not parse '%.*s'"),
2141+
(int)(end_of_object_name - bol), bol);
21412142

21422143
item->commit = lookup_commit_reference(r, &commit_oid);
21432144
return !item->commit;
@@ -3640,14 +3641,14 @@ static int pick_commits(struct repository *r,
36403641
res = do_exec(r, item->arg);
36413642
*end_of_arg = saved;
36423643

3643-
/* Reread the todo file if it has changed. */
36443644
if (res) {
36453645
if (opts->reschedule_failed_exec)
36463646
reschedule = 1;
36473647
} else if (stat(get_todo_path(opts), &st))
36483648
res = error_errno(_("could not stat '%s'"),
36493649
get_todo_path(opts));
36503650
else if (match_stat_data(&todo_list->stat, &st)) {
3651+
/* Reread the todo file if it has changed. */
36513652
todo_list_release(todo_list);
36523653
if (read_populate_todo(r, todo_list, opts))
36533654
res = -1; /* message was printed */

sha1-name.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ static enum get_oid_result get_short_oid(const char *name, int len,
442442
find_short_packed_object(&ds);
443443
status = finish_object_disambiguation(&ds, oid);
444444

445+
/*
446+
* If we didn't find it, do the usual reprepare() slow-path,
447+
* since the object may have recently been added to the repository
448+
* or migrated from loose to packed.
449+
*/
450+
if (status == MISSING_OBJECT) {
451+
reprepare_packed_git(the_repository);
452+
find_short_object_filename(&ds);
453+
find_short_packed_object(&ds);
454+
status = finish_object_disambiguation(&ds, oid);
455+
}
456+
445457
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
446458
struct oid_array collect = OID_ARRAY_INIT;
447459

t/t3429-rebase-edit-todo.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,26 @@ test_expect_success 'rebase exec modifies rebase-todo' '
1111
test -e F
1212
'
1313

14+
test_expect_success SHA1 'loose object cache vs re-reading todo list' '
15+
GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
16+
export GIT_REBASE_TODO &&
17+
write_script append-todo.sh <<-\EOS &&
18+
# For values 5 and 6, this yields SHA-1s with the same first two digits
19+
echo "pick $(git rev-parse --short \
20+
$(printf "%s\\n" \
21+
"tree $EMPTY_TREE" \
22+
"author A U Thor <[email protected]> $1 +0000" \
23+
"committer A U Thor <[email protected]> $1 +0000" \
24+
"" \
25+
"$1" |
26+
git hash-object -t commit -w --stdin))" >>$GIT_REBASE_TODO
27+
28+
shift
29+
test -z "$*" ||
30+
echo "exec $0 $*" >>$GIT_REBASE_TODO
31+
EOS
32+
33+
git rebase HEAD -x "./append-todo.sh 5 6"
34+
'
35+
1436
test_done

0 commit comments

Comments
 (0)