{"thread":{"id":"66818","subject":"[PATCH 0/4] object-file: eagerly create ODB transaction temporary directory","startedAt":"2026-11-10T00:22:47Z","lastAt":"2026-11-19T20:04:48Z","messageCount":29,"participants":["Justin Tobler","Patrick Steinhardt","Karthik Nayak","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"558012","messageId":"20261110002251.2007617-1-jltobler@gmail.com","threadId":"66818","inReplyTo":null,"subject":"[PATCH 0/4] object-file: eagerly create ODB transaction temporary directory","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T00:22:47Z","receivedAt":"2026-11-10T00:22:47Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"Greetings,\n\nThis series continues work for the \"files\" ODB transactions and makes it\nso the underlying transaction temporary directory is created eagerly.\nPreviously, by default, it would wait for the first object write to\nlazily create the temporary object directory. Furthermore, this series\nalso ensures that objects are written to the temporary directory for all\ntransactional object writes, not just when batched fsync is configured.\n\nThe first three patches consist of some minor preparatory refactors. The\nfinal patch swaps to creating the temporary directory eagerly and drops\nthe lazy setup.\n\nThis series is based on 3c60ef1e38 (The 17th batch, 2026-11-08) with\njt/tmp-objdir-loose-idx-merge merged into it.\n\nThanks,\n-Justin\n\nJustin Tobler (4):\n  object-file: rename default transaction prefix\n  object-file: only flush batched fsync writes when enabled\n  tmp-objdir: preserve errno when directory creation fails\n  object-file: create ODB transaction temporary directory eagerly\n\n object-file.c         | 99 ++++++++++++++++---------------------------\n object-file.h         |  1 -\n odb/source-loose.c    |  6 ---\n t/t0004-unwritable.sh | 19 ++++-----\n tmp-objdir.c          |  8 ++++\n tmp-objdir.h          |  3 +-\n 6 files changed, 54 insertions(+), 82 deletions(-)\n\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558013","messageId":"20261110002251.2007617-2-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"[PATCH 1/4] object-file: rename default transaction prefix","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T00:22:48Z","receivedAt":"2026-11-10T00:22:48Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"By default, the temporary directory created for a \"files\" ODB\ntransaction has its name prefixed with \"bulk-fsync\". This name dates\nback to c0f4752ed2 (core.fsyncmethod: batched disk flushes for\nloose-objects, 2022-04-04), where the temporary object directory only\nserved to batch fsyncs of loose objects.\n\nODB transactions have since grown into a more general interface for\nwriting objects though, and the temporary object directory is not\ninherently tied to how objects are synced. In a subsequent commit, the\ntemporary object directory is created for every transaction regardless\nof the configured fsync method, which would make the name misleading.\n\nRename the default prefix to \"transaction\" accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 132aaab6f8..201d9d6490 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -1566,7 +1566,7 @@ int odb_transaction_files_begin(struct odb_source *source,\n \ttransaction->flags = flags;\n \tstrvec_init(&transaction->pack_names);\n \n-\ttransaction->prefix = \"bulk-fsync\";\n+\ttransaction->prefix = \"transaction\";\n \tif (flags & ODB_TRANSACTION_RECEIVE) {\n \t\t/*\n \t\t * ODB transactions for git-receive-pack(1) eagerly create a\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558014","messageId":"20261110002251.2007617-3-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"[PATCH 2/4] object-file: only flush batched fsync writes when enabled","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T00:22:49Z","receivedAt":"2026-11-10T00:22:49Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When committing an ODB transaction for the \"files\" backend, a full\nhardware flush is issued against a temporary file before the staged\nobjects are migrated into the main object database. This flush acts as a\nbarrier for objects that have been written with batched fsync, where\n`odb_transaction_files_fsync()` only issues a writeout request for each\nobject instead of fully syncing it.\n\nThe flush is issued whenever the transaction has a temporary object\ndirectory though, regardless of whether batched fsync is actually\nenabled. For transactions configured for git-receive-pack(1), the\ntemporary object directory is always created, so the flush is also\nperformed when objects are synced individually or not synced at all. In\nthose cases there are no pending writeout requests and the flush is\nunnecessary. Only issue the flush when batched fsync is enabled\naccordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c | 43 +++++++++++++++++++++++++------------------\n 1 file changed, 25 insertions(+), 18 deletions(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 201d9d6490..da189111bd 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -1330,6 +1330,29 @@ static int write_pack_lockfiles(struct odb_transaction_files *transaction)\n \treturn ret;\n }\n \n+static void flush_batched_fsync(struct repository *repo)\n+{\n+\tstruct strbuf temp_path = STRBUF_INIT;\n+\tstruct tempfile *temp;\n+\n+\t/*\n+\t * Issue a full hardware flush against a temporary file to ensure\n+\t * that all objects are durable before any renames occur. The code in\n+\t * odb_transaction_files_fsync has already issued a writeout\n+\t * request, but it has not flushed any writeback cache in the storage\n+\t * hardware or any filesystem logs. This fsync call acts as a barrier\n+\t * to ensure that the data in each new object file is durable before\n+\t * the final name is visible.\n+\t */\n+\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n+\t\t    repo_get_object_directory(repo));\n+\ttemp = xmks_tempfile(temp_path.buf);\n+\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n+\n+\tstrbuf_release(&temp_path);\n+\tdelete_tempfile(&temp);\n+}\n+\n static int odb_transaction_files_commit(struct odb_transaction *base)\n {\n \tstruct odb_transaction_files *transaction =\n@@ -1339,24 +1362,8 @@ static int odb_transaction_files_commit(struct odb_transaction *base)\n \tflush_packfile_transaction(transaction);\n \n \tif (transaction->objdir) {\n-\t\tstruct strbuf temp_path = STRBUF_INIT;\n-\t\tstruct tempfile *temp;\n-\n-\t\t/*\n-\t\t * Issue a full hardware flush against a temporary file to ensure\n-\t\t * that all objects are durable before any renames occur. The code in\n-\t\t * odb_transaction_files_fsync has already issued a writeout\n-\t\t * request, but it has not flushed any writeback cache in the storage\n-\t\t * hardware or any filesystem logs. This fsync call acts as a barrier\n-\t\t * to ensure that the data in each new object file is durable before\n-\t\t * the final name is visible.\n-\t\t */\n-\t\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n-\t\t\t    repo_get_object_directory(transaction->base.source->odb->repo));\n-\t\ttemp = xmks_tempfile(temp_path.buf);\n-\t\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n-\t\tdelete_tempfile(&temp);\n-\t\tstrbuf_release(&temp_path);\n+\t\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n+\t\t\tflush_batched_fsync(transaction->base.source->odb->repo);\n \n \t\tif (write_pack_lockfiles(transaction))\n \t\t\treturn error(_(\"unable to lock packfiles\"));\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558015","messageId":"20261110002251.2007617-4-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"[PATCH 3/4] tmp-objdir: preserve errno when directory creation fails","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T00:22:50Z","receivedAt":"2026-11-10T00:22:50Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When `tmp_objdir_create()` fails to create the temporary object\ndirectory, it cleans up after itself before returning NULL. Depending on\nwhere the failure occurred, this cleanup may clobber `errno`, leaving\ncallers without a way to reliably tell why creating the directory\nfailed.\n\nIn a subsequent commit, ODB transactions create their temporary object\ndirectory eagerly and report a more specific error regarding creation\nfailure. Preserve `errno` across the cleanup so that callers can inspect\nit accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n tmp-objdir.c | 8 ++++++++\n tmp-objdir.h | 3 ++-\n 2 files changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex 5307717354..4b91d86787 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -148,10 +148,13 @@ static int setup_tmp_objdir(const char *root)\n {\n \tchar *path;\n \tint ret = 0;\n+\tint saved_errno;\n \n \tpath = xstrfmt(\"%s/pack\", root);\n \tret = mkdir(path, 0777);\n+\tsaved_errno = errno;\n \tfree(path);\n+\terrno = saved_errno;\n \n \treturn ret;\n }\n@@ -163,6 +166,7 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tstruct odb_source_files *files = odb_source_files_downcast(r->objects->source);\n \tstatic int installed_handlers;\n \tstruct tmp_objdir *t;\n+\tint saved_errno;\n \n \tif (the_tmp_objdir)\n \t\tBUG(\"only one tmp_objdir can be used at a time\");\n@@ -185,8 +189,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\tchdir_notify_register(tmp_objdir_reparent, t);\n \n \tif (!mkdtemp(t->path.buf)) {\n+\t\tsaved_errno = errno;\n \t\t/* free, not destroy, as we never touched the filesystem */\n \t\ttmp_objdir_free(t);\n+\t\terrno = saved_errno;\n \t\treturn NULL;\n \t}\n \n@@ -197,7 +203,9 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t}\n \n \tif (setup_tmp_objdir(t->path.buf)) {\n+\t\tsaved_errno = errno;\n \t\ttmp_objdir_destroy(t);\n+\t\terrno = saved_errno;\n \t\treturn NULL;\n \t}\n \ndiff --git a/tmp-objdir.h b/tmp-objdir.h\nindex a301b01d84..4ef6750a01 100644\n--- a/tmp-objdir.h\n+++ b/tmp-objdir.h\n@@ -26,7 +26,8 @@ struct tmp_objdir;\n \n /*\n  * Create a new temporary object directory with the specified prefix and\n- * install the directory as the primary write target; returns NULL on failure.\n+ * install the directory as the primary write target; returns NULL and sets\n+ * errno on failure.\n  */\n struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix,\n \t\t\t\t     int will_destroy);\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558016","messageId":"20261110002251.2007617-5-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"[PATCH 4/4] object-file: create ODB transaction temporary directory eagerly","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-10T00:22:51Z","receivedAt":"2026-11-10T00:22:51Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"By default, ODB transactions for the \"files\" backend create their\ntemporary object directory lazily once the first loose object is about\nto be written, and only if batched fsync is enabled. Transactions\nconfigured for git-receive-pack(1) are the exception as the directory is\nneeded to quarantine incoming objects up front. Lazily creating the\ntemporary directory in this manner is awkward for a couple of reasons:\n\n  - Writing loose objects has to know about the transaction internals to\n    trigger the lazy creation of the temporary object directory.\n\n  - Whether objects are staged in a temporary object directory, and thus\n    whether they become visible at once on commit, depends on the\n    configured fsync method.\n\nCreate the temporary object directory eagerly for every transaction when\nit is started instead. This also ensures that no object is written to\nthe main object database before the transaction is committed.\n\nNote that committing a transaction migrates every written object into\nthe primary object directory even when batched fsync is disabled. This\nadds some minor overhead to ODB transaction callers that previously only\nused a temporary directory if batched fsync was enabled. The following\nbenchmark uses the default fsync configuration and adds 10000 files of 4\nKiB each to a freshly initialized repository via git-add(1):\n\n  Benchmark 1: git add . (rev = HEAD~)\n    Time (mean ± σ):     895.0 ms ±  23.8 ms    [User: 545.3 ms, System: 340.7 ms]\n    Range (min … max):   866.7 ms … 928.7 ms    20 runs\n\n  Benchmark 2: git add . (rev = HEAD)\n    Time (mean ± σ):     956.3 ms ±  26.1 ms    [User: 541.4 ms, System: 405.2 ms]\n    Range (min … max):   923.9 ms … 993.6 ms    20 runs\n\n  Summary\n    git add . (rev = HEAD~) ran\n      1.07 ± 0.04 times faster than git add . (rev = HEAD)\n\nTypically large numbers of loose objects are not expected to be written\ninto an ODB transaction so the overhead here should be marginal.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c         | 56 +++++++++----------------------------------\n object-file.h         |  1 -\n odb/source-loose.c    |  6 -----\n t/t0004-unwritable.sh | 19 +++++++--------\n 4 files changed, 19 insertions(+), 63 deletions(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex da189111bd..a9fb42705c 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -489,7 +489,6 @@ struct odb_transaction_files {\n \n \tstruct tmp_objdir *objdir;\n \tstruct transaction_packfile packfile;\n-\tconst char *prefix;\n \n \tstruct strvec pack_names;\n \tstruct tempfile **pack_lockfiles;\n@@ -497,27 +496,6 @@ struct odb_transaction_files {\n \tsize_t pack_lockfiles_alloc;\n };\n \n-int odb_transaction_files_prepare(struct odb_transaction *base)\n-{\n-\tstruct odb_transaction_files *transaction =\n-\t\tcontainer_of_or_null(base, struct odb_transaction_files, base);\n-\n-\t/*\n-\t * We lazily create the temporary object directory\n-\t * the first time an object might be added, since\n-\t * callers may not know whether any objects will be\n-\t * added at the time they call odb_transaction_files_begin.\n-\t */\n-\tif (!transaction || transaction->objdir)\n-\t\treturn 0;\n-\n-\ttransaction->objdir = tmp_objdir_create(base->source->odb->repo, transaction->prefix, 0);\n-\tif (!transaction->objdir)\n-\t\treturn error(_(\"unable to create temporary object directory\"));\n-\n-\treturn 0;\n-}\n-\n void odb_transaction_files_fsync(struct odb_transaction *base,\n \t\t\t\t int fd, const char *filename)\n {\n@@ -1548,13 +1526,10 @@ static int odb_transaction_files_env(struct odb_transaction *base,\n {\n \tstruct odb_transaction_files *transaction =\n \t\tcontainer_of(base, struct odb_transaction_files, base);\n-\tint ret;\n \n-\tret = odb_transaction_files_prepare(&transaction->base);\n-\tif (!ret)\n-\t\tstrvec_pushv(env, tmp_objdir_env(transaction->objdir));\n+\tstrvec_pushv(env, tmp_objdir_env(transaction->objdir));\n \n-\treturn ret;\n+\treturn 0;\n }\n \n int odb_transaction_files_begin(struct odb_source *source,\n@@ -1562,6 +1537,8 @@ int odb_transaction_files_begin(struct odb_source *source,\n \t\t\t\tenum odb_transaction_flags flags)\n {\n \tstruct odb_transaction_files *transaction;\n+\tconst char *prefix;\n+\tint ret;\n \n \ttransaction = xcalloc(1, sizeof(*transaction));\n \ttransaction->base.source = source;\n@@ -1573,24 +1550,13 @@ int odb_transaction_files_begin(struct odb_source *source,\n \ttransaction->flags = flags;\n \tstrvec_init(&transaction->pack_names);\n \n-\ttransaction->prefix = \"transaction\";\n-\tif (flags & ODB_TRANSACTION_RECEIVE) {\n-\t\t/*\n-\t\t * ODB transactions for git-receive-pack(1) eagerly create a\n-\t\t * temporary directory and use a different temporary directory\n-\t\t * prefix.\n-\t\t *\n-\t\t * NEEDSWORK: This transaction flag is only used by the \"files\"\n-\t\t * backend to special case temporary directory set up and\n-\t\t * handling. Ideally transaction users should not have to care\n-\t\t * though. To avoid this, we could eagerly create the temporary\n-\t\t * directory and use the same prefix name for all transactions.\n-\t\t */\n-\t\ttransaction->prefix = \"incoming\";\n-\t\tif (odb_transaction_files_prepare(&transaction->base)) {\n-\t\t\tfree(transaction);\n-\t\t\treturn -1;\n-\t\t}\n+\tprefix = flags & ODB_TRANSACTION_RECEIVE ? \"incoming\" : \"transaction\";\n+\ttransaction->objdir = tmp_objdir_create(source->odb->repo, prefix, 0);\n+\tif (!transaction->objdir) {\n+\t\tret = error_errno(_(\"unable to create temporary object directory in %s\"),\n+\t\t\t\t  source->path);\n+\t\tfree(transaction);\n+\t\treturn ret;\n \t}\n \n \t*out = &transaction->base;\ndiff --git a/object-file.h b/object-file.h\nindex f44758c4f8..9ad79bbde0 100644\n--- a/object-file.h\n+++ b/object-file.h\n@@ -177,7 +177,6 @@ int odb_transaction_files_begin(struct odb_source *source,\n \t\t\t\tstruct odb_transaction **out,\n \t\t\t\tenum odb_transaction_flags flags);\n \n-int odb_transaction_files_prepare(struct odb_transaction *base);\n void odb_transaction_files_fsync(struct odb_transaction *base,\n \t\t\t\t int fd, const char *filename);\n \ndiff --git a/odb/source-loose.c b/odb/source-loose.c\nindex 50cb388c35..9330ae94b5 100644\n--- a/odb/source-loose.c\n+++ b/odb/source-loose.c\n@@ -769,9 +769,6 @@ static int write_loose_object(struct odb_source_loose *loose,\n \tstatic struct strbuf tmp_file = STRBUF_INIT;\n \tstatic struct strbuf filename = STRBUF_INIT;\n \n-\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n-\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n-\n \todb_loose_path(loose, &filename, oid);\n \n \tfd = start_loose_object_common(loose, &tmp_file, filename.buf, flags,\n@@ -860,9 +857,6 @@ static int odb_source_loose_write_object_stream(struct odb_source *source,\n \tchar hdr[MAX_HEADER_LEN];\n \tint hdrlen;\n \n-\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n-\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n-\n \t/* Since oid is not determined, save tmp file to odb path. */\n \tstrbuf_addf(&filename, \"%s/\", loose->base.path);\n \thdrlen = format_object_header(hdr, sizeof(hdr), in_stream->type, in_stream->size);\ndiff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh\nindex 3bdafbae0f..7292672a66 100755\n--- a/t/t0004-unwritable.sh\n+++ b/t/t0004-unwritable.sh\n@@ -24,8 +24,8 @@ test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable reposi\n test_lazy_prereq WRITE_TREE_OUT 'test -e \"$TRASH_DIRECTORY\"/out.write-tree'\n test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\tfatal: git-write-tree: error building trees\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start ODB transaction\n \tEOF\n \ttest_cmp expect out.write-tree\n '\n@@ -39,8 +39,8 @@ test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository\n test_lazy_prereq COMMIT_OUT 'test -e \"$TRASH_DIRECTORY\"/out.commit'\n test_expect_success COMMIT_OUT 'commit output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: Error building trees\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start ODB transaction\n \tEOF\n \ttest_cmp expect out.commit\n '\n@@ -55,9 +55,8 @@ test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repo\n test_lazy_prereq UPDATE_INDEX_OUT 'test -e \"$TRASH_DIRECTORY\"/out.update-index'\n test_expect_success UPDATE_INDEX_OUT 'update-index output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: file: failed to insert into database\n-\tfatal: Unable to process path file\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start ODB transaction\n \tEOF\n \ttest_cmp expect out.update-index\n '\n@@ -72,10 +71,8 @@ test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '\n test_lazy_prereq ADD_OUT 'test -e \"$TRASH_DIRECTORY\"/out.add'\n test_expect_success ADD_OUT 'add output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: file: failed to insert into database\n-\terror: unable to index file '\\''file'\\''\n-\tfatal: updating files failed\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start ODB transaction\n \tEOF\n \ttest_cmp expect out.add\n '\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558202","messageId":"avRqiH9eIpJUGKMo@pks.im","threadId":"66818","inReplyTo":"20261110002251.2007617-5-jltobler@gmail.com","subject":"Re: [PATCH 4/4] object-file: create ODB transaction temporary directory eagerly","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T13:15:52Z","receivedAt":"2026-11-11T13:15:52Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 06:22:51PM -0600, Justin Tobler wrote:\n> By default, ODB transactions for the \"files\" backend create their\n> temporary object directory lazily once the first loose object is about\n> to be written, and only if batched fsync is enabled. Transactions\n> configured for git-receive-pack(1) are the exception as the directory is\n> needed to quarantine incoming objects up front. Lazily creating the\n> temporary directory in this manner is awkward for a couple of reasons:\n> \n>   - Writing loose objects has to know about the transaction internals to\n>     trigger the lazy creation of the temporary object directory.\n> \n>   - Whether objects are staged in a temporary object directory, and thus\n>     whether they become visible at once on commit, depends on the\n>     configured fsync method.\n\nAnd three: the whole premise of creating ad-hoc transactions behind the\ncaller's back for the purpose of bulk-flushing writes to disk is\nsomewhat flawed in the first place. In a perfect world I'd think that\ncallers would manually manage their object transactions in all cases\nwhere they know to write multiple objects at once.\n\nBut we don't live in that world (yet), and this step here brings us a\nbit closer to it.\n\n> diff --git a/object-file.c b/object-file.c\n> index da189111bd..a9fb42705c 100644\n> --- a/object-file.c\n> +++ b/object-file.c\n> @@ -1573,24 +1550,13 @@ int odb_transaction_files_begin(struct odb_source *source,\n>  \ttransaction->flags = flags;\n>  \tstrvec_init(&transaction->pack_names);\n>  \n> -\ttransaction->prefix = \"transaction\";\n> -\tif (flags & ODB_TRANSACTION_RECEIVE) {\n> -\t\t/*\n> -\t\t * ODB transactions for git-receive-pack(1) eagerly create a\n> -\t\t * temporary directory and use a different temporary directory\n> -\t\t * prefix.\n> -\t\t *\n> -\t\t * NEEDSWORK: This transaction flag is only used by the \"files\"\n> -\t\t * backend to special case temporary directory set up and\n> -\t\t * handling. Ideally transaction users should not have to care\n> -\t\t * though. To avoid this, we could eagerly create the temporary\n> -\t\t * directory and use the same prefix name for all transactions.\n> -\t\t */\n> -\t\ttransaction->prefix = \"incoming\";\n> -\t\tif (odb_transaction_files_prepare(&transaction->base)) {\n> -\t\t\tfree(transaction);\n> -\t\t\treturn -1;\n> -\t\t}\n> +\tprefix = flags & ODB_TRANSACTION_RECEIVE ? \"incoming\" : \"transaction\";\n\nMakes me wonder whether it's important to keep the \"incoming\" prefix\nhere or whether there is an argument to be made that it should simply be\ncalled \"transaction\", as well.\n\nThat may be out of scope for this series though.\n\n> +\ttransaction->objdir = tmp_objdir_create(source->odb->repo, prefix, 0);\n> +\tif (!transaction->objdir) {\n> +\t\tret = error_errno(_(\"unable to create temporary object directory in %s\"),\n> +\t\t\t\t  source->path);\n> +\t\tfree(transaction);\n> +\t\treturn ret;\n>  \t}\n>  \n>  \t*out = &transaction->base;\n\nNice, this logic becomes quite a bit simpler.\n\n> diff --git a/odb/source-loose.c b/odb/source-loose.c\n> index 50cb388c35..9330ae94b5 100644\n> --- a/odb/source-loose.c\n> +++ b/odb/source-loose.c\n> @@ -769,9 +769,6 @@ static int write_loose_object(struct odb_source_loose *loose,\n>  \tstatic struct strbuf tmp_file = STRBUF_INIT;\n>  \tstatic struct strbuf filename = STRBUF_INIT;\n>  \n> -\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n> -\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n> -\n>  \todb_loose_path(loose, &filename, oid);\n>  \n>  \tfd = start_loose_object_common(loose, &tmp_file, filename.buf, flags,\n> @@ -860,9 +857,6 @@ static int odb_source_loose_write_object_stream(struct odb_source *source,\n>  \tchar hdr[MAX_HEADER_LEN];\n>  \tint hdrlen;\n>  \n> -\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n> -\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n> -\n>  \t/* Since oid is not determined, save tmp file to odb path. */\n>  \tstrbuf_addf(&filename, \"%s/\", loose->base.path);\n>  \thdrlen = format_object_header(hdr, sizeof(hdr), in_stream->type, in_stream->size);\n\nNice to see that we can get rid of all of this leaking abstraction.\n\n> diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh\n> index 3bdafbae0f..7292672a66 100755\n> --- a/t/t0004-unwritable.sh\n> +++ b/t/t0004-unwritable.sh\n> @@ -24,8 +24,8 @@ test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable reposi\n>  test_lazy_prereq WRITE_TREE_OUT 'test -e \"$TRASH_DIRECTORY\"/out.write-tree'\n>  test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '\n>  \tcat >expect <<-\\EOF &&\n> -\terror: insufficient permission for adding an object to repository database .git/objects\n> -\tfatal: git-write-tree: error building trees\n> +\terror: unable to create temporary object directory in .git/objects: Permission denied\n> +\tfatal: failed to start ODB transaction\n\nNot a new issue, but this second error message is awful. An average user\nwon't have any idea what an \"ODB\" even is. s/ODB/object/ would make a\nlot more sense.\n\nPatrick\n\n"},{"id":"558203","messageId":"avRqjlLbMOfFRQse@pks.im","threadId":"66818","inReplyTo":"20261110002251.2007617-2-jltobler@gmail.com","subject":"Re: [PATCH 1/4] object-file: rename default transaction prefix","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T13:15:58Z","receivedAt":"2026-11-11T13:15:58Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 06:22:48PM -0600, Justin Tobler wrote:\n> By default, the temporary directory created for a \"files\" ODB\n> transaction has its name prefixed with \"bulk-fsync\". This name dates\n> back to c0f4752ed2 (core.fsyncmethod: batched disk flushes for\n> loose-objects, 2022-04-04), where the temporary object directory only\n> served to batch fsyncs of loose objects.\n> \n> ODB transactions have since grown into a more general interface for\n> writing objects though, and the temporary object directory is not\n> inherently tied to how objects are synced.\n\nRight. We don't really use it for a lot of cases yet, but we anticipate\nthat we'll start using it more often now that it becomes more generally\nuseful.\n\n> In a subsequent commit, the\n> temporary object directory is created for every transaction regardless\n> of the configured fsync method, which would make the name misleading.\n> \n> Rename the default prefix to \"transaction\" accordingly.\n\nWe could of course change the logic so that we make the prefix dependent\non the actual caller. But I really doubt that this would be sensible, so\nI'm very much aligned with naming those directories more generically.\n\nPatrick\n\n"},{"id":"558204","messageId":"avRqlHdN83O67HB1@pks.im","threadId":"66818","inReplyTo":"20261110002251.2007617-3-jltobler@gmail.com","subject":"Re: [PATCH 2/4] object-file: only flush batched fsync writes when enabled","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T13:16:04Z","receivedAt":"2026-11-11T13:16:04Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 06:22:49PM -0600, Justin Tobler wrote:\n> When committing an ODB transaction for the \"files\" backend, a full\n> hardware flush is issued against a temporary file before the staged\n> objects are migrated into the main object database. This flush acts as a\n> barrier for objects that have been written with batched fsync, where\n> `odb_transaction_files_fsync()` only issues a writeout request for each\n> object instead of fully syncing it.\n\nHmm, okay. The difference here is bascially that we don't issue a\nhardware flush. So we know that the data is not in the page cache\nanymore, but it may still only be cached by the disk.\n\n> The flush is issued whenever the transaction has a temporary object\n> directory though, regardless of whether batched fsync is actually\n> enabled. For transactions configured for git-receive-pack(1), the\n> temporary object directory is always created, so the flush is also\n> performed when objects are synced individually or not synced at all. In\n> those cases there are no pending writeout requests and the flush is\n> unnecessary. Only issue the flush when batched fsync is enabled\n> accordingly.\n\nSo this is essentially a performance optimization?\n\n> diff --git a/object-file.c b/object-file.c\n> index 201d9d6490..da189111bd 100644\n> --- a/object-file.c\n> +++ b/object-file.c\n> @@ -1330,6 +1330,29 @@ static int write_pack_lockfiles(struct odb_transaction_files *transaction)\n>  \treturn ret;\n>  }\n>  \n> +static void flush_batched_fsync(struct repository *repo)\n\nOkay. Instead of adding more nesting you extract the code into a\nfunction that gets called conditionally. Fair.\n\n> +{\n> +\tstruct strbuf temp_path = STRBUF_INIT;\n> +\tstruct tempfile *temp;\n> +\n> +\t/*\n> +\t * Issue a full hardware flush against a temporary file to ensure\n> +\t * that all objects are durable before any renames occur. The code in\n> +\t * odb_transaction_files_fsync has already issued a writeout\n> +\t * request, but it has not flushed any writeback cache in the storage\n> +\t * hardware or any filesystem logs. This fsync call acts as a barrier\n> +\t * to ensure that the data in each new object file is durable before\n> +\t * the final name is visible.\n> +\t */\n> +\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n> +\t\t    repo_get_object_directory(repo));\n> +\ttemp = xmks_tempfile(temp_path.buf);\n> +\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n> +\n> +\tstrbuf_release(&temp_path);\n> +\tdelete_tempfile(&temp);\n> +}\n> +\n>  static int odb_transaction_files_commit(struct odb_transaction *base)\n>  {\n>  \tstruct odb_transaction_files *transaction =\n> @@ -1339,24 +1362,8 @@ static int odb_transaction_files_commit(struct odb_transaction *base)\n>  \tflush_packfile_transaction(transaction);\n>  \n>  \tif (transaction->objdir) {\n> -\t\tstruct strbuf temp_path = STRBUF_INIT;\n> -\t\tstruct tempfile *temp;\n> -\n> -\t\t/*\n> -\t\t * Issue a full hardware flush against a temporary file to ensure\n> -\t\t * that all objects are durable before any renames occur. The code in\n> -\t\t * odb_transaction_files_fsync has already issued a writeout\n> -\t\t * request, but it has not flushed any writeback cache in the storage\n> -\t\t * hardware or any filesystem logs. This fsync call acts as a barrier\n> -\t\t * to ensure that the data in each new object file is durable before\n> -\t\t * the final name is visible.\n> -\t\t */\n> -\t\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n> -\t\t\t    repo_get_object_directory(transaction->base.source->odb->repo));\n> -\t\ttemp = xmks_tempfile(temp_path.buf);\n> -\t\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n> -\t\tdelete_tempfile(&temp);\n> -\t\tstrbuf_release(&temp_path);\n> +\t\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n> +\t\t\tflush_batched_fsync(transaction->base.source->odb->repo);\n\nI assume that we only support batched fsyncs for loose objects in the\nfirst place? In other words, if a transaction were to write a bunch of\npackfiles, it would not be possible to batch-fsync those right now?\n\nIf so this new condition correct to me. But I think this should be\ndocumented as part of the commit message, because it's an implicit\nassumption.\n\nPatrick\n\n"},{"id":"558205","messageId":"avRqmRR29QSbj1k4@pks.im","threadId":"66818","inReplyTo":"20261110002251.2007617-4-jltobler@gmail.com","subject":"Re: [PATCH 3/4] tmp-objdir: preserve errno when directory creation fails","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-11T13:16:09Z","receivedAt":"2026-11-11T13:16:09Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 09, 2026 at 06:22:50PM -0600, Justin Tobler wrote:\n> diff --git a/tmp-objdir.c b/tmp-objdir.c\n> index 5307717354..4b91d86787 100644\n> --- a/tmp-objdir.c\n> +++ b/tmp-objdir.c\n> @@ -148,10 +148,13 @@ static int setup_tmp_objdir(const char *root)\n>  {\n>  \tchar *path;\n>  \tint ret = 0;\n> +\tint saved_errno;\n>  \n>  \tpath = xstrfmt(\"%s/pack\", root);\n>  \tret = mkdir(path, 0777);\n> +\tsaved_errno = errno;\n>  \tfree(path);\n> +\terrno = saved_errno;\n>  \n>  \treturn ret;\n>  }\n\nThis whole function here is somewhat pointless, it's only really\nrequired because memory handling would otherwise be awkward. That\ncould've been avoided if its only caller had a single return path, but\nit doesn't.\n\nNo need to fix that as part of your patch series though, if you ask me.\n\n> @@ -163,6 +166,7 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n>  \tstruct odb_source_files *files = odb_source_files_downcast(r->objects->source);\n>  \tstatic int installed_handlers;\n>  \tstruct tmp_objdir *t;\n> +\tint saved_errno;\n>  \n>  \tif (the_tmp_objdir)\n>  \t\tBUG(\"only one tmp_objdir can be used at a time\");\n\nThis could've been a local variable in each of the two blocks, but okay.\n\n> @@ -185,8 +189,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n>  \t\tchdir_notify_register(tmp_objdir_reparent, t);\n>  \n>  \tif (!mkdtemp(t->path.buf)) {\n> +\t\tsaved_errno = errno;\n>  \t\t/* free, not destroy, as we never touched the filesystem */\n>  \t\ttmp_objdir_free(t);\n> +\t\terrno = saved_errno;\n>  \t\treturn NULL;\n>  \t}\n>  \n> @@ -197,7 +203,9 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n>  \t}\n>  \n>  \tif (setup_tmp_objdir(t->path.buf)) {\n> +\t\tsaved_errno = errno;\n>  \t\ttmp_objdir_destroy(t);\n> +\t\terrno = saved_errno;\n>  \t\treturn NULL;\n>  \t}\n\nOkay, both early returns are adapted in the same way. Makes sense.\n\nPatrick\n\n"},{"id":"558217","messageId":"CAOLa=ZTDxY6dJL0ctDtexJpkGE6YxEPo6SEa55aPrF+2VZg1VQ@mail.gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"Re: [PATCH 0/4] object-file: eagerly create ODB transaction temporary directory","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-11T14:33:26Z","receivedAt":"2026-11-11T14:33:26Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> Greetings,\n>\n> This series continues work for the \"files\" ODB transactions and makes it\n> so the underlying transaction temporary directory is created eagerly.\n\nWithout knowing enough, my first question would be 'why'. Over the top,\n'lazily' seems to be a good way to go about this. Hopefully the\nindividual commits explain this.\n\n> Previously, by default, it would wait for the first object write to\n> lazily create the temporary object directory. Furthermore, this series\n> also ensures that objects are written to the temporary directory for all\n> transactional object writes, not just when batched fsync is configured.\n>\n> The first three patches consist of some minor preparatory refactors. The\n> final patch swaps to creating the temporary directory eagerly and drops\n> the lazy setup.\n>\n> This series is based on 3c60ef1e38 (The 17th batch, 2026-11-08) with\n> jt/tmp-objdir-loose-idx-merge merged into it.\n>\n> Thanks,\n> -Justin\n"},{"id":"558218","messageId":"CAOLa=ZRpoB5+woCf=D6PAWkQZ+jDkoDgkpffh=AYwCa8BefQyw@mail.gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-2-jltobler@gmail.com","subject":"Re: [PATCH 1/4] object-file: rename default transaction prefix","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-11T14:36:51Z","receivedAt":"2026-11-11T14:36:51Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> By default, the temporary directory created for a \"files\" ODB\n> transaction has its name prefixed with \"bulk-fsync\". This name dates\n> back to c0f4752ed2 (core.fsyncmethod: batched disk flushes for\n> loose-objects, 2022-04-04), where the temporary object directory only\n> served to batch fsyncs of loose objects.\n>\n> ODB transactions have since grown into a more general interface for\n> writing objects though, and the temporary object directory is not\n> inherently tied to how objects are synced. In a subsequent commit, the\n> temporary object directory is created for every transaction regardless\n> of the configured fsync method, which would make the name misleading.\n>\n> Rename the default prefix to \"transaction\" accordingly.\n>\n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>  object-file.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/object-file.c b/object-file.c\n> index 132aaab6f8..201d9d6490 100644\n> --- a/object-file.c\n> +++ b/object-file.c\n> @@ -1566,7 +1566,7 @@ int odb_transaction_files_begin(struct odb_source *source,\n>  \ttransaction->flags = flags;\n>  \tstrvec_init(&transaction->pack_names);\n>\n> -\ttransaction->prefix = \"bulk-fsync\";\n> +\ttransaction->prefix = \"transaction\";\n\nOkay so the prefix is fed to `tmp_objdir_create()`, which will then name\nit 'tmp_objdir-transaction-XXXXXX'. So this makes sense as we use ODB\ntransactions in a general sense.\n\n>  \tif (flags & ODB_TRANSACTION_RECEIVE) {\n>  \t\t/*\n>  \t\t * ODB transactions for git-receive-pack(1) eagerly create a\n> --\n> 2.56.0.173.gf57c9a7388\n"},{"id":"558220","messageId":"CAOLa=ZRp=JeAGhN3m6-RCos3F82__6Wzt2UsKvUjqHSHUg6o_Q@mail.gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-3-jltobler@gmail.com","subject":"Re: [PATCH 2/4] object-file: only flush batched fsync writes when enabled","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-11T14:48:58Z","receivedAt":"2026-11-11T14:48:58Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> When committing an ODB transaction for the \"files\" backend, a full\n> hardware flush is issued against a temporary file before the staged\n> objects are migrated into the main object database. This flush acts as a\n> barrier for objects that have been written with batched fsync, where\n> `odb_transaction_files_fsync()` only issues a writeout request for each\n> object instead of fully syncing it.\n>\n\nDoes `fsync(fd)` even guarantee syncing of previous writes?\n\n> The flush is issued whenever the transaction has a temporary object\n> directory though, regardless of whether batched fsync is actually\n> enabled. For transactions configured for git-receive-pack(1), the\n> temporary object directory is always created, so the flush is also\n> performed when objects are synced individually or not synced at all. In\n> those cases there are no pending writeout requests and the flush is\n> unnecessary. Only issue the flush when batched fsync is enabled\n> accordingly.\n>\n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>  object-file.c | 43 +++++++++++++++++++++++++------------------\n>  1 file changed, 25 insertions(+), 18 deletions(-)\n>\n> diff --git a/object-file.c b/object-file.c\n> index 201d9d6490..da189111bd 100644\n> --- a/object-file.c\n> +++ b/object-file.c\n> @@ -1330,6 +1330,29 @@ static int write_pack_lockfiles(struct odb_transaction_files *transaction)\n>  \treturn ret;\n>  }\n>\n> +static void flush_batched_fsync(struct repository *repo)\n> +{\n> +\tstruct strbuf temp_path = STRBUF_INIT;\n> +\tstruct tempfile *temp;\n> +\n> +\t/*\n> +\t * Issue a full hardware flush against a temporary file to ensure\n> +\t * that all objects are durable before any renames occur. The code in\n> +\t * odb_transaction_files_fsync has already issued a writeout\n> +\t * request, but it has not flushed any writeback cache in the storage\n> +\t * hardware or any filesystem logs. This fsync call acts as a barrier\n> +\t * to ensure that the data in each new object file is durable before\n> +\t * the final name is visible.\n> +\t */\n\nNit: This could become a function comment, since it now describes the\nfunction well.\n\n> +\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n> +\t\t    repo_get_object_directory(repo));\n> +\ttemp = xmks_tempfile(temp_path.buf);\n> +\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n> +\n> +\tstrbuf_release(&temp_path);\n> +\tdelete_tempfile(&temp);\n> +}\n> +\n\n[snip]\n"},{"id":"558235","messageId":"CAOLa=ZSonhP78j2sJdTwctp2h101jWZbvU_jcg1_TR41cRK7dA@mail.gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-4-jltobler@gmail.com","subject":"Re: [PATCH 3/4] tmp-objdir: preserve errno when directory creation fails","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-11T16:44:02Z","receivedAt":"2026-11-11T16:44:02Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> When `tmp_objdir_create()` fails to create the temporary object\n> directory, it cleans up after itself before returning NULL. Depending on\n> where the failure occurred, this cleanup may clobber `errno`, leaving\n> callers without a way to reliably tell why creating the directory\n> failed.\n>\n> In a subsequent commit, ODB transactions create their temporary object\n> directory eagerly and report a more specific error regarding creation\n> failure. Preserve `errno` across the cleanup so that callers can inspect\n> it accordingly.\n>\n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>  tmp-objdir.c | 8 ++++++++\n>  tmp-objdir.h | 3 ++-\n>  2 files changed, 10 insertions(+), 1 deletion(-)\n>\n> diff --git a/tmp-objdir.c b/tmp-objdir.c\n> index 5307717354..4b91d86787 100644\n> --- a/tmp-objdir.c\n> +++ b/tmp-objdir.c\n> @@ -148,10 +148,13 @@ static int setup_tmp_objdir(const char *root)\n>  {\n>  \tchar *path;\n>  \tint ret = 0;\n> +\tint saved_errno;\n>\n>  \tpath = xstrfmt(\"%s/pack\", root);\n>  \tret = mkdir(path, 0777);\n> +\tsaved_errno = errno;\n>  \tfree(path);\n> +\terrno = saved_errno;\n>\n\nThis and the below pattern of save+restore seems a bit finicky to me.\nCould we instead do:\n\n1. Move this function inline\n\nmodified   tmp-objdir.c\n@@ -144,18 +144,6 @@ static void env_replace(struct strvec *env, const\nchar *key, const char *val)\n \tstrvec_pushf(env, \"%s=%s\", key, val);\n }\n\n-static int setup_tmp_objdir(const char *root)\n-{\n-\tchar *path;\n-\tint ret = 0;\n-\n-\tpath = xstrfmt(\"%s/pack\", root);\n-\tret = mkdir(path, 0777);\n-\tfree(path);\n-\n-\treturn ret;\n-}\n-\n struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\t\t\t     const char *prefix,\n \t\t\t\t     int will_destroy)\n@@ -163,6 +151,8 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tstruct odb_source_files *files =\nodb_source_files_downcast(r->objects->source);\n \tstatic int installed_handlers;\n \tstruct tmp_objdir *t;\n+\tchar *path;\n+\tint ret;\n\n \tif (the_tmp_objdir)\n \t\tBUG(\"only one tmp_objdir can be used at a time\");\n@@ -196,7 +186,11 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\tinstalled_handlers++;\n \t}\n\n-\tif (setup_tmp_objdir(t->path.buf)) {\n+\tpath = xstrfmt(\"%s/pack\", t->path.buf);\n+\tret = mkdir(path, 0777);\n+\tfree(path);\n+\n+\tif (ret) {\n \t\ttmp_objdir_destroy(t);\n \t\treturn NULL;\n \t}\n\n--8<---\n\n2. Then we can only set the errno we actually care about and jump to\nexit\n\nmodified   tmp-objdir.c\n@@ -151,6 +151,7 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tstruct odb_source_files *files =\nodb_source_files_downcast(r->objects->source);\n \tstatic int installed_handlers;\n \tstruct tmp_objdir *t;\n+\tint saved_errno;\n \tchar *path;\n \tint ret;\n\n@@ -175,9 +176,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\tchdir_notify_register(tmp_objdir_reparent, t);\n\n \tif (!mkdtemp(t->path.buf)) {\n+\t\tsaved_errno = errno;\n \t\t/* free, not destroy, as we never touched the filesystem */\n \t\ttmp_objdir_free(t);\n-\t\treturn NULL;\n+\t\tgoto fail;\n \t}\n\n \tthe_tmp_objdir = t;\n@@ -191,8 +193,9 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tfree(path);\n\n \tif (ret) {\n+\t\tsaved_errno = errno;\n \t\ttmp_objdir_destroy(t);\n-\t\treturn NULL;\n+\t\tgoto fail;\n \t}\n\n \tenv_append(&t->env, ALTERNATE_DB_ENVIRONMENT,\n@@ -215,6 +218,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tt->repo->disable_ref_updates = true;\n\n \treturn t;\n+\n+fail:\n+\terrno = saved_errno;\n+\treturn NULL;\n }\n\n--8<---\n\nThis avoids having to care about other syscalls which may be added in\nthe future and breaking our setup as done in the patch here.\n\n[snip]\n"},{"id":"558237","messageId":"CAOLa=ZShhVC=7uYs4_CP6pUSuiYziQrbN8EbJhpqYToixPV-VA@mail.gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-5-jltobler@gmail.com","subject":"Re: [PATCH 4/4] object-file: create ODB transaction temporary directory eagerly","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-11-11T16:48:30Z","receivedAt":"2026-11-11T16:48:30Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Justin Tobler <jltobler@gmail.com> writes:\n\n> By default, ODB transactions for the \"files\" backend create their\n> temporary object directory lazily once the first loose object is about\n> to be written, and only if batched fsync is enabled. Transactions\n> configured for git-receive-pack(1) are the exception as the directory is\n> needed to quarantine incoming objects up front. Lazily creating the\n> temporary directory in this manner is awkward for a couple of reasons:\n>\n>   - Writing loose objects has to know about the transaction internals to\n>     trigger the lazy creation of the temporary object directory.\n>\n>   - Whether objects are staged in a temporary object directory, and thus\n>     whether they become visible at once on commit, depends on the\n>     configured fsync method.\n>\n> Create the temporary object directory eagerly for every transaction when\n> it is started instead. This also ensures that no object is written to\n> the main object database before the transaction is committed.\n>\n> Note that committing a transaction migrates every written object into\n> the primary object directory even when batched fsync is disabled. This\n> adds some minor overhead to ODB transaction callers that previously only\n> used a temporary directory if batched fsync was enabled. The following\n> benchmark uses the default fsync configuration and adds 10000 files of 4\n> KiB each to a freshly initialized repository via git-add(1):\n>\n>   Benchmark 1: git add . (rev = HEAD~)\n>     Time (mean ± σ):     895.0 ms ±  23.8 ms    [User: 545.3 ms, System: 340.7 ms]\n>     Range (min … max):   866.7 ms … 928.7 ms    20 runs\n>\n>   Benchmark 2: git add . (rev = HEAD)\n>     Time (mean ± σ):     956.3 ms ±  26.1 ms    [User: 541.4 ms, System: 405.2 ms]\n>     Range (min … max):   923.9 ms … 993.6 ms    20 runs\n>\n>   Summary\n>     git add . (rev = HEAD~) ran\n>       1.07 ± 0.04 times faster than git add . (rev = HEAD)\n>\n\nThe explanation hre is well written and nicely explains what the cover\nletter didn't _cover_. Nice.\n\n> Typically large numbers of loose objects are not expected to be written\n> into an ODB transaction so the overhead here should be marginal.\n>\n\nQuestion: why is that?\n\n> Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> ---\n>  object-file.c         | 56 +++++++++----------------------------------\n>  object-file.h         |  1 -\n>  odb/source-loose.c    |  6 -----\n>  t/t0004-unwritable.sh | 19 +++++++--------\n>  4 files changed, 19 insertions(+), 63 deletions(-)\n\nThe changes itself looks good.\n"},{"id":"558664","messageId":"avzghl3FBW3TTWhV@denethor","threadId":"66818","inReplyTo":"avRqlHdN83O67HB1@pks.im","subject":"Re: [PATCH 2/4] object-file: only flush batched fsync writes when enabled","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-17T23:35:44Z","receivedAt":"2026-11-17T23:35:44Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/11 02:16PM, Patrick Steinhardt wrote:\n> On Mon, Nov 09, 2026 at 06:22:49PM -0600, Justin Tobler wrote:\n> > When committing an ODB transaction for the \"files\" backend, a full\n> > hardware flush is issued against a temporary file before the staged\n> > objects are migrated into the main object database. This flush acts as a\n> > barrier for objects that have been written with batched fsync, where\n> > `odb_transaction_files_fsync()` only issues a writeout request for each\n> > object instead of fully syncing it.\n> \n> Hmm, okay. The difference here is bascially that we don't issue a\n> hardware flush. So we know that the data is not in the page cache\n> anymore, but it may still only be cached by the disk.\n\nPerforming the hardware sync here is really only intended for batch fsync \n\nRight, that's what writeout-only gives us for each object with batched\nfsync, and why the single hardware flush at commit time is needed as a\nbarrier.\n\nThat state only arises with batched fsync though. Otherwise, objects are\neither fully synced individually, in which case they are already durable\nand the extra flush is redundant, or not synced at all, in which case\nthere is nothing to make durable. So the flush is only useful if there\nwere writeout-only syncs.\n\n> > The flush is issued whenever the transaction has a temporary object\n> > directory though, regardless of whether batched fsync is actually\n> > enabled. For transactions configured for git-receive-pack(1), the\n> > temporary object directory is always created, so the flush is also\n> > performed when objects are synced individually or not synced at all. In\n> > those cases there are no pending writeout requests and the flush is\n> > unnecessary. Only issue the flush when batched fsync is enabled\n> > accordingly.\n> \n> So this is essentially a performance optimization?\n\nYes and I also think its not really the correct behavior. Even is fsync\nis disabled, the fsync here happens. It doesn't really harm anything,\nbut I think it makes sense to address as we begin to roll out\ntransactions more widely.\n\n[snip]\n> I assume that we only support batched fsyncs for loose objects in the\n> first place? In other words, if a transaction were to write a bunch of\n> packfiles, it would not be possible to batch-fsync those right now?\n\nCorrect, this mechanism was intended to batch fsync loose objects.\n\n> If so this new condition correct to me. But I think this should be\n> documented as part of the commit message, because it's an implicit\n> assumption.\n\nMakes sense. I'll update the commit message in the next version.\n\nThanks,\n-Justin\n\n"},{"id":"558665","messageId":"avzlrYKsGIbyMz8r@denethor","threadId":"66818","inReplyTo":"CAOLa=ZRp=JeAGhN3m6-RCos3F82__6Wzt2UsKvUjqHSHUg6o_Q@mail.gmail.com","subject":"Re: [PATCH 2/4] object-file: only flush batched fsync writes when enabled","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-17T23:42:59Z","receivedAt":"2026-11-17T23:42:59Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/11 06:48AM, Karthik Nayak wrote:\n> Justin Tobler <jltobler@gmail.com> writes:\n> \n> > When committing an ODB transaction for the \"files\" backend, a full\n> > hardware flush is issued against a temporary file before the staged\n> > objects are migrated into the main object database. This flush acts as a\n> > barrier for objects that have been written with batched fsync, where\n> > `odb_transaction_files_fsync()` only issues a writeout request for each\n> > object instead of fully syncing it.\n> >\n> \n> Does `fsync(fd)` even guarantee syncing of previous writes?\n\nI believe the answer here is platform specific. This feature oringally\ncomes from c0f4752ed2 (core.fsyncmethod: batched disk flushes for\nloose-objects, 2022-04-04) which has a pretty good explaination. :)\n\n> > The flush is issued whenever the transaction has a temporary object\n> > directory though, regardless of whether batched fsync is actually\n> > enabled. For transactions configured for git-receive-pack(1), the\n> > temporary object directory is always created, so the flush is also\n> > performed when objects are synced individually or not synced at all. In\n> > those cases there are no pending writeout requests and the flush is\n> > unnecessary. Only issue the flush when batched fsync is enabled\n> > accordingly.\n> >\n> > Signed-off-by: Justin Tobler <jltobler@gmail.com>\n> > ---\n> >  object-file.c | 43 +++++++++++++++++++++++++------------------\n> >  1 file changed, 25 insertions(+), 18 deletions(-)\n> >\n> > diff --git a/object-file.c b/object-file.c\n> > index 201d9d6490..da189111bd 100644\n> > --- a/object-file.c\n> > +++ b/object-file.c\n> > @@ -1330,6 +1330,29 @@ static int write_pack_lockfiles(struct odb_transaction_files *transaction)\n> >  \treturn ret;\n> >  }\n> >\n> > +static void flush_batched_fsync(struct repository *repo)\n> > +{\n> > +\tstruct strbuf temp_path = STRBUF_INIT;\n> > +\tstruct tempfile *temp;\n> > +\n> > +\t/*\n> > +\t * Issue a full hardware flush against a temporary file to ensure\n> > +\t * that all objects are durable before any renames occur. The code in\n> > +\t * odb_transaction_files_fsync has already issued a writeout\n> > +\t * request, but it has not flushed any writeback cache in the storage\n> > +\t * hardware or any filesystem logs. This fsync call acts as a barrier\n> > +\t * to ensure that the data in each new object file is durable before\n> > +\t * the final name is visible.\n> > +\t */\n> \n> Nit: This could become a function comment, since it now describes the\n> function well.\n\nWill do in the next version.\n\n-Justin\n\n"},{"id":"558666","messageId":"avznJsg7cB8NsP97@denethor","threadId":"66818","inReplyTo":"CAOLa=ZSonhP78j2sJdTwctp2h101jWZbvU_jcg1_TR41cRK7dA@mail.gmail.com","subject":"Re: [PATCH 3/4] tmp-objdir: preserve errno when directory creation fails","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-17T23:46:25Z","receivedAt":"2026-11-17T23:46:25Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/11 08:44AM, Karthik Nayak wrote:\n> This avoids having to care about other syscalls which may be added in\n> the future and breaking our setup as done in the patch here.\n\nI think the suggestion here is fair. Will use in the next version.\n\nThanks,\n-Justin\n\n"},{"id":"558667","messageId":"avznZz5351gjqPVQ@denethor","threadId":"66818","inReplyTo":"avRqiH9eIpJUGKMo@pks.im","subject":"Re: [PATCH 4/4] object-file: create ODB transaction temporary directory eagerly","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-17T23:48:23Z","receivedAt":"2026-11-17T23:48:23Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/11 02:15PM, Patrick Steinhardt wrote:\n> On Mon, Nov 09, 2026 at 06:22:51PM -0600, Justin Tobler wrote:\n> > +\tprefix = flags & ODB_TRANSACTION_RECEIVE ? \"incoming\" : \"transaction\";\n> \n> Makes me wonder whether it's important to keep the \"incoming\" prefix\n> here or whether there is an argument to be made that it should simply be\n> called \"transaction\", as well.\n> \n> That may be out of scope for this series though.\n\nYa, this is something I would also like to change, but I decided to\nleave it for a future series. :)\n\n[snip]\n> > diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh\n> > index 3bdafbae0f..7292672a66 100755\n> > --- a/t/t0004-unwritable.sh\n> > +++ b/t/t0004-unwritable.sh\n> > @@ -24,8 +24,8 @@ test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable reposi\n> >  test_lazy_prereq WRITE_TREE_OUT 'test -e \"$TRASH_DIRECTORY\"/out.write-tree'\n> >  test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '\n> >  \tcat >expect <<-\\EOF &&\n> > -\terror: insufficient permission for adding an object to repository database .git/objects\n> > -\tfatal: git-write-tree: error building trees\n> > +\terror: unable to create temporary object directory in .git/objects: Permission denied\n> > +\tfatal: failed to start ODB transaction\n> \n> Not a new issue, but this second error message is awful. An average user\n> won't have any idea what an \"ODB\" even is. s/ODB/object/ would make a\n> lot more sense.\n\nI agree. I'll add another small patch in the next version that changes\nthis.\n\n-Justin\n\n"},{"id":"558669","messageId":"avzn-Zz5-h1haIEq@denethor","threadId":"66818","inReplyTo":"CAOLa=ZShhVC=7uYs4_CP6pUSuiYziQrbN8EbJhpqYToixPV-VA@mail.gmail.com","subject":"Re: [PATCH 4/4] object-file: create ODB transaction temporary directory eagerly","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-17T23:57:48Z","receivedAt":"2026-11-17T23:57:48Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/11/11 08:48AM, Karthik Nayak wrote:\n> Justin Tobler <jltobler@gmail.com> writes:\n> \n> > Typically large numbers of loose objects are not expected to be written\n> > into an ODB transaction so the overhead here should be marginal.\n> \n> Question: why is that?\n\nLoose objects are only written to a transaction if the number of objects\nin the incoming packfile are below the unpack limit (default 100\nobjects) or by objects being added. Of course it is possible that a user\ncould add a new tree with a large number of objects for the first time\nthough. There real point here though is that the overhead here is per\nobject and small in comparison to the cost of writting the object in the\nfirst place. In most cases, I wouldn't expect it to be noticed. I'll try\nto update the message here to be a bit more clear.\n\n-Justin\n\n"},{"id":"558772","messageId":"20261119002043.2108654-1-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261110002251.2007617-1-jltobler@gmail.com","subject":"[PATCH v2 0/6] object-file: eagerly create ODB transaction temporary directory","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:37Z","receivedAt":"2026-11-19T00:20:37Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"Greetings,\n\nThis series continues work for the \"files\" ODB transactions and makes it\nso the underlying transaction temporary directory is created eagerly.\nPreviously, by default, it would wait for the first object write to\nlazily create the temporary object directory, and only did so if batched\nfsync was configured. This lazy setup is awkward for a couple of\nreasons. Writing loose objects has to know about transaction internals\nto trigger the creation of the temporary directory, and whether objects\nwritten in a transaction become visible at once on commit depends on the\nconfigured fsync method. Creating the temporary directory eagerly\nremoves both of these special cases and ensures that objects are written\nto the temporary directory for all transactional object writes.\n\nThe first five patches consist of some minor preparatory refactors. The\nfinal patch swaps to creating the temporary directory eagerly and drops\nthe lazy setup.\n\nChanges since v1:\n  - Moved the comment for `flush_batched_fsync()` above the function and\n    documented that batch fsync only applies to loose objects.\n  - Added a new patch that inlines `setup_tmp_objdir()` into\n    `tmp_objdir_create()`, which now restores `errno` ina  single exit path.\n  - Added a new patch that avoids the \"ODB\" term in user-facing error\n    messages.\n  - Clarified some commit messages.\n\nThis series is based on 3c60ef1e38 (The 17th batch, 2026-11-08) with\njt/tmp-objdir-loose-idx-merge merged into it.\n\nThanks,\n-Justin\n\nJustin Tobler (6):\n  object-file: rename default transaction prefix\n  object-file: only flush batched fsync writes when enabled\n  tmp-objdir: inline `setup_tmp_objdir()`\n  tmp-objdir: preserve errno when directory creation fails\n  odb/transaction: avoid \"ODB\" in error messages\n  object-file: create ODB transaction temporary directory eagerly\n\n object-file.c         | 98 ++++++++++++++++---------------------------\n object-file.h         |  1 -\n odb/source-loose.c    |  6 ---\n odb/transaction.h     |  6 +--\n t/t0004-unwritable.sh | 19 ++++-----\n tmp-objdir.c          | 30 ++++++-------\n tmp-objdir.h          |  3 +-\n 7 files changed, 63 insertions(+), 100 deletions(-)\n\nRange-diff against v1:\n1:  eb3679a4ea = 1:  eb3679a4ea object-file: rename default transaction prefix\n2:  392893af4e ! 2:  e2fb4b4833 object-file: only flush batched fsync writes when enabled\n    @@ Commit message\n         unnecessary. Only issue the flush when batched fsync is enabled\n         accordingly.\n     \n    +    Note that batched fsync only applies to loose objects. Other files\n    +    written as part of the transaction, such as packfiles, are fully synced\n    +    when written or not synced at all, and thus do not rely on this flush.\n    +\n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n      ## object-file.c ##\n    @@ object-file.c: static int write_pack_lockfiles(struct odb_transaction_files *tra\n      \treturn ret;\n      }\n      \n    ++/*\n    ++ * Issue a full hardware flush against a temporary file to ensure that all\n    ++ * objects are durable before any renames occur. The code in\n    ++ * odb_transaction_files_fsync has already issued a writeout request, but it has\n    ++ * not flushed any writeback cache in the storage hardware or any filesystem\n    ++ * logs. This fsync call acts as a barrier to ensure that the data in each new\n    ++ * object file is durable before the final name is visible.\n    ++ */\n     +static void flush_batched_fsync(struct repository *repo)\n     +{\n     +\tstruct strbuf temp_path = STRBUF_INIT;\n     +\tstruct tempfile *temp;\n     +\n    -+\t/*\n    -+\t * Issue a full hardware flush against a temporary file to ensure\n    -+\t * that all objects are durable before any renames occur. The code in\n    -+\t * odb_transaction_files_fsync has already issued a writeout\n    -+\t * request, but it has not flushed any writeback cache in the storage\n    -+\t * hardware or any filesystem logs. This fsync call acts as a barrier\n    -+\t * to ensure that the data in each new object file is durable before\n    -+\t * the final name is visible.\n    -+\t */\n     +\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n     +\t\t    repo_get_object_directory(repo));\n     +\ttemp = xmks_tempfile(temp_path.buf);\n-:  ---------- > 3:  ae6548cd8f tmp-objdir: inline `setup_tmp_objdir()`\n3:  ede4bc8aa1 ! 4:  f013767e55 tmp-objdir: preserve errno when directory creation fails\n    @@ Commit message\n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n      ## tmp-objdir.c ##\n    -@@ tmp-objdir.c: static int setup_tmp_objdir(const char *root)\n    - {\n    - \tchar *path;\n    - \tint ret = 0;\n    -+\tint saved_errno;\n    - \n    - \tpath = xstrfmt(\"%s/pack\", root);\n    - \tret = mkdir(path, 0777);\n    -+\tsaved_errno = errno;\n    - \tfree(path);\n    -+\terrno = saved_errno;\n    - \n    - \treturn ret;\n    - }\n     @@ tmp-objdir.c: struct tmp_objdir *tmp_objdir_create(struct repository *r,\n      \tstruct odb_source_files *files = odb_source_files_downcast(r->objects->source);\n      \tstatic int installed_handlers;\n      \tstruct tmp_objdir *t;\n     +\tint saved_errno;\n    + \tchar *path;\n    + \tint ret;\n      \n    - \tif (the_tmp_objdir)\n    - \t\tBUG(\"only one tmp_objdir can be used at a time\");\n     @@ tmp-objdir.c: struct tmp_objdir *tmp_objdir_create(struct repository *r,\n      \t\tchdir_notify_register(tmp_objdir_reparent, t);\n      \n    @@ tmp-objdir.c: struct tmp_objdir *tmp_objdir_create(struct repository *r,\n     +\t\tsaved_errno = errno;\n      \t\t/* free, not destroy, as we never touched the filesystem */\n      \t\ttmp_objdir_free(t);\n    -+\t\terrno = saved_errno;\n    - \t\treturn NULL;\n    +-\t\treturn NULL;\n    ++\t\tgoto error;\n      \t}\n      \n    + \tthe_tmp_objdir = t;\n     @@ tmp-objdir.c: struct tmp_objdir *tmp_objdir_create(struct repository *r,\n    - \t}\n      \n    - \tif (setup_tmp_objdir(t->path.buf)) {\n    -+\t\tsaved_errno = errno;\n    + \tpath = xstrfmt(\"%s/pack\", t->path.buf);\n    + \tret = mkdir(path, 0777);\n    ++\tsaved_errno = errno;\n    + \tfree(path);\n    + \tif (ret) {\n      \t\ttmp_objdir_destroy(t);\n    -+\t\terrno = saved_errno;\n    - \t\treturn NULL;\n    +-\t\treturn NULL;\n    ++\t\tgoto error;\n      \t}\n      \n    + \tenv_append(&t->env, ALTERNATE_DB_ENVIRONMENT,\n    +@@ tmp-objdir.c: struct tmp_objdir *tmp_objdir_create(struct repository *r,\n    + \tt->repo->disable_ref_updates = true;\n    + \n    + \treturn t;\n    ++\n    ++error:\n    ++\terrno = saved_errno;\n    ++\treturn NULL;\n    + }\n    + \n    + /*\n     \n      ## tmp-objdir.h ##\n     @@ tmp-objdir.h: struct tmp_objdir;\n-:  ---------- > 5:  66eaf498e9 odb/transaction: avoid \"ODB\" in error messages\n4:  dd36ba0fb7 ! 6:  6d2266ad20 object-file: create ODB transaction temporary directory eagerly\n    @@ Commit message\n             git add . (rev = HEAD~) ran\n               1.07 ± 0.04 times faster than git add . (rev = HEAD)\n     \n    -    Typically large numbers of loose objects are not expected to be written\n    -    into an ODB transaction so the overhead here should be marginal.\n    +    The overhead is a small fixed cost per object for migrating it into the\n    +    primary object directory, which is minor compared to the cost of writing\n    +    the object in the first place. It is most visible when adding many small\n    +    files at once, as in the benchmark above. Otherwise, transactions\n    +    typically write only a few loose objects, for example when unpacking a\n    +    pushed packfile with fewer objects than the unpack limit. So the\n    +    overhead is not expected to be noticeable in most cases.\n     \n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n    @@ t/t0004-unwritable.sh: test_expect_success POSIXPERM,SANITY 'write-tree should n\n     -\terror: insufficient permission for adding an object to repository database .git/objects\n     -\tfatal: git-write-tree: error building trees\n     +\terror: unable to create temporary object directory in .git/objects: Permission denied\n    -+\tfatal: failed to start ODB transaction\n    ++\tfatal: failed to start object transaction\n      \tEOF\n      \ttest_cmp expect out.write-tree\n      '\n    @@ t/t0004-unwritable.sh: test_expect_success POSIXPERM,SANITY 'commit should notic\n     -\terror: insufficient permission for adding an object to repository database .git/objects\n     -\terror: Error building trees\n     +\terror: unable to create temporary object directory in .git/objects: Permission denied\n    -+\tfatal: failed to start ODB transaction\n    ++\tfatal: failed to start object transaction\n      \tEOF\n      \ttest_cmp expect out.commit\n      '\n    @@ t/t0004-unwritable.sh: test_expect_success POSIXPERM,SANITY 'update-index should\n     -\terror: file: failed to insert into database\n     -\tfatal: Unable to process path file\n     +\terror: unable to create temporary object directory in .git/objects: Permission denied\n    -+\tfatal: failed to start ODB transaction\n    ++\tfatal: failed to start object transaction\n      \tEOF\n      \ttest_cmp expect out.update-index\n      '\n    @@ t/t0004-unwritable.sh: test_expect_success POSIXPERM,SANITY 'add should notice u\n     -\terror: unable to index file '\\''file'\\''\n     -\tfatal: updating files failed\n     +\terror: unable to create temporary object directory in .git/objects: Permission denied\n    -+\tfatal: failed to start ODB transaction\n    ++\tfatal: failed to start object transaction\n      \tEOF\n      \ttest_cmp expect out.add\n      '\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558773","messageId":"20261119002043.2108654-2-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 1/6] object-file: rename default transaction prefix","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:38Z","receivedAt":"2026-11-19T00:20:38Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"By default, the temporary directory created for a \"files\" ODB\ntransaction has its name prefixed with \"bulk-fsync\". This name dates\nback to c0f4752ed2 (core.fsyncmethod: batched disk flushes for\nloose-objects, 2022-04-04), where the temporary object directory only\nserved to batch fsyncs of loose objects.\n\nODB transactions have since grown into a more general interface for\nwriting objects though, and the temporary object directory is not\ninherently tied to how objects are synced. In a subsequent commit, the\ntemporary object directory is created for every transaction regardless\nof the configured fsync method, which would make the name misleading.\n\nRename the default prefix to \"transaction\" accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 132aaab6f8..201d9d6490 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -1566,7 +1566,7 @@ int odb_transaction_files_begin(struct odb_source *source,\n \ttransaction->flags = flags;\n \tstrvec_init(&transaction->pack_names);\n \n-\ttransaction->prefix = \"bulk-fsync\";\n+\ttransaction->prefix = \"transaction\";\n \tif (flags & ODB_TRANSACTION_RECEIVE) {\n \t\t/*\n \t\t * ODB transactions for git-receive-pack(1) eagerly create a\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558774","messageId":"20261119002043.2108654-3-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 2/6] object-file: only flush batched fsync writes when enabled","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:39Z","receivedAt":"2026-11-19T00:20:39Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When committing an ODB transaction for the \"files\" backend, a full\nhardware flush is issued against a temporary file before the staged\nobjects are migrated into the main object database. This flush acts as a\nbarrier for objects that have been written with batched fsync, where\n`odb_transaction_files_fsync()` only issues a writeout request for each\nobject instead of fully syncing it.\n\nThe flush is issued whenever the transaction has a temporary object\ndirectory though, regardless of whether batched fsync is actually\nenabled. For transactions configured for git-receive-pack(1), the\ntemporary object directory is always created, so the flush is also\nperformed when objects are synced individually or not synced at all. In\nthose cases there are no pending writeout requests and the flush is\nunnecessary. Only issue the flush when batched fsync is enabled\naccordingly.\n\nNote that batched fsync only applies to loose objects. Other files\nwritten as part of the transaction, such as packfiles, are fully synced\nwhen written or not synced at all, and thus do not rely on this flush.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c | 42 ++++++++++++++++++++++++------------------\n 1 file changed, 24 insertions(+), 18 deletions(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 201d9d6490..1926f61f53 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -1330,6 +1330,28 @@ static int write_pack_lockfiles(struct odb_transaction_files *transaction)\n \treturn ret;\n }\n \n+/*\n+ * Issue a full hardware flush against a temporary file to ensure that all\n+ * objects are durable before any renames occur. The code in\n+ * odb_transaction_files_fsync has already issued a writeout request, but it has\n+ * not flushed any writeback cache in the storage hardware or any filesystem\n+ * logs. This fsync call acts as a barrier to ensure that the data in each new\n+ * object file is durable before the final name is visible.\n+ */\n+static void flush_batched_fsync(struct repository *repo)\n+{\n+\tstruct strbuf temp_path = STRBUF_INIT;\n+\tstruct tempfile *temp;\n+\n+\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n+\t\t    repo_get_object_directory(repo));\n+\ttemp = xmks_tempfile(temp_path.buf);\n+\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n+\n+\tstrbuf_release(&temp_path);\n+\tdelete_tempfile(&temp);\n+}\n+\n static int odb_transaction_files_commit(struct odb_transaction *base)\n {\n \tstruct odb_transaction_files *transaction =\n@@ -1339,24 +1361,8 @@ static int odb_transaction_files_commit(struct odb_transaction *base)\n \tflush_packfile_transaction(transaction);\n \n \tif (transaction->objdir) {\n-\t\tstruct strbuf temp_path = STRBUF_INIT;\n-\t\tstruct tempfile *temp;\n-\n-\t\t/*\n-\t\t * Issue a full hardware flush against a temporary file to ensure\n-\t\t * that all objects are durable before any renames occur. The code in\n-\t\t * odb_transaction_files_fsync has already issued a writeout\n-\t\t * request, but it has not flushed any writeback cache in the storage\n-\t\t * hardware or any filesystem logs. This fsync call acts as a barrier\n-\t\t * to ensure that the data in each new object file is durable before\n-\t\t * the final name is visible.\n-\t\t */\n-\t\tstrbuf_addf(&temp_path, \"%s/bulk_fsync_XXXXXX\",\n-\t\t\t    repo_get_object_directory(transaction->base.source->odb->repo));\n-\t\ttemp = xmks_tempfile(temp_path.buf);\n-\t\tfsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));\n-\t\tdelete_tempfile(&temp);\n-\t\tstrbuf_release(&temp_path);\n+\t\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n+\t\t\tflush_batched_fsync(transaction->base.source->odb->repo);\n \n \t\tif (write_pack_lockfiles(transaction))\n \t\t\treturn error(_(\"unable to lock packfiles\"));\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558775","messageId":"20261119002043.2108654-4-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 3/6] tmp-objdir: inline `setup_tmp_objdir()`","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:40Z","receivedAt":"2026-11-19T00:20:40Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"In a subsequent commit, `tmp_objdir_create()` is updated to preserve\n`errno` when it fails to create the temporary object directory. In\npreparation for this change, inline `setup_tmp_objdir()` into its only\ncaller so `errno` only has to be preserved in the single function.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n tmp-objdir.c | 19 ++++++-------------\n 1 file changed, 6 insertions(+), 13 deletions(-)\n\ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex 5307717354..c78fc0e6b6 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -144,18 +144,6 @@ static void env_replace(struct strvec *env, const char *key, const char *val)\n \tstrvec_pushf(env, \"%s=%s\", key, val);\n }\n \n-static int setup_tmp_objdir(const char *root)\n-{\n-\tchar *path;\n-\tint ret = 0;\n-\n-\tpath = xstrfmt(\"%s/pack\", root);\n-\tret = mkdir(path, 0777);\n-\tfree(path);\n-\n-\treturn ret;\n-}\n-\n struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\t\t\t     const char *prefix,\n \t\t\t\t     int will_destroy)\n@@ -163,6 +151,8 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tstruct odb_source_files *files = odb_source_files_downcast(r->objects->source);\n \tstatic int installed_handlers;\n \tstruct tmp_objdir *t;\n+\tchar *path;\n+\tint ret;\n \n \tif (the_tmp_objdir)\n \t\tBUG(\"only one tmp_objdir can be used at a time\");\n@@ -196,7 +186,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\tinstalled_handlers++;\n \t}\n \n-\tif (setup_tmp_objdir(t->path.buf)) {\n+\tpath = xstrfmt(\"%s/pack\", t->path.buf);\n+\tret = mkdir(path, 0777);\n+\tfree(path);\n+\tif (ret) {\n \t\ttmp_objdir_destroy(t);\n \t\treturn NULL;\n \t}\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558776","messageId":"20261119002043.2108654-5-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 4/6] tmp-objdir: preserve errno when directory creation fails","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:41Z","receivedAt":"2026-11-19T00:20:41Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When `tmp_objdir_create()` fails to create the temporary object\ndirectory, it cleans up after itself before returning NULL. Depending on\nwhere the failure occurred, this cleanup may clobber `errno`, leaving\ncallers without a way to reliably tell why creating the directory\nfailed.\n\nIn a subsequent commit, ODB transactions create their temporary object\ndirectory eagerly and report a more specific error regarding creation\nfailure. Preserve `errno` across the cleanup so that callers can inspect\nit accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n tmp-objdir.c | 11 +++++++++--\n tmp-objdir.h |  3 ++-\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/tmp-objdir.c b/tmp-objdir.c\nindex c78fc0e6b6..c3549c2e8d 100644\n--- a/tmp-objdir.c\n+++ b/tmp-objdir.c\n@@ -151,6 +151,7 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tstruct odb_source_files *files = odb_source_files_downcast(r->objects->source);\n \tstatic int installed_handlers;\n \tstruct tmp_objdir *t;\n+\tint saved_errno;\n \tchar *path;\n \tint ret;\n \n@@ -175,9 +176,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \t\tchdir_notify_register(tmp_objdir_reparent, t);\n \n \tif (!mkdtemp(t->path.buf)) {\n+\t\tsaved_errno = errno;\n \t\t/* free, not destroy, as we never touched the filesystem */\n \t\ttmp_objdir_free(t);\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n \n \tthe_tmp_objdir = t;\n@@ -188,10 +190,11 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \n \tpath = xstrfmt(\"%s/pack\", t->path.buf);\n \tret = mkdir(path, 0777);\n+\tsaved_errno = errno;\n \tfree(path);\n \tif (ret) {\n \t\ttmp_objdir_destroy(t);\n-\t\treturn NULL;\n+\t\tgoto error;\n \t}\n \n \tenv_append(&t->env, ALTERNATE_DB_ENVIRONMENT,\n@@ -214,6 +217,10 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,\n \tt->repo->disable_ref_updates = true;\n \n \treturn t;\n+\n+error:\n+\terrno = saved_errno;\n+\treturn NULL;\n }\n \n /*\ndiff --git a/tmp-objdir.h b/tmp-objdir.h\nindex a301b01d84..4ef6750a01 100644\n--- a/tmp-objdir.h\n+++ b/tmp-objdir.h\n@@ -26,7 +26,8 @@ struct tmp_objdir;\n \n /*\n  * Create a new temporary object directory with the specified prefix and\n- * install the directory as the primary write target; returns NULL on failure.\n+ * install the directory as the primary write target; returns NULL and sets\n+ * errno on failure.\n  */\n struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix,\n \t\t\t\t     int will_destroy);\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558777","messageId":"20261119002043.2108654-6-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 5/6] odb/transaction: avoid \"ODB\" in error messages","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:42Z","receivedAt":"2026-11-19T00:20:42Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When starting, committing, or finalizing an ODB transaction fails, the\n`odb_transaction_begin_or_die()` and\n`odb_transaction_commit_and_finalize_or_die()` helpers die with a\nmessage referring to an \"ODB transaction\". The term \"ODB\" is unlikely to\nbe understood by the average user though.\n\nRefer to an \"object transaction\" in these messages instead.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n odb/transaction.h | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/odb/transaction.h b/odb/transaction.h\nindex 2a40c85bc8..f6c4b523cd 100644\n--- a/odb/transaction.h\n+++ b/odb/transaction.h\n@@ -125,7 +125,7 @@ static inline void odb_transaction_begin_or_die(struct object_database *odb,\n \t\t\t\t\t\tenum odb_transaction_flags flags)\n {\n \tif (odb_transaction_begin(odb, out, flags))\n-\t\tdie(_(\"failed to start ODB transaction\"));\n+\t\tdie(_(\"failed to start object transaction\"));\n }\n \n /*\n@@ -146,9 +146,9 @@ int odb_transaction_finalize(struct odb_transaction *transaction);\n static inline void odb_transaction_commit_and_finalize_or_die(struct odb_transaction *transaction)\n {\n \tif (odb_transaction_commit(transaction))\n-\t\tdie(_(\"failed to commit ODB transaction\"));\n+\t\tdie(_(\"failed to commit object transaction\"));\n \tif (odb_transaction_finalize(transaction))\n-\t\tdie(_(\"failed to finalize ODB transaction\"));\n+\t\tdie(_(\"failed to finalize object transaction\"));\n }\n \n /*\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558778","messageId":"20261119002043.2108654-7-jltobler@gmail.com","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"[PATCH v2 6/6] object-file: create ODB transaction temporary directory eagerly","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-19T00:20:43Z","receivedAt":"2026-11-19T00:20:43Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"By default, ODB transactions for the \"files\" backend create their\ntemporary object directory lazily once the first loose object is about\nto be written, and only if batched fsync is enabled. Transactions\nconfigured for git-receive-pack(1) are the exception as the directory is\nneeded to quarantine incoming objects up front. Lazily creating the\ntemporary directory in this manner is awkward for a couple of reasons:\n\n  - Writing loose objects has to know about the transaction internals to\n    trigger the lazy creation of the temporary object directory.\n\n  - Whether objects are staged in a temporary object directory, and thus\n    whether they become visible at once on commit, depends on the\n    configured fsync method.\n\nCreate the temporary object directory eagerly for every transaction when\nit is started instead. This also ensures that no object is written to\nthe main object database before the transaction is committed.\n\nNote that committing a transaction migrates every written object into\nthe primary object directory even when batched fsync is disabled. This\nadds some minor overhead to ODB transaction callers that previously only\nused a temporary directory if batched fsync was enabled. The following\nbenchmark uses the default fsync configuration and adds 10000 files of 4\nKiB each to a freshly initialized repository via git-add(1):\n\n  Benchmark 1: git add . (rev = HEAD~)\n    Time (mean ± σ):     895.0 ms ±  23.8 ms    [User: 545.3 ms, System: 340.7 ms]\n    Range (min … max):   866.7 ms … 928.7 ms    20 runs\n\n  Benchmark 2: git add . (rev = HEAD)\n    Time (mean ± σ):     956.3 ms ±  26.1 ms    [User: 541.4 ms, System: 405.2 ms]\n    Range (min … max):   923.9 ms … 993.6 ms    20 runs\n\n  Summary\n    git add . (rev = HEAD~) ran\n      1.07 ± 0.04 times faster than git add . (rev = HEAD)\n\nThe overhead is a small fixed cost per object for migrating it into the\nprimary object directory, which is minor compared to the cost of writing\nthe object in the first place. It is most visible when adding many small\nfiles at once, as in the benchmark above. Otherwise, transactions\ntypically write only a few loose objects, for example when unpacking a\npushed packfile with fewer objects than the unpack limit. So the\noverhead is not expected to be noticeable in most cases.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n object-file.c         | 56 +++++++++----------------------------------\n object-file.h         |  1 -\n odb/source-loose.c    |  6 -----\n t/t0004-unwritable.sh | 19 +++++++--------\n 4 files changed, 19 insertions(+), 63 deletions(-)\n\ndiff --git a/object-file.c b/object-file.c\nindex 1926f61f53..8af9b0975a 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -489,7 +489,6 @@ struct odb_transaction_files {\n \n \tstruct tmp_objdir *objdir;\n \tstruct transaction_packfile packfile;\n-\tconst char *prefix;\n \n \tstruct strvec pack_names;\n \tstruct tempfile **pack_lockfiles;\n@@ -497,27 +496,6 @@ struct odb_transaction_files {\n \tsize_t pack_lockfiles_alloc;\n };\n \n-int odb_transaction_files_prepare(struct odb_transaction *base)\n-{\n-\tstruct odb_transaction_files *transaction =\n-\t\tcontainer_of_or_null(base, struct odb_transaction_files, base);\n-\n-\t/*\n-\t * We lazily create the temporary object directory\n-\t * the first time an object might be added, since\n-\t * callers may not know whether any objects will be\n-\t * added at the time they call odb_transaction_files_begin.\n-\t */\n-\tif (!transaction || transaction->objdir)\n-\t\treturn 0;\n-\n-\ttransaction->objdir = tmp_objdir_create(base->source->odb->repo, transaction->prefix, 0);\n-\tif (!transaction->objdir)\n-\t\treturn error(_(\"unable to create temporary object directory\"));\n-\n-\treturn 0;\n-}\n-\n void odb_transaction_files_fsync(struct odb_transaction *base,\n \t\t\t\t int fd, const char *filename)\n {\n@@ -1547,13 +1525,10 @@ static int odb_transaction_files_env(struct odb_transaction *base,\n {\n \tstruct odb_transaction_files *transaction =\n \t\tcontainer_of(base, struct odb_transaction_files, base);\n-\tint ret;\n \n-\tret = odb_transaction_files_prepare(&transaction->base);\n-\tif (!ret)\n-\t\tstrvec_pushv(env, tmp_objdir_env(transaction->objdir));\n+\tstrvec_pushv(env, tmp_objdir_env(transaction->objdir));\n \n-\treturn ret;\n+\treturn 0;\n }\n \n int odb_transaction_files_begin(struct odb_source *source,\n@@ -1561,6 +1536,8 @@ int odb_transaction_files_begin(struct odb_source *source,\n \t\t\t\tenum odb_transaction_flags flags)\n {\n \tstruct odb_transaction_files *transaction;\n+\tconst char *prefix;\n+\tint ret;\n \n \ttransaction = xcalloc(1, sizeof(*transaction));\n \ttransaction->base.source = source;\n@@ -1572,24 +1549,13 @@ int odb_transaction_files_begin(struct odb_source *source,\n \ttransaction->flags = flags;\n \tstrvec_init(&transaction->pack_names);\n \n-\ttransaction->prefix = \"transaction\";\n-\tif (flags & ODB_TRANSACTION_RECEIVE) {\n-\t\t/*\n-\t\t * ODB transactions for git-receive-pack(1) eagerly create a\n-\t\t * temporary directory and use a different temporary directory\n-\t\t * prefix.\n-\t\t *\n-\t\t * NEEDSWORK: This transaction flag is only used by the \"files\"\n-\t\t * backend to special case temporary directory set up and\n-\t\t * handling. Ideally transaction users should not have to care\n-\t\t * though. To avoid this, we could eagerly create the temporary\n-\t\t * directory and use the same prefix name for all transactions.\n-\t\t */\n-\t\ttransaction->prefix = \"incoming\";\n-\t\tif (odb_transaction_files_prepare(&transaction->base)) {\n-\t\t\tfree(transaction);\n-\t\t\treturn -1;\n-\t\t}\n+\tprefix = flags & ODB_TRANSACTION_RECEIVE ? \"incoming\" : \"transaction\";\n+\ttransaction->objdir = tmp_objdir_create(source->odb->repo, prefix, 0);\n+\tif (!transaction->objdir) {\n+\t\tret = error_errno(_(\"unable to create temporary object directory in %s\"),\n+\t\t\t\t  source->path);\n+\t\tfree(transaction);\n+\t\treturn ret;\n \t}\n \n \t*out = &transaction->base;\ndiff --git a/object-file.h b/object-file.h\nindex f44758c4f8..9ad79bbde0 100644\n--- a/object-file.h\n+++ b/object-file.h\n@@ -177,7 +177,6 @@ int odb_transaction_files_begin(struct odb_source *source,\n \t\t\t\tstruct odb_transaction **out,\n \t\t\t\tenum odb_transaction_flags flags);\n \n-int odb_transaction_files_prepare(struct odb_transaction *base);\n void odb_transaction_files_fsync(struct odb_transaction *base,\n \t\t\t\t int fd, const char *filename);\n \ndiff --git a/odb/source-loose.c b/odb/source-loose.c\nindex 50cb388c35..9330ae94b5 100644\n--- a/odb/source-loose.c\n+++ b/odb/source-loose.c\n@@ -769,9 +769,6 @@ static int write_loose_object(struct odb_source_loose *loose,\n \tstatic struct strbuf tmp_file = STRBUF_INIT;\n \tstatic struct strbuf filename = STRBUF_INIT;\n \n-\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n-\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n-\n \todb_loose_path(loose, &filename, oid);\n \n \tfd = start_loose_object_common(loose, &tmp_file, filename.buf, flags,\n@@ -860,9 +857,6 @@ static int odb_source_loose_write_object_stream(struct odb_source *source,\n \tchar hdr[MAX_HEADER_LEN];\n \tint hdrlen;\n \n-\tif (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))\n-\t\todb_transaction_files_prepare(loose->base.odb->transaction);\n-\n \t/* Since oid is not determined, save tmp file to odb path. */\n \tstrbuf_addf(&filename, \"%s/\", loose->base.path);\n \thdrlen = format_object_header(hdr, sizeof(hdr), in_stream->type, in_stream->size);\ndiff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh\nindex 3bdafbae0f..4dca4ada91 100755\n--- a/t/t0004-unwritable.sh\n+++ b/t/t0004-unwritable.sh\n@@ -24,8 +24,8 @@ test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable reposi\n test_lazy_prereq WRITE_TREE_OUT 'test -e \"$TRASH_DIRECTORY\"/out.write-tree'\n test_expect_success WRITE_TREE_OUT 'write-tree output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\tfatal: git-write-tree: error building trees\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start object transaction\n \tEOF\n \ttest_cmp expect out.write-tree\n '\n@@ -39,8 +39,8 @@ test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository\n test_lazy_prereq COMMIT_OUT 'test -e \"$TRASH_DIRECTORY\"/out.commit'\n test_expect_success COMMIT_OUT 'commit output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: Error building trees\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start object transaction\n \tEOF\n \ttest_cmp expect out.commit\n '\n@@ -55,9 +55,8 @@ test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repo\n test_lazy_prereq UPDATE_INDEX_OUT 'test -e \"$TRASH_DIRECTORY\"/out.update-index'\n test_expect_success UPDATE_INDEX_OUT 'update-index output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: file: failed to insert into database\n-\tfatal: Unable to process path file\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start object transaction\n \tEOF\n \ttest_cmp expect out.update-index\n '\n@@ -72,10 +71,8 @@ test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' '\n test_lazy_prereq ADD_OUT 'test -e \"$TRASH_DIRECTORY\"/out.add'\n test_expect_success ADD_OUT 'add output on unwritable repository' '\n \tcat >expect <<-\\EOF &&\n-\terror: insufficient permission for adding an object to repository database .git/objects\n-\terror: file: failed to insert into database\n-\terror: unable to index file '\\''file'\\''\n-\tfatal: updating files failed\n+\terror: unable to create temporary object directory in .git/objects: Permission denied\n+\tfatal: failed to start object transaction\n \tEOF\n \ttest_cmp expect out.add\n '\n-- \n2.56.0.173.gf57c9a7388\n\n\n"},{"id":"558839","messageId":"av7oWMU84sH-Wx1c@pks.im","threadId":"66818","inReplyTo":"20261119002043.2108654-6-jltobler@gmail.com","subject":"Re: [PATCH v2 5/6] odb/transaction: avoid \"ODB\" in error messages","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T12:15:20Z","receivedAt":"2026-11-19T12:15:20Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Nov 18, 2026 at 06:20:42PM -0600, Justin Tobler wrote:\n> diff --git a/odb/transaction.h b/odb/transaction.h\n> index 2a40c85bc8..f6c4b523cd 100644\n> --- a/odb/transaction.h\n> +++ b/odb/transaction.h\n> @@ -125,7 +125,7 @@ static inline void odb_transaction_begin_or_die(struct object_database *odb,\n>  \t\t\t\t\t\tenum odb_transaction_flags flags)\n>  {\n>  \tif (odb_transaction_begin(odb, out, flags))\n> -\t\tdie(_(\"failed to start ODB transaction\"));\n> +\t\tdie(_(\"failed to start object transaction\"));\n>  }\n>  \n>  /*\n> @@ -146,9 +146,9 @@ int odb_transaction_finalize(struct odb_transaction *transaction);\n>  static inline void odb_transaction_commit_and_finalize_or_die(struct odb_transaction *transaction)\n>  {\n>  \tif (odb_transaction_commit(transaction))\n> -\t\tdie(_(\"failed to commit ODB transaction\"));\n> +\t\tdie(_(\"failed to commit object transaction\"));\n>  \tif (odb_transaction_finalize(transaction))\n> -\t\tdie(_(\"failed to finalize ODB transaction\"));\n> +\t\tdie(_(\"failed to finalize object transaction\"));\n>  }\n\nThanks for including this, the changes look obviously good to me.\n\nPatrick\n\n"},{"id":"558840","messageId":"av7oYYvxdMutzgyP@pks.im","threadId":"66818","inReplyTo":"20261119002043.2108654-1-jltobler@gmail.com","subject":"Re: [PATCH v2 0/6] object-file: eagerly create ODB transaction temporary directory","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-19T12:15:29Z","receivedAt":"2026-11-19T12:15:29Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Nov 18, 2026 at 06:20:37PM -0600, Justin Tobler wrote:\n> Range-diff against v1:\n\nAll of the changes look sensible to me, so I'm happy with this version.\nThanks!\n\nPatrick\n\n"},{"id":"558886","messageId":"xmqqeccgwpsv.fsf@gitster.g","threadId":"66818","inReplyTo":"av7oYYvxdMutzgyP@pks.im","subject":"Re: [PATCH v2 0/6] object-file: eagerly create ODB transaction temporary directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T20:04:48Z","receivedAt":"2026-11-19T20:04:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Wed, Nov 18, 2026 at 06:20:37PM -0600, Justin Tobler wrote:\n>> Range-diff against v1:\n>\n> All of the changes look sensible to me, so I'm happy with this version.\n> Thanks!\n\nThanks for writing and reviewing.  Will queue.\n\n"}]}