{"thread":{"id":"66501","subject":"[PATCH] fast-import: fix lookup for new commits","startedAt":"2026-10-10T17:24:38Z","lastAt":"2026-10-10T17:24:38Z","messageCount":1,"participants":["Marc Becker via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"554696","messageId":"pull.2252.git.1791653078449.gitgitgadget@gmail.com","threadId":"66501","inReplyTo":null,"subject":"[PATCH] fast-import: fix lookup for new commits","fromName":"Marc Becker via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-10T17:24:38Z","receivedAt":"2026-10-10T17:24:38Z","isPatch":true,"sender":{"key":"marc.becker@astos.de","avatar":null},"body":"From: Marc Becker <becm@gmx.de>\n\nQueries for commits created during the same 'git fast-import'  session\nresult in a crash:\n    < reset refs/heads/newbranch\n    < from <new-commit-oid>\n    > fatal: not a valid commit: <new-commit-oid>\n\nGetting file content for commit has no issue (working implementation):\n    < ls <new-commit-oid> file-in-new-commit.txt\n    > {file content}\n\nDuring import, new objects may not (yet) be reachable via the ODB layer.\nTry to resolve requested tag/commit via object cache first\nto avoid crash and (eventually) improve lookup speed.\n\nSigned-off-by: Marc Becker <becm@gmx.de>\n---\n    fast-import: fix lookup for new commits\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2252%2Fbecm%2Ffix-fast-import-commit-from-existing-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2252/becm/fix-fast-import-commit-from-existing-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2252\n\n builtin/fast-import.c | 18 ++++++++++++++----\n 1 file changed, 14 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex fbd919982c..4b93148551 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -292,6 +292,8 @@ static void fast_import_state_init(struct fast_import_state *state,\n \tstate->option = option;\n }\n \n+static struct object_entry *dereference(struct object_entry *oe, struct object_id *oid);\n+\n static void parse_argv(struct fast_import_state *state);\n static void parse_get_mark(struct fast_import_state *state, const char *p);\n static void parse_cat_blob(struct fast_import_state *state, const char *p);\n@@ -2658,12 +2660,20 @@ static void parse_from_existing(struct branch *b)\n \t\toidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);\n \t} else {\n \t\tunsigned long size;\n-\t\tsize_t size_st = 0;\n \t\tchar *buf;\n+\t\tstruct object_entry *e = find_object(&b->oid);\n \n-\t\tbuf = odb_read_object_peeled(the_repository->objects, &b->oid,\n-\t\t\t\t\t     OBJ_COMMIT, &size_st, &b->oid);\n-\t\tsize = cast_size_t_to_ulong(size_st);\n+\t\twhile (e && e->type == OBJ_TAG)\n+\t\t\te = dereference(e, &b->oid);\n+\n+\t\tif (e && e->type == OBJ_COMMIT && e->pack_id != MAX_PACK_ID) {\n+\t\t\tbuf = gfi_unpack_entry(e, &size);\n+\t\t} else {\n+\t\t\tsize_t size_st = 0;\n+\t\t\tbuf = odb_read_object_peeled(the_repository->objects, &b->oid,\n+\t\t\t\t\t\t     OBJ_COMMIT, &size_st, &b->oid);\n+\t\t\tsize = cast_size_t_to_ulong(size_st);\n+\t\t}\n \t\tparse_from_commit(b, buf, size);\n \t\tfree(buf);\n \t}\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\n-- \ngitgitgadget\n\n"}]}