# Fix for transaction commit failing when a compatibility hash is configured

_With batch fsync and a compatibility hash both enabled, migrating the temporary object directory cannot handle an existing loose-object-idx file._

Section: Patches. Edition of 2026-10-30. Written by an AI editor from the thread "[PATCH] tmp-objdir: merge loose object index when migrating tmpdir" (34 messages): https://gitlist.dev/t/66637

Justin Tobler found the bug while working on a separate series that creates the "files" ODB transaction eagerly instead of lazily. When a compatibility hash is configured, each loose object write also records a mapping in a "loose-object-idx" file. With batch fsync enabled, the objects and the mapping file go to a temporary object directory and are migrated to the primary directory on commit.

The objects migrate fine. The mapping file cannot be migrated if one already exists in the primary object directory, so the transaction fails on commit. Tobler's fix reads the temporary mapping file and merges its entries into the primary one, then writes a new "loose-object-idx" atomically.

The series was split into preparatory steps. One extracts `loose_object_map_write()` from the existing writer so callers can choose the map and file descriptor. Another extracts `loose_object_map_read()`, which parses an index into a caller-supplied map. A third adds LOOSE_OBJECT_IDX_LOCK_TIMEOUT_MS, set to 1000ms, for every caller that locks the file. Until now they passed a timeout of -1 and retried forever, so a stale lockfile could hang every later writer. The 1000ms value matches the default for core.packedRefsTimeout.

Junio Hamano reported that merging the topic to 'seen' interacted oddly with other topics. `repo_write_loose_object_map()`, which the new write helper was extracted from, loses all its callers and disappears in the merge, while the new helper stays. Tobler agreed that keeping the helper and dropping the old function is the right resolution. He noted that 'seen' still has the old declaration in "loose.h".

Tobler said he has small changes queued for a v3. Responding to review, he agreed that the source file can be read before the lock is acquired and said he would update the patch.
