Skip to content

Commit 4e50f63

Browse files
committed
fast-import: fix lookup for new commits
Queries for commits created during the same 'git fast-import' session result in a crash: < reset refs/heads/newbranch < from <new-commit-oid> > fatal: not a valid commit: <new-commit-oid> Getting file content for commit has no issue (working implementation): < ls <new-commit-oid> file-in-new-commit.txt > {file content} During import, new objects may not (yet) be reachable via the ODB layer. Try to resolve requested tag/commit via object cache first to avoid crash and (eventually) improve lookup speed. Signed-off-by: Marc Becker <becm@gmx.de>
1 parent 6de20f6 commit 4e50f63

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎builtin/fast-import.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ static void fast_import_state_init(struct fast_import_state *state,
292292
state->option = option;
293293
}
294294

295+
static struct object_entry *dereference(struct object_entry *oe, struct object_id *oid);
296+
295297
static void parse_argv(struct fast_import_state *state);
296298
static void parse_get_mark(struct fast_import_state *state, const char *p);
297299
static void parse_cat_blob(struct fast_import_state *state, const char *p);
@@ -2658,12 +2660,20 @@ static void parse_from_existing(struct branch *b)
26582660
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
26592661
} else {
26602662
unsigned long size;
2661-
size_t size_st = 0;
26622663
char *buf;
2664+
struct object_entry *e = find_object(&b->oid);
26632665

2664-
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
2665-
OBJ_COMMIT, &size_st, &b->oid);
2666-
size = cast_size_t_to_ulong(size_st);
2666+
while (e && e->type == OBJ_TAG)
2667+
e = dereference(e, &b->oid);
2668+
2669+
if (e && e->type == OBJ_COMMIT && e->pack_id != MAX_PACK_ID) {
2670+
buf = gfi_unpack_entry(e, &size);
2671+
} else {
2672+
size_t size_st = 0;
2673+
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
2674+
OBJ_COMMIT, &size_st, &b->oid);
2675+
size = cast_size_t_to_ulong(size_st);
2676+
}
26672677
parse_from_commit(b, buf, size);
26682678
free(buf);
26692679
}

0 commit comments

Comments
 (0)