Skip to content

Commit 77de3b7

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge pull request #2121 from dscho/fix-rereading-todo-list
rebase -i: fix re-reading the todo list when newly created objects are referenced
2 parents 49b5815 + a882b9f commit 77de3b7

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
@@ -2136,7 +2136,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
21362136
item->arg_len = (int)(eol - item->arg);
21372137

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

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

3642-
/* Reread the todo file if it has changed. */
36433643
if (res) {
36443644
if (opts->reschedule_failed_exec)
36453645
reschedule = 1;
36463646
} else if (stat(get_todo_path(opts), &st))
36473647
res = error_errno(_("could not stat '%s'"),
36483648
get_todo_path(opts));
36493649
else if (match_stat_data(&todo_list->stat, &st)) {
3650+
/* Reread the todo file if it has changed. */
36503651
todo_list_release(todo_list);
36513652
if (read_populate_todo(r, todo_list, opts))
36523653
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)