Skip to content
Permalink
Browse files

Merge pull request #2121 from dscho/fix-rereading-todo-list

rebase -i: fix re-reading the todo list when newly created objects are referenced
  • Loading branch information...
dscho committed May 7, 2019
2 parents c63a3d5 + 119c983 commit 59a40eeaf4b055b8478270d1929bfed41feb8278
Showing with 37 additions and 2 deletions.
  1. +3 −2 sequencer.c
  2. +12 −0 sha1-name.c
  3. +22 −0 t/t3429-rebase-edit-todo.sh
@@ -2136,7 +2136,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;
@@ -3639,14 +3640,14 @@ 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;
} else if (stat(get_todo_path(opts), &st))
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 */
@@ -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;

@@ -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

0 comments on commit 59a40ee

Please sign in to comment.
You can’t perform that action at this time.