{"thread":{"id":"66501","subject":"[PATCH] fast-import: fix lookup for new commits","startedAt":"2026-10-10T17:24:38Z","lastAt":"2026-10-14T22:42:49Z","messageCount":9,"participants":["Marc Becker via GitGitGadget","Aniket Gupta","Junio C Hamano"],"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"},{"id":"554722","messageId":"20261011193855.43162-1-aniketgupta3001@gmail.com","threadId":"66501","inReplyTo":"pull.2252.git.1791653078449.gitgitgadget@gmail.com","subject":"Re: [PATCH] fast-import: fix lookup for new commits","fromName":"Aniket Gupta","fromEmail":"aniketgupta3001@gmail.com","sentAt":"2026-10-11T19:38:55Z","receivedAt":"2026-10-11T19:38:55Z","isPatch":true,"sender":{"key":"aniketgupta3001@gmail.com","avatar":null},"body":"Hello Marc,\n\nSorry for the noise, my first mail lost its In-Reply-To header on the\nway, so it is not in this thread. Resending the same review here.\n\nI tried this on top of 6de20f609 with DEVELOPER=1 and did not get warnings.\n\n> Queries for commits created during the same 'git fast-import'  session\n> result in a crash:\n>     < reset refs/heads/newbranch\n>     < from <new-commit-oid>\n>     > fatal: not a valid commit: <new-commit-oid>\n\nI was able to repro this. With the patch fsck is clean and it works\nnicely. Same goes for \"commit\" with \"from <new-oid>\", a tag made in\nthe same session, and a tag of a tag. Existing commits and tags and\n\"from <blob>\" behave like before.\n\nOne small nitpick: there is a double space in \"'git fast-import'  session\".\n\n> to avoid crash and (eventually) improve lookup speed.\n\nDid you measure this? If not, maybe drop it or say it is only a\npossible side effect.\n\n> +static struct object_entry *dereference(struct object_entry *oe, struct object_id *oid);\n\nThis is over 80 columns, can it be wrapped like the definition?\n\n>  builtin/fast-import.c | 18 ++++++++++++++----\n\nI could not find a test for this. Can you add one to t9300? You can\nget the new oid with get-mark and use it in a \"reset ... from <oid>\"\nin the same stream.\n\nThanks,\nAniket\n\n"},{"id":"554818","messageId":"pull.2252.v2.git.1791845420568.gitgitgadget@gmail.com","threadId":"66501","inReplyTo":"pull.2252.git.1791653078449.gitgitgadget@gmail.com","subject":"[PATCH v2] fast-import: fix lookup for new commits and tags","fromName":"Marc Becker via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-12T22:50:20Z","receivedAt":"2026-10-12T22:50:20Z","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.\nAdd test to 't/t9300.sh' with references to a pending tag and commit.\n\nSigned-off-by: Marc Becker <becm@gmx.de>\n---\n    fast-import: fix lookup for new commits\n    \n    Changes since v1:\n    \n     * address notes regarding commit message\n     * stick to line length in new code\n     * add test with (fixed) pending references (files for SHA1 and SHA256,\n       no coproc in sh, avoid named pipes)\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2252%2Fbecm%2Ffix-fast-import-commit-from-existing-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2252/becm/fix-fast-import-commit-from-existing-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/2252\n\nRange-diff vs v1:\n\n 1:  4e50f63354 ! 1:  d834e2fc47 fast-import: fix lookup for new commits\n     @@ Metadata\n      Author: Marc Becker <becm@gmx.de>\n      \n       ## Commit message ##\n     -    fast-import: fix lookup for new commits\n     +    fast-import: fix lookup for new commits and tags\n      \n     -    Queries for commits created during the same 'git fast-import'  session\n     +    Queries for commits created during the same 'git fast-import' session\n          result in a crash:\n              < reset refs/heads/newbranch\n              < from <new-commit-oid>\n     @@ Commit message\n      \n          During import, new objects may not (yet) be reachable via the ODB layer.\n          Try to resolve requested tag/commit via object cache first\n     -    to avoid crash and (eventually) improve lookup speed.\n     +    to avoid crash.\n     +    Add test to 't/t9300.sh' with references to a pending tag and commit.\n      \n          Signed-off-by: Marc Becker <becm@gmx.de>\n      \n     @@ builtin/fast-import.c: static void fast_import_state_init(struct fast_import_sta\n       \tstate->option = option;\n       }\n       \n     -+static struct object_entry *dereference(struct object_entry *oe, struct object_id *oid);\n     ++static struct object_entry *dereference(struct object_entry *oe,\n     ++\t\t\t\t\tstruct 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     @@ builtin/fast-import.c: static void parse_from_existing(struct branch *b)\n       \t\tparse_from_commit(b, buf, size);\n       \t\tfree(buf);\n       \t}\n     +\n     + ## t/t9300-fast-import.sh ##\n     +@@ t/t9300-fast-import.sh: test_expect_success 'Y: rewrite submodules' '\n     + \t)\n     + '\n     + \n     ++cat >Y-reference-pending-sha256 <<\\Y_INPUT_END\n     ++commit refs/heads/main\n     ++committer A U Thor <author@example.com> 1712563200 +0000\n     ++data 14\n     ++commit message\n     ++M 644 inline test file\n     ++data 14\n     ++dummy content\n     ++\n     ++tag newtag\n     ++from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     ++tagger A U Thor <author@example.com> 1712563300 +0000\n     ++data 11\n     ++tag message\n     ++# no emty line after tag data!\n     ++reset refs/heads/other\n     ++from 85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n     ++\n     ++commit refs/heads/further\n     ++committer A U Thor <author@example.com> 1712563400 +0000\n     ++data 21\n     ++what about 2nd commit\n     ++from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     ++M 644 inline other test file\n     ++data 19\n     ++more dummy content\n     ++\n     ++done\n     ++Y_INPUT_END\n     ++\n     ++cat >Y-reference-pending-sha1 <<\\Y_INPUT_END\n     ++commit refs/heads/main\n     ++committer A U Thor <author@example.com> 1712563200 +0000\n     ++data 14\n     ++commit message\n     ++M 644 inline test file\n     ++data 14\n     ++dummy content\n     ++\n     ++tag newtag\n     ++from 85b46dd918355ff17b4109ec738723d42f235a04\n     ++tagger A U Thor <author@example.com> 1712563300 +0000\n     ++data 11\n     ++tag message\n     ++# no emty line after tag data!\n     ++reset refs/heads/other\n     ++from ec6c4db71feb5f66615214dad2324ce030e777a7\n     ++\n     ++commit refs/heads/further\n     ++committer A U Thor <author@example.com> 1712563400 +0000\n     ++data 21\n     ++what about 2nd commit\n     ++from 85b46dd918355ff17b4109ec738723d42f235a04\n     ++M 644 inline other test file\n     ++data 19\n     ++more dummy content\n     ++\n     ++done\n     ++Y_INPUT_END\n     ++\n     ++test_expect_success 'Y: reference pending tag or commit' '\n     ++\tgit init reference-pending &&\n     ++\t(\n     ++\t\tcd reference-pending &&\n     ++\t\tgit fast-import < \"../Y-reference-pending-$(git rev-parse --show-object-format)\"\n     ++\t)\n     ++'\n     ++\n     + test_done\n\n\n builtin/fast-import.c  | 19 +++++++++---\n t/t9300-fast-import.sh | 68 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 83 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex fbd919982c..574a03c484 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -292,6 +292,9 @@ 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,\n+\t\t\t\t\tstruct 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 +2661,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}\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex d9de2ef0d8..1f52be2c2c 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -3938,4 +3938,72 @@ test_expect_success 'Y: rewrite submodules' '\n \t)\n '\n \n+cat >Y-reference-pending-sha256 <<\\Y_INPUT_END\n+commit refs/heads/main\n+committer A U Thor <author@example.com> 1712563200 +0000\n+data 14\n+commit message\n+M 644 inline test file\n+data 14\n+dummy content\n+\n+tag newtag\n+from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n+tagger A U Thor <author@example.com> 1712563300 +0000\n+data 11\n+tag message\n+# no emty line after tag data!\n+reset refs/heads/other\n+from 85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n+\n+commit refs/heads/further\n+committer A U Thor <author@example.com> 1712563400 +0000\n+data 21\n+what about 2nd commit\n+from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n+M 644 inline other test file\n+data 19\n+more dummy content\n+\n+done\n+Y_INPUT_END\n+\n+cat >Y-reference-pending-sha1 <<\\Y_INPUT_END\n+commit refs/heads/main\n+committer A U Thor <author@example.com> 1712563200 +0000\n+data 14\n+commit message\n+M 644 inline test file\n+data 14\n+dummy content\n+\n+tag newtag\n+from 85b46dd918355ff17b4109ec738723d42f235a04\n+tagger A U Thor <author@example.com> 1712563300 +0000\n+data 11\n+tag message\n+# no emty line after tag data!\n+reset refs/heads/other\n+from ec6c4db71feb5f66615214dad2324ce030e777a7\n+\n+commit refs/heads/further\n+committer A U Thor <author@example.com> 1712563400 +0000\n+data 21\n+what about 2nd commit\n+from 85b46dd918355ff17b4109ec738723d42f235a04\n+M 644 inline other test file\n+data 19\n+more dummy content\n+\n+done\n+Y_INPUT_END\n+\n+test_expect_success 'Y: reference pending tag or commit' '\n+\tgit init reference-pending &&\n+\t(\n+\t\tcd reference-pending &&\n+\t\tgit fast-import < \"../Y-reference-pending-$(git rev-parse --show-object-format)\"\n+\t)\n+'\n+\n test_done\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\n-- \ngitgitgadget\n\n"},{"id":"554819","messageId":"xmqq1p9u4g44.fsf@gitster.g","threadId":"66501","inReplyTo":"pull.2252.v2.git.1791845420568.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] fast-import: fix lookup for new commits and tags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T00:08:11Z","receivedAt":"2026-10-13T00:08:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Marc Becker via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\nThe patch text seems to make sense, but ...\n\n> From: Marc Becker <becm@gmx.de>\n>\n> Queries for commits created during the same 'git fast-import' session\n> result in a crash:\n\nShould it say \"sometimes results in a crash\"?  It is not like that\nno queries for commits can ever be made before the session gets\nclosed, right?\n\n>     < reset refs/heads/newbranch\n>     < from <new-commit-oid>\n>     > fatal: not a valid commit: <new-commit-oid>\n>\n> Getting file content for commit has no issue (working implementation):\n\n... what do you mean by \"(working implementation)\" here?  Do you\nmean that without your patch applied, neither commits nor blobs can\nbe read, and with the patch applied we get a \"working\nimplementation\" and blobs can be read?  Or do you mean that objects\nother than commits do not have such a problem?\n\n>     < ls <new-commit-oid> file-in-new-commit.txt\n>     > {file content}\n\nOr do you mean the current code does not allow reading commits but\neverything else it does allow reading?  If so, such a description\nshould be followed by why commit alone is so special, or put it\ndifferently, why blobs can be accessed just fine.  Otherwise, saying\nthat getting file content would work fine only confuses readers\nwithout adding much value to them.\n\n> During import, new objects may not (yet) be reachable via the ODB layer.\n\nThis \"may not (yet)\" is very believable; I would be very surprised\nif we were holding any and all object data we were fed in core\nwithout flushing to the ODB, but depending on the timing of your\nquery, necessary objects may or may not have been flushed.  Is that\nwhat you meant by \"may not (yet)\" here?  If so, that confirms my\n\"sometimes results in a crash\" above, right?\n\nHere is what my assistant produced trying to guess what the commit\nwanted to say.  I do not know how close it is to what you wanted to\nsay, but if the change were explained like this, it may have been\neasier to understand.  At least, failures for commit vs success with blobs\nyou hinted at is explained sufficiently.\n\nOf course, my assistant may be totally off the mark and the following may\nnot explain what you wanted to do at all.  I dunno.\n\n    fast-import: allow 'from' to reference new commits and tags by oid\n\n    During a 'git fast-import' session, newly created objects are written\n    to an in-progress packfile and recorded in fast-import's internal\n    object table.  Until a 'checkpoint' command or the end of the session\n    finalizes and indexes that packfile, these objects are not visible to\n    the repository's object database via odb_read_object_peeled().\n\n    Commands such as 'ls' (via parse_treeish_dataref() and dereference())\n    and 'cat-blob' already account for this when given a hex object name:\n    they look up the object in fast-import's internal object table with\n    find_object() first and read it from the in-progress packfile with\n    gfi_unpack_entry() when its '.pack_id' is not MAX_PACK_ID.\n\n    By contrast, when 'from <committish>' (in a 'commit' or 'reset'\n    command) is given a hex object name instead of a mark or branch name,\n    parse_objectish() parses the hex string into 'b->oid' and calls\n    parse_from_existing(), which unconditionally looks up the object via\n    odb_read_object_peeled().  If the object is a commit or tag created in\n    the current pack cycle, odb_read_object_peeled() returns NULL and\n    fast-import dies with \"fatal: not a valid commit: <oid>\".\n\n    Teach parse_from_existing() to look up 'b->oid' with find_object()\n    first, peel any tag objects in the object table using dereference(),\n    and unpack the target commit with gfi_unpack_entry() if it resides in\n    the in-progress packfile, before falling back to\n    odb_read_object_peeled() for objects in the repository's object\n    database.\n\n> diff --git a/builtin/fast-import.c b/builtin/fast-import.c\n> index fbd919982c..574a03c484 100644\n> --- a/builtin/fast-import.c\n> +++ b/builtin/fast-import.c\n> @@ -292,6 +292,9 @@ 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,\n> +\t\t\t\t\tstruct 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 +2661,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\nThis would mean we would peel down a tag that points at a tree or a\nblob to tree or blob.  And that object is not a commit, so we would\ncontinue going down the other \"read from odb_read_object_peeled()\"\ncode path.  That is the same behaviour as the original (in happy\ncase, when the objects are flushed to the odb layer).\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\nAnd the code inside this \"else\" clause is the same as the original.\n\n> +\t\t}\n\nSo the change itself makes sense.  It is that it is not clear if the\n\"makes sense\" I just said matches what you described in your proposed log\nmessage.\n\n>  \t\tparse_from_commit(b, buf, size);\n>  \t\tfree(buf);\n>  \t}\n\n"},{"id":"554822","messageId":"xmqqik362xap.fsf@gitster.g","threadId":"66501","inReplyTo":"pull.2252.v2.git.1791845420568.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] fast-import: fix lookup for new commits and tags","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T01:39:58Z","receivedAt":"2026-10-13T01:39:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Marc Becker via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\n> index d9de2ef0d8..1f52be2c2c 100755\n> --- a/t/t9300-fast-import.sh\n> +++ b/t/t9300-fast-import.sh\n> @@ -3938,4 +3938,72 @@ test_expect_success 'Y: rewrite submodules' '\n>  \t)\n>  '\n>  \n> +cat >Y-reference-pending-sha256 <<\\Y_INPUT_END\n> +commit refs/heads/main\n> +committer A U Thor <author@example.com> 1712563200 +0000\n> +data 14\n> +commit message\n> +M 644 inline test file\n> +data 14\n> +dummy content\n> +\n> +tag newtag\n> +from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n> +tagger A U Thor <author@example.com> 1712563300 +0000\n> +data 11\n> +tag message\n> +# no emty line after tag data!\n> +reset refs/heads/other\n> +from 85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n> +\n> +commit refs/heads/further\n> +committer A U Thor <author@example.com> 1712563400 +0000\n> +data 21\n> +what about 2nd commit\n> +from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n> +M 644 inline other test file\n> +data 19\n> +more dummy content\n> +\n> +done\n> +Y_INPUT_END\n> +\n> +cat >Y-reference-pending-sha1 <<\\Y_INPUT_END\n> +commit refs/heads/main\n> +committer A U Thor <author@example.com> 1712563200 +0000\n> +data 14\n> +commit message\n> +M 644 inline test file\n> +data 14\n> +dummy content\n> +\n> +tag newtag\n> +from 85b46dd918355ff17b4109ec738723d42f235a04\n> +tagger A U Thor <author@example.com> 1712563300 +0000\n> +data 11\n> +tag message\n> +# no emty line after tag data!\n> +reset refs/heads/other\n> +from ec6c4db71feb5f66615214dad2324ce030e777a7\n> +\n> +commit refs/heads/further\n> +committer A U Thor <author@example.com> 1712563400 +0000\n> +data 21\n> +what about 2nd commit\n> +from 85b46dd918355ff17b4109ec738723d42f235a04\n> +M 644 inline other test file\n> +data 19\n> +more dummy content\n> +\n> +done\n> +Y_INPUT_END\n\nThe above duplicates a rather simple test, and only differences\nbetween them are the embedded object names.  Can't you use the\ntest_oid_cache & test_oid mechanism to reduce the repetition to\nmake the tests easier to maintain?  It may look something like this:\n\ntest_expect_success 'Y: reference pending tag or commit' '\n\ttest_oid_cache <<-EOF &&\n\tpending_commit sha1:86b46d....5a04\n\tpending_commit sha256:17e65...ed3d\n\tpending_tag sha1:ec6c6d...77a7\n\tpending_tag sha256:85edc5...1f46\n\tEOF\n\n\tgit init reference-pending &&\n\t(\n\t\tcd reference-pending &&\n                git fast-import <<-EOF &&\n                commit refs/heads/main\n                committer A U Thor <author@example.com> 1712563200 +0000\n                ...\n                dummy content\n\n                tag newtag\n                from $(test_oid pending_commit)\n                tagger A U Thor <author@example.com> 1712563300 +0000\n     \t\t...\n\t\tdata 19\n\t\tmore dummy content\n\n\t\tdone\n\t\tEOF\n\t)\n'\n\n"},{"id":"555046","messageId":"pull.2252.v3.git.1791995252623.gitgitgadget@gmail.com","threadId":"66501","inReplyTo":"pull.2252.git.1791653078449.gitgitgadget@gmail.com","subject":"[PATCH v3] fast-import: allow 'from' to reference new commits and tags by oid","fromName":"Marc Becker via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-14T16:27:32Z","receivedAt":"2026-10-14T16:27:32Z","isPatch":true,"sender":{"key":"marc.becker@astos.de","avatar":null},"body":"From: Marc Becker <becm@gmx.de>\n\nDuring a 'git fast-import' session, newly created objects are written\nto an in-progress packfile and recorded in fast-import's internal\nobject table.  Until a 'checkpoint' command or the end of the session\nfinalizes and indexes that packfile, these objects are not visible to\nthe repository's object database via odb_read_object_peeled().\n\nCommands such as 'ls' (via parse_treeish_dataref() and dereference())\nand 'cat-blob' already account for this when given a hex object name:\nthey look up the object in fast-import's internal object table with\nfind_object() first and read it from the in-progress packfile with\ngfi_unpack_entry() when its '.pack_id' is not MAX_PACK_ID.\n\nBy contrast, when 'from <committish>' (in a 'commit' or 'reset'\ncommand) is given a hex object name instead of a mark or branch name,\nparse_objectish() parses the hex string into 'b->oid' and calls\nparse_from_existing(), which unconditionally looks up the object via\nodb_read_object_peeled().  If the object is a commit or tag created in\nthe current pack cycle, odb_read_object_peeled() returns NULL and\nfast-import dies with \"fatal: not a valid commit: <oid>\".\n\nTeach parse_from_existing() to look up 'b->oid' with find_object()\nfirst, peel any tag objects in the object table using dereference(),\nand unpack the target commit with gfi_unpack_entry() if it resides in\nthe in-progress packfile, before falling back to\nodb_read_object_peeled() for objects in the repository's object\ndatabase.\n\nSigned-off-by: Marc Becker <becm@gmx.de>\n---\n    fast-import: fix lookup for new commits\n    \n    Changes since v2:\n    \n     * use LLM-generated commit message (description is on point) by Junio\n     * provide hash-specific OIDs in test code via test_oid\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2252%2Fbecm%2Ffix-fast-import-commit-from-existing-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2252/becm/fix-fast-import-commit-from-existing-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/2252\n\nRange-diff vs v2:\n\n 1:  d834e2fc47 ! 1:  25113432c6 fast-import: fix lookup for new commits and tags\n     @@ Metadata\n      Author: Marc Becker <becm@gmx.de>\n      \n       ## Commit message ##\n     -    fast-import: fix lookup for new commits and tags\n     +    fast-import: allow 'from' to reference new commits and tags by oid\n      \n     -    Queries for commits created during the same 'git fast-import' session\n     -    result in a crash:\n     -        < reset refs/heads/newbranch\n     -        < from <new-commit-oid>\n     -        > fatal: not a valid commit: <new-commit-oid>\n     +    During a 'git fast-import' session, newly created objects are written\n     +    to an in-progress packfile and recorded in fast-import's internal\n     +    object table.  Until a 'checkpoint' command or the end of the session\n     +    finalizes and indexes that packfile, these objects are not visible to\n     +    the repository's object database via odb_read_object_peeled().\n      \n     -    Getting file content for commit has no issue (working implementation):\n     -        < ls <new-commit-oid> file-in-new-commit.txt\n     -        > {file content}\n     +    Commands such as 'ls' (via parse_treeish_dataref() and dereference())\n     +    and 'cat-blob' already account for this when given a hex object name:\n     +    they look up the object in fast-import's internal object table with\n     +    find_object() first and read it from the in-progress packfile with\n     +    gfi_unpack_entry() when its '.pack_id' is not MAX_PACK_ID.\n      \n     -    During import, new objects may not (yet) be reachable via the ODB layer.\n     -    Try to resolve requested tag/commit via object cache first\n     -    to avoid crash.\n     -    Add test to 't/t9300.sh' with references to a pending tag and commit.\n     +    By contrast, when 'from <committish>' (in a 'commit' or 'reset'\n     +    command) is given a hex object name instead of a mark or branch name,\n     +    parse_objectish() parses the hex string into 'b->oid' and calls\n     +    parse_from_existing(), which unconditionally looks up the object via\n     +    odb_read_object_peeled().  If the object is a commit or tag created in\n     +    the current pack cycle, odb_read_object_peeled() returns NULL and\n     +    fast-import dies with \"fatal: not a valid commit: <oid>\".\n     +\n     +    Teach parse_from_existing() to look up 'b->oid' with find_object()\n     +    first, peel any tag objects in the object table using dereference(),\n     +    and unpack the target commit with gfi_unpack_entry() if it resides in\n     +    the in-progress packfile, before falling back to\n     +    odb_read_object_peeled() for objects in the repository's object\n     +    database.\n      \n          Signed-off-by: Marc Becker <becm@gmx.de>\n      \n     @@ t/t9300-fast-import.sh: test_expect_success 'Y: rewrite submodules' '\n       \t)\n       '\n       \n     -+cat >Y-reference-pending-sha256 <<\\Y_INPUT_END\n     -+commit refs/heads/main\n     -+committer A U Thor <author@example.com> 1712563200 +0000\n     -+data 14\n     -+commit message\n     -+M 644 inline test file\n     -+data 14\n     -+dummy content\n     -+\n     -+tag newtag\n     -+from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     -+tagger A U Thor <author@example.com> 1712563300 +0000\n     -+data 11\n     -+tag message\n     -+# no emty line after tag data!\n     -+reset refs/heads/other\n     -+from 85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n     -+\n     -+commit refs/heads/further\n     -+committer A U Thor <author@example.com> 1712563400 +0000\n     -+data 21\n     -+what about 2nd commit\n     -+from 17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     -+M 644 inline other test file\n     -+data 19\n     -+more dummy content\n     -+\n     -+done\n     -+Y_INPUT_END\n     -+\n     -+cat >Y-reference-pending-sha1 <<\\Y_INPUT_END\n     -+commit refs/heads/main\n     -+committer A U Thor <author@example.com> 1712563200 +0000\n     -+data 14\n     -+commit message\n     -+M 644 inline test file\n     -+data 14\n     -+dummy content\n     -+\n     -+tag newtag\n     -+from 85b46dd918355ff17b4109ec738723d42f235a04\n     -+tagger A U Thor <author@example.com> 1712563300 +0000\n     -+data 11\n     -+tag message\n     -+# no emty line after tag data!\n     -+reset refs/heads/other\n     -+from ec6c4db71feb5f66615214dad2324ce030e777a7\n     -+\n     -+commit refs/heads/further\n     -+committer A U Thor <author@example.com> 1712563400 +0000\n     -+data 21\n     -+what about 2nd commit\n     -+from 85b46dd918355ff17b4109ec738723d42f235a04\n     -+M 644 inline other test file\n     -+data 19\n     -+more dummy content\n     -+\n     -+done\n     -+Y_INPUT_END\n     -+\n      +test_expect_success 'Y: reference pending tag or commit' '\n     ++\ttest_oid_cache <<-EOF &&\n     ++\t\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n     ++\t\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     ++\t\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n     ++\t\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n     ++\t\tEOF\n     ++\n      +\tgit init reference-pending &&\n      +\t(\n      +\t\tcd reference-pending &&\n     -+\t\tgit fast-import < \"../Y-reference-pending-$(git rev-parse --show-object-format)\"\n     ++\t\tgit fast-import <<-EOF\n     ++\t\t\tcommit refs/heads/main\n     ++\t\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n     ++\t\t\tdata 14\n     ++\t\t\tcommit message\n     ++\t\t\tM 644 inline test file\n     ++\t\t\tdata 14\n     ++\t\t\tdummy content\n     ++\n     ++\t\t\ttag newtag\n     ++\t\t\tfrom $(test_oid pending_commit)\n     ++\t\t\ttagger A U Thor <author@example.com> 1712563300 +0000\n     ++\t\t\tdata 11\n     ++\t\t\ttag message\n     ++\t\t\t# no emty line after tag data!\n     ++\t\t\treset refs/heads/other\n     ++\t\t\tfrom $(test_oid pending_tag)\n     ++\n     ++\t\t\tcommit refs/heads/further\n     ++\t\t\tcommitter A U Thor <author@example.com> 1712563400 +0000\n     ++\t\t\tdata 21\n     ++\t\t\twhat about 2nd commit\n     ++\t\t\tfrom $(test_oid pending_commit)\n     ++\t\t\tM 644 inline other test file\n     ++\t\t\tdata 19\n     ++\t\t\tmore dummy content\n     ++\n     ++\t\t\tdone\n     ++\t\t\tEOF\n      +\t)\n      +'\n      +\n\n\n builtin/fast-import.c  | 19 +++++++++++++++----\n t/t9300-fast-import.sh | 43 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 58 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex fbd919982c..574a03c484 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -292,6 +292,9 @@ 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,\n+\t\t\t\t\tstruct 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 +2661,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}\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex d9de2ef0d8..9001e2572a 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -3938,4 +3938,47 @@ test_expect_success 'Y: rewrite submodules' '\n \t)\n '\n \n+test_expect_success 'Y: reference pending tag or commit' '\n+\ttest_oid_cache <<-EOF &&\n+\t\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n+\t\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n+\t\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n+\t\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n+\t\tEOF\n+\n+\tgit init reference-pending &&\n+\t(\n+\t\tcd reference-pending &&\n+\t\tgit fast-import <<-EOF\n+\t\t\tcommit refs/heads/main\n+\t\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n+\t\t\tdata 14\n+\t\t\tcommit message\n+\t\t\tM 644 inline test file\n+\t\t\tdata 14\n+\t\t\tdummy content\n+\n+\t\t\ttag newtag\n+\t\t\tfrom $(test_oid pending_commit)\n+\t\t\ttagger A U Thor <author@example.com> 1712563300 +0000\n+\t\t\tdata 11\n+\t\t\ttag message\n+\t\t\t# no emty line after tag data!\n+\t\t\treset refs/heads/other\n+\t\t\tfrom $(test_oid pending_tag)\n+\n+\t\t\tcommit refs/heads/further\n+\t\t\tcommitter A U Thor <author@example.com> 1712563400 +0000\n+\t\t\tdata 21\n+\t\t\twhat about 2nd commit\n+\t\t\tfrom $(test_oid pending_commit)\n+\t\t\tM 644 inline other test file\n+\t\t\tdata 19\n+\t\t\tmore dummy content\n+\n+\t\t\tdone\n+\t\t\tEOF\n+\t)\n+'\n+\n test_done\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\n-- \ngitgitgadget\n\n"},{"id":"555066","messageId":"xmqqmrsgqdl7.fsf@gitster.g","threadId":"66501","inReplyTo":"pull.2252.v3.git.1791995252623.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] fast-import: allow 'from' to reference new commits and tags by oid","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-14T19:36:20Z","receivedAt":"2026-10-14T19:36:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Marc Becker via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\n> index d9de2ef0d8..9001e2572a 100755\n> --- a/t/t9300-fast-import.sh\n> +++ b/t/t9300-fast-import.sh\n> @@ -3938,4 +3938,47 @@ test_expect_success 'Y: rewrite submodules' '\n>  \t)\n>  '\n>  \n> +test_expect_success 'Y: reference pending tag or commit' '\n> +\ttest_oid_cache <<-EOF &&\n> +\t\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n> +\t\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n> +\t\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n> +\t\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n> +\t\tEOF\n\nLooking at the output from\n\n    $ git grep -A4 'test_oid_cache <<' t\n\ntells us that here-doc used in the above is indented by one level\ntoo deep.  I will leave checking how the \"git fast-import <<-EOF\"\nshould be written as an exercise to the reader ;-)\n\nThanks.\n\n> +\tgit init reference-pending &&\n> +\t(\n> +\t\tcd reference-pending &&\n> +\t\tgit fast-import <<-EOF\n> +\t\t\tcommit refs/heads/main\n> +\t\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n> + ...\n> +\t\t\tdone\n> +\t\t\tEOF\n> +\t)\n> +'\n\n"},{"id":"555078","messageId":"pull.2252.v4.git.1792012956734.gitgitgadget@gmail.com","threadId":"66501","inReplyTo":"pull.2252.git.1791653078449.gitgitgadget@gmail.com","subject":"[PATCH v4] fast-import: allow 'from' to reference new commits and tags by oid","fromName":"Marc Becker via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-14T21:22:36Z","receivedAt":"2026-10-14T21:22:36Z","isPatch":true,"sender":{"key":"marc.becker@astos.de","avatar":null},"body":"From: Marc Becker <becm@gmx.de>\n\nDuring a 'git fast-import' session, newly created objects are written\nto an in-progress packfile and recorded in fast-import's internal\nobject table.  Until a 'checkpoint' command or the end of the session\nfinalizes and indexes that packfile, these objects are not visible to\nthe repository's object database via odb_read_object_peeled().\n\nCommands such as 'ls' (via parse_treeish_dataref() and dereference())\nand 'cat-blob' already account for this when given a hex object name:\nthey look up the object in fast-import's internal object table with\nfind_object() first and read it from the in-progress packfile with\ngfi_unpack_entry() when its '.pack_id' is not MAX_PACK_ID.\n\nBy contrast, when 'from <committish>' (in a 'commit' or 'reset'\ncommand) is given a hex object name instead of a mark or branch name,\nparse_objectish() parses the hex string into 'b->oid' and calls\nparse_from_existing(), which unconditionally looks up the object via\nodb_read_object_peeled().  If the object is a commit or tag created in\nthe current pack cycle, odb_read_object_peeled() returns NULL and\nfast-import dies with \"fatal: not a valid commit: <oid>\".\n\nTeach parse_from_existing() to look up 'b->oid' with find_object()\nfirst, peel any tag objects in the object table using dereference(),\nand unpack the target commit with gfi_unpack_entry() if it resides in\nthe in-progress packfile, before falling back to\nodb_read_object_peeled() for objects in the repository's object\ndatabase.\n\nSigned-off-by: Marc Becker <becm@gmx.de>\n---\n    fast-import: fix lookup for new commits\n    \n    Changes since v3:\n    \n     * align here-doc indention in test with expected style\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2252%2Fbecm%2Ffix-fast-import-commit-from-existing-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2252/becm/fix-fast-import-commit-from-existing-v4\nPull-Request: https://github.com/gitgitgadget/git/pull/2252\n\nRange-diff vs v3:\n\n 1:  25113432c6 ! 1:  0daef81925 fast-import: allow 'from' to reference new commits and tags by oid\n     @@ t/t9300-fast-import.sh: test_expect_success 'Y: rewrite submodules' '\n       \n      +test_expect_success 'Y: reference pending tag or commit' '\n      +\ttest_oid_cache <<-EOF &&\n     -+\t\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n     -+\t\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     -+\t\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n     -+\t\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n     -+\t\tEOF\n     ++\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n     ++\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n     ++\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n     ++\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n     ++\tEOF\n      +\n      +\tgit init reference-pending &&\n      +\t(\n      +\t\tcd reference-pending &&\n      +\t\tgit fast-import <<-EOF\n     -+\t\t\tcommit refs/heads/main\n     -+\t\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n     -+\t\t\tdata 14\n     -+\t\t\tcommit message\n     -+\t\t\tM 644 inline test file\n     -+\t\t\tdata 14\n     -+\t\t\tdummy content\n     ++\t\tcommit refs/heads/main\n     ++\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n     ++\t\tdata 14\n     ++\t\tcommit message\n     ++\t\tM 644 inline test file\n     ++\t\tdata 14\n     ++\t\tdummy content\n      +\n     -+\t\t\ttag newtag\n     -+\t\t\tfrom $(test_oid pending_commit)\n     -+\t\t\ttagger A U Thor <author@example.com> 1712563300 +0000\n     -+\t\t\tdata 11\n     -+\t\t\ttag message\n     -+\t\t\t# no emty line after tag data!\n     -+\t\t\treset refs/heads/other\n     -+\t\t\tfrom $(test_oid pending_tag)\n     ++\t\ttag newtag\n     ++\t\tfrom $(test_oid pending_commit)\n     ++\t\ttagger A U Thor <author@example.com> 1712563300 +0000\n     ++\t\tdata 11\n     ++\t\ttag message\n     ++\t\t# no emty line after tag data!\n     ++\t\treset refs/heads/other\n     ++\t\tfrom $(test_oid pending_tag)\n      +\n     -+\t\t\tcommit refs/heads/further\n     -+\t\t\tcommitter A U Thor <author@example.com> 1712563400 +0000\n     -+\t\t\tdata 21\n     -+\t\t\twhat about 2nd commit\n     -+\t\t\tfrom $(test_oid pending_commit)\n     -+\t\t\tM 644 inline other test file\n     -+\t\t\tdata 19\n     -+\t\t\tmore dummy content\n     ++\t\tcommit refs/heads/further\n     ++\t\tcommitter A U Thor <author@example.com> 1712563400 +0000\n     ++\t\tdata 21\n     ++\t\twhat about 2nd commit\n     ++\t\tfrom $(test_oid pending_commit)\n     ++\t\tM 644 inline other test file\n     ++\t\tdata 19\n     ++\t\tmore dummy content\n      +\n     -+\t\t\tdone\n     -+\t\t\tEOF\n     ++\t\tdone\n     ++\t\tEOF\n      +\t)\n      +'\n      +\n\n\n builtin/fast-import.c  | 19 +++++++++++++++----\n t/t9300-fast-import.sh | 43 ++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 58 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex fbd919982c..574a03c484 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -292,6 +292,9 @@ 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,\n+\t\t\t\t\tstruct 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 +2661,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}\ndiff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh\nindex d9de2ef0d8..73c6e3d448 100755\n--- a/t/t9300-fast-import.sh\n+++ b/t/t9300-fast-import.sh\n@@ -3938,4 +3938,47 @@ test_expect_success 'Y: rewrite submodules' '\n \t)\n '\n \n+test_expect_success 'Y: reference pending tag or commit' '\n+\ttest_oid_cache <<-EOF &&\n+\tpending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04\n+\tpending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d\n+\tpending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7\n+\tpending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46\n+\tEOF\n+\n+\tgit init reference-pending &&\n+\t(\n+\t\tcd reference-pending &&\n+\t\tgit fast-import <<-EOF\n+\t\tcommit refs/heads/main\n+\t\tcommitter A U Thor <author@example.com> 1712563200 +0000\n+\t\tdata 14\n+\t\tcommit message\n+\t\tM 644 inline test file\n+\t\tdata 14\n+\t\tdummy content\n+\n+\t\ttag newtag\n+\t\tfrom $(test_oid pending_commit)\n+\t\ttagger A U Thor <author@example.com> 1712563300 +0000\n+\t\tdata 11\n+\t\ttag message\n+\t\t# no emty line after tag data!\n+\t\treset refs/heads/other\n+\t\tfrom $(test_oid pending_tag)\n+\n+\t\tcommit refs/heads/further\n+\t\tcommitter A U Thor <author@example.com> 1712563400 +0000\n+\t\tdata 21\n+\t\twhat about 2nd commit\n+\t\tfrom $(test_oid pending_commit)\n+\t\tM 644 inline other test file\n+\t\tdata 19\n+\t\tmore dummy content\n+\n+\t\tdone\n+\t\tEOF\n+\t)\n+'\n+\n test_done\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\n-- \ngitgitgadget\n\n"},{"id":"555084","messageId":"xmqqqzhrq4ye.fsf@gitster.g","threadId":"66501","inReplyTo":"pull.2252.v4.git.1792012956734.gitgitgadget@gmail.com","subject":"Re: [PATCH v4] fast-import: allow 'from' to reference new commits and tags by oid","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-14T22:42:49Z","receivedAt":"2026-10-14T22:42:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Marc Becker via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Marc Becker <becm@gmx.de>\n>\n> During a 'git fast-import' session, newly created objects are written\n> to an in-progress packfile and recorded in fast-import's internal\n> object table.  Until a 'checkpoint' command or the end of the session\n> finalizes and indexes that packfile, these objects are not visible to\n> the repository's object database via odb_read_object_peeled().\n>\n> Commands such as 'ls' (via parse_treeish_dataref() and dereference())\n> and 'cat-blob' already account for this when given a hex object name:\n> they look up the object in fast-import's internal object table with\n> find_object() first and read it from the in-progress packfile with\n> gfi_unpack_entry() when its '.pack_id' is not MAX_PACK_ID.\n>\n> By contrast, when 'from <committish>' (in a 'commit' or 'reset'\n> command) is given a hex object name instead of a mark or branch name,\n> parse_objectish() parses the hex string into 'b->oid' and calls\n> parse_from_existing(), which unconditionally looks up the object via\n> odb_read_object_peeled().  If the object is a commit or tag created in\n> the current pack cycle, odb_read_object_peeled() returns NULL and\n> fast-import dies with \"fatal: not a valid commit: <oid>\".\n>\n> Teach parse_from_existing() to look up 'b->oid' with find_object()\n> first, peel any tag objects in the object table using dereference(),\n> and unpack the target commit with gfi_unpack_entry() if it resides in\n> the in-progress packfile, before falling back to\n> odb_read_object_peeled() for objects in the repository's object\n> database.\n>\n> Signed-off-by: Marc Becker <becm@gmx.de>\n> ---\n>     fast-import: fix lookup for new commits\n>     \n>     Changes since v3:\n>     \n>      * align here-doc indention in test with expected style\n\nThanks.  This round I have nothing more to add.\n\nWill queue.\n\n"}]}