Skip to content

Commit a882b9f

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
get_oid(): when an object was not found, try harder
It is quite possible that the loose object cache gets stale when new objects are written. In that case, get_oid() would potentially say that it cannot find a given object, even if it should find it. Let's blow away the loose object cache as well as the read packs and try again in that case. Note: this does *not* affect the code path that was introduced to help avoid looking for the same non-existing objects (which made some operations really expensive via NFS): that code path is handled by the `OBJECT_INFO_QUICK` flag (which does not even apply to `get_oid()`, which has no equivalent flag, at least at the time this patch was written). This incidentally fixes the problem identified earlier where an interactive rebase wanted to re-read (and validate) the todo list after an `exec` command modified it. Helped-by: Jeff King <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c55f364 commit a882b9f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_expect_success 'rebase exec modifies rebase-todo' '
1111
test -e F
1212
'
1313

14-
test_expect_failure SHA1 'loose object cache vs re-reading todo list' '
14+
test_expect_success SHA1 'loose object cache vs re-reading todo list' '
1515
GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
1616
export GIT_REBASE_TODO &&
1717
write_script append-todo.sh <<-\EOS &&

0 commit comments

Comments
 (0)