* [PATCH] cache-tree: do not start an ODB transaction for repair-only updates
@ 2026-12-04 14:37 Johannes Schindelin via GitGitGadget
2026-12-04 14:44 ` Derrick Stolee
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2026-12-04 14:37 UTC (permalink / raw)
To: git; +Cc: Johannes Schindelin, Johannes Schindelin
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Since e928a32355dc (object-file: create ODB transaction temporary
directory eagerly), every ODB transaction in the "files" backend
immediately creates `<objects>/tmp_objdir-transaction-XXXXXX/pack`.
The `cache_tree_update()` function begins such a transaction whenever
none is in flight, even with `WRITE_TREE_REPAIR`. A repair never writes
objects, though: it only hashes tree buffers and checks whether those
objects already exist. Because `unpack_trees()` and `git checkout` both
request repair-only updates, a checkout can now create and then remove a
temporary object directory for nothing.
On Windows without `core.longPaths=true` (which only exists only in Git
for Windows so far, anyway), that is not just wasteful. The `mkdir()`
refuses paths of 248 characters or more on that platform.
As a consequence, Git for Windows' `t7429-submodule-long-path.sh`
started failing when Git for Windows was rebased onto v2.98.0-rc0. The
object directory of the nested submodule is 214 characters long.
Appending `/tmp_objdir-transaction-XXXXXX/pack` goes over the limit, and
the checkout fails:
error: unable to create temporary object directory in
.../objects: Filename too long
fatal: failed to start object transaction
Since that operation does not need to write any new objects, skip the
transaction when repairing, and keep the transaction for updates that
write trees. Obviously, the latter would still fail, but we do not test
for that in Git's test suite, and addressing that is a longer story
(involving upstreaming the `core.longPaths` support from Git for
Windows, something we'll need to do _some_ day, but not during the `-rc`
phase of v2.98.0).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
cache-tree: do not start an ODB transaction for repair-only updates
I needed this (in addition to many other fixes) to get Git for Windows
v2.98.0-rc0 out the door.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2348%2Fdscho%2Fcache-tree-vs-odb-transactions-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2348/dscho/cache-tree-vs-odb-transactions-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2348
cache-tree.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/cache-tree.c b/cache-tree.c
index 671d4165bf..3c86144cd1 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -525,7 +525,8 @@ static int update_one(struct repository *repo,
int cache_tree_update(struct index_state *istate, int flags)
{
- int inflight = !!istate->repo->objects->transaction;
+ int start_transaction = !istate->repo->objects->transaction &&
+ !(flags & WRITE_TREE_REPAIR);
struct odb_transaction *transaction;
int skip, i;
@@ -542,11 +543,11 @@ int cache_tree_update(struct index_state *istate, int flags)
trace_performance_enter();
trace2_region_enter("cache_tree", "update", istate->repo);
- if (!inflight)
+ if (start_transaction)
odb_transaction_begin_or_die(istate->repo->objects, &transaction, 0);
i = update_one(istate->repo, istate->cache_tree, istate->cache, istate->cache_nr,
"", 0, &skip, flags);
- if (!inflight)
+ if (start_transaction)
odb_transaction_commit_and_finalize_or_die(transaction);
trace2_region_leave("cache_tree", "update", istate->repo);
trace_performance_leave("cache_tree_update");
base-commit: 566b6997dd4710b625c0882cf10a7443bf52d183
--
gitgitgadget
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cache-tree: do not start an ODB transaction for repair-only updates
2026-12-04 14:37 [PATCH] cache-tree: do not start an ODB transaction for repair-only updates Johannes Schindelin via GitGitGadget
@ 2026-12-04 14:44 ` Derrick Stolee
0 siblings, 0 replies; 2+ messages in thread
From: Derrick Stolee @ 2026-12-04 14:44 UTC (permalink / raw)
To: git
On 12/4/2026 9:37 AM, Johannes Schindelin via GitGitGadget wrote:
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> Since e928a32355dc (object-file: create ODB transaction temporary
> directory eagerly), every ODB transaction in the "files" backend
> immediately creates `<objects>/tmp_objdir-transaction-XXXXXX/pack`.
>
> The `cache_tree_update()` function begins such a transaction whenever
> none is in flight, even with `WRITE_TREE_REPAIR`. A repair never writes
> objects, though: it only hashes tree buffers and checks whether those
> objects already exist. Because `unpack_trees()` and `git checkout` both
> request repair-only updates, a checkout can now create and then remove a
> temporary object directory for nothing.
I imagine that this has some performance implications beyond your issues
with long paths. Perhaps it's minor compared to everything else going on.
> On Windows without `core.longPaths=true` (which only exists only in Git
> for Windows so far, anyway), that is not just wasteful. The `mkdir()`
> refuses paths of 248 characters or more on that platform.
>
> As a consequence, Git for Windows' `t7429-submodule-long-path.sh`
> started failing when Git for Windows was rebased onto v2.98.0-rc0. The
> object directory of the nested submodule is 214 characters long.
> Appending `/tmp_objdir-transaction-XXXXXX/pack` goes over the limit, and
> the checkout fails:
>
> error: unable to create temporary object directory in
> .../objects: Filename too long
> fatal: failed to start object transaction
>
> Since that operation does not need to write any new objects, skip the
> transaction when repairing, and keep the transaction for updates that
> write trees. Obviously, the latter would still fail, but we do not test
> for that in Git's test suite, and addressing that is a longer story
> (involving upstreaming the `core.longPaths` support from Git for
> Windows, something we'll need to do _some_ day, but not during the `-rc`
> phase of v2.98.0).
Thanks for stepping through how this was caught. Yes, there are going to
be other issues with long paths. This change is a pretty solid fix for
avoiding unnecessary transactions. And perhaps is a good thing to find
for future avoidance of transactions, when possible.
LGTM.
-Stolee
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 14:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 14:37 [PATCH] cache-tree: do not start an ODB transaction for repair-only updates Johannes Schindelin via GitGitGadget
2026-12-04 14:44 ` Derrick Stolee
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.