git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 4/4] tmp-objdir: merge loose object index when migrating tmpdir

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 29, 2026, 08:05 UTC
Message-ID
<auL-ZBontaECu8vo@pks.im>
In-Reply-To
<20261029002413.3291184-5-jltobler@gmail.com>
On Wed, Oct 28, 2026 at 07:24:13PM -0500, Justin Tobler wrote:
Show 25 quoted lines
> diff --git a/loose.c b/loose.c
> index f2e111c25e..36da63684f 100644
> --- a/loose.c
> +++ b/loose.c
> @@ -311,3 +311,50 @@ void loose_object_map_clear(struct loose_object_map **map)
>  	free(m);
>  	*map = NULL;
>  }
> +
> +int loose_object_idx_merge(struct repository *repo, const char *src,
> +			   const char *dst)
> +{
> +	struct lock_file lock = LOCK_INIT;
> +	struct loose_object_map *map;
> +	int ret;
> +	int fd;
> +
> +	loose_object_map_init(&map);
> +
> +	fd = repo_hold_lock_file_for_update_timeout(repo, &lock, dst, 0,
> +						    LOOSE_OBJECT_IDX_LOCK_TIMEOUT_MS);
> +	if (fd < 0) {
> +		ret = error_errno(_("unable to lock %s"), dst);
> +		goto out;
> +	}

Okay, so this explains why you didn't want to pass a path to `loose_object_map_write()`: we need the lock to span across multiple other operations. Makes sense.

Show 9 quoted lines
> +	if (loose_object_map_read(repo, dst, map, NULL) < 0) {
> +		ret = error(_("unable to read loose object index %s"), dst);
> +		goto out;
> +	}
> +
> +	if (loose_object_map_read(repo, src, map, NULL) < 0) {
> +		ret = error(_("unable to read loose object index %s"), src);
> +		goto out;
> +	}

It makes sense that we read `dst` under the lock so that we don't risk losing data that a concurrent process writes into it. But to minimize the critical section, can't we move `src` out of it and read it before we lock?

Show 10 quoted lines
> diff --git a/loose.h b/loose.h
> index ed663ac550..35b46f4be5 100644
> --- a/loose.h
> +++ b/loose.h
> @@ -23,5 +23,7 @@ int repo_add_loose_object_map(struct odb_source_loose *loose,
>  			      const struct object_id *compat_oid);
>  int repo_read_loose_object_map(struct repository *repo);
>  int repo_write_loose_object_map(struct repository *repo);
> +int loose_object_idx_merge(struct repository *repo, const char *src,
> +			   const char *dst);
Do we maybe want to add a comment to this new function?
Thanks!
Patrick
Previous: Justin ToblerNext: Justin Tobler
Message 16 of 33 in “tmp-objdir: merge loose object index when migrating tmpdir”
  1. tmp-objdir: merge loose object index when migrating tmpdirJustin Tobler, Oct 22, 2026
  2. Patrick SteinhardtOct 23, 2026
  3. Justin ToblerOct 23, 2026
  4. Patrick SteinhardtOct 26, 2026
  5. Justin ToblerOct 26, 2026
  6. 0/4 loose: fix migrating "loose-object-idx" with batch fsyncJustin Tobler, Oct 29, 2026
  7. 1/4 loose: use finite timeout when locking "loose-object-idx" fileJustin Tobler, Oct 29, 2026
  8. Patrick SteinhardtOct 29, 2026
  9. 2/4 loose: lift loose object index parsing logic into helperJustin Tobler, Oct 29, 2026
  10. Patrick SteinhardtOct 29, 2026
  11. Justin ToblerOct 29, 2026
  12. 3/4 loose: lift loose object index writing logic into helperJustin Tobler, Oct 29, 2026
  13. Patrick SteinhardtOct 29, 2026
  14. Justin ToblerOct 29, 2026
  15. 4/4 tmp-objdir: merge loose object index when migrating tmpdirJustin Tobler, Oct 29, 2026
  16. Patrick SteinhardtOct 29, 2026
  17. Justin ToblerOct 29, 2026
  18. Junio C HamanoOct 29, 2026
  19. Justin ToblerOct 29, 2026
  20. 0/4 loose: fix migrating "loose-object-idx" with batch fsyncJustin Tobler, Oct 29, 2026
  21. 1/4 loose: use finite timeout when locking "loose-object-idx" fileJustin Tobler, Oct 29, 2026
  22. Karthik NayakOct 30, 2026
  23. 2/4 loose: lift loose object index parsing logic into helperJustin Tobler, Oct 29, 2026
  24. Karthik NayakOct 30, 2026
  25. Justin ToblerOct 30, 2026
  26. 3/4 loose: lift loose object index writing logic into helperJustin Tobler, Oct 29, 2026
  27. 4/4 tmp-objdir: merge loose object index when migrating tmpdirJustin Tobler, Oct 29, 2026
  28. Karthik NayakOct 30, 2026
  29. Justin ToblerOct 30, 2026
  30. Patrick SteinhardtOct 30, 2026
  31. Justin ToblerOct 30, 2026
  32. Karthik NayakOct 30, 2026
  33. Justin ToblerOct 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.