Skip to content

cache-tree: do not start an ODB transaction for repair-only updates - #2348

Open
dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:cache-tree-vs-odb-transactions
Open

dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:cache-tree-vs-odb-transactions

Conversation

@dscho

@dscho dscho commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

I needed this (in addition to many other fixes) to get Git for Windows v2.98.0-rc0 out the door.

cc: Derrick Stolee stolee@gmail.com

Since e928a32 (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>
@dscho dscho self-assigned this Dec 4, 2026
@dscho

dscho commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

/submit

@gitgitgadget

gitgitgadget Bot commented Dec 4, 2026

Copy link
Copy Markdown

Submitted as pull.2348.git.1796395037799.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2348/dscho/cache-tree-vs-odb-transactions-v1

To fetch this version to local tag pr-2348/dscho/cache-tree-vs-odb-transactions-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2348/dscho/cache-tree-vs-odb-transactions-v1

@gitgitgadget

gitgitgadget Bot commented Dec 4, 2026

Copy link
Copy Markdown

Derrick Stolee wrote on the Git mailing list (how to reply to this email):

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

@gitgitgadget

gitgitgadget Bot commented Dec 4, 2026

Copy link
Copy Markdown

User Derrick Stolee <stolee@gmail.com> has been added to the cc: list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant