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

Re: [PATCH 02/13] odb: introduce `odb_source_new()`

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 27, 2025, 11:21 UTC
Message-ID
<aP9VutHav-f37NHw@pks.im>
In-Reply-To
<xmqqjz0kp86k.fsf@gitster.g>
On Fri, Oct 24, 2025 at 09:37:39AM -0700, Junio C Hamano wrote:
Show 42 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > diff --git a/repository.c b/repository.c
> > index 6faf5c73981..6aaa7ba0086 100644
> > --- a/repository.c
> > +++ b/repository.c
> > @@ -160,20 +160,24 @@ void repo_set_gitdir(struct repository *repo,
> >  	 * until after xstrdup(root). Then we can free it.
> >  	 */
> >  	char *old_gitdir = repo->gitdir;
> > +	char *objects_path = NULL;
> >  
> >  	repo->gitdir = xstrdup(gitfile ? gitfile : root);
> >  	free(old_gitdir);
> >  
> >  	repo_set_commondir(repo, o->commondir);
> > +	expand_base_dir(&objects_path, o->object_dir,
> > +			repo->commondir, "objects");
> >  
> >  	if (!repo->objects->sources) {
> > -		CALLOC_ARRAY(repo->objects->sources, 1);
> > -		repo->objects->sources->odb = repo->objects;
> > -		repo->objects->sources->local = true;
> > +		repo->objects->sources = odb_source_new(repo->objects,
> > +							objects_path, true);
> >  		repo->objects->sources_tail = &repo->objects->sources->next;
> > +		free(objects_path);
> > +	} else {
> > +		free(repo->objects->sources->path);
> > +		repo->objects->sources->path = objects_path;
> >  	}
> > -	expand_base_dir(&repo->objects->sources->path, o->object_dir,
> > -			repo->commondir, "objects");
> >  
> >  	repo->objects->sources->disable_ref_updates = o->disable_ref_updates;
> 
> Everything else is straight-forward, but this one is trickier.  When
> the .sources structure already exists, we used to just change the
> path in it, but now because creation of .sources structure requires
> path to be computed beforehand, we need an "else" clause to handle
> the "when we already had .sources when we enter this section of
> code" case.

Yeah. I plan on revamping this area so that we create the primary object source only after we have figured out all details about the repository. But for now we'll continue to reach into the already allocated source and replace its path.

Patrick
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 7 of 58 in “Carve out loose object source”
  1. 00/13 Carve out loose object sourcePatrick Steinhardt, Oct 24, 2025
  2. 01/13 odb: fix subtle logic to check whether an alternate is usablePatrick Steinhardt, Oct 24, 2025
  3. Junio C HamanoOct 24, 2025
  4. Karthik NayakOct 30, 2025
  5. 02/13 odb: introduce `odb_source_new()`Patrick Steinhardt, Oct 24, 2025
  6. Junio C HamanoOct 24, 2025
  7. Patrick SteinhardtOct 27, 2025
  8. 03/13 odb: adjust naming to free object sourcesPatrick Steinhardt, Oct 24, 2025
  9. Karthik NayakOct 30, 2025
  10. 04/13 object-file: move `fetch_if_missing`Patrick Steinhardt, Oct 24, 2025
  11. 05/13 object-file: introduce `struct odb_loose_source`Patrick Steinhardt, Oct 24, 2025
  12. Karthik NayakOct 30, 2025
  13. Patrick SteinhardtOct 30, 2025
  14. Patrick SteinhardtOct 31, 2025
  15. Junio C HamanoOct 31, 2025
  16. Patrick SteinhardtNov 3, 2025
  17. Junio C HamanoOct 31, 2025
  18. 06/13 object-file: move loose object cache into loose sourcePatrick Steinhardt, Oct 24, 2025
  19. Junio C HamanoOct 24, 2025
  20. Patrick SteinhardtOct 27, 2025
  21. 07/13 object-file: hide internals when we need to reprepare loose sourcesPatrick Steinhardt, Oct 24, 2025
  22. 08/13 object-file: move loose object map into loose sourcePatrick Steinhardt, Oct 24, 2025
  23. 09/13 object-file: read objects via the loose object sourcePatrick Steinhardt, Oct 24, 2025
  24. Karthik NayakOct 30, 2025
  25. 10/13 object-file: rename `has_loose_object()`Patrick Steinhardt, Oct 24, 2025
  26. 11/13 object-file: refactor freshening of objectsPatrick Steinhardt, Oct 24, 2025
  27. 12/13 object-file: rename `write_object_file()`Patrick Steinhardt, Oct 24, 2025
  28. 13/13 object-file: refactor writing objects via a streamPatrick Steinhardt, Oct 24, 2025
  29. Karthik NayakOct 30, 2025
  30. 00/13 Carve out loose object sourcePatrick Steinhardt, Oct 31, 2025
  31. 01/13 odb: fix subtle logic to check whether an alternate is usablePatrick Steinhardt, Oct 31, 2025
  32. 02/13 odb: introduce `odb_source_new()`Patrick Steinhardt, Oct 31, 2025
  33. 03/13 odb: adjust naming to free object sourcesPatrick Steinhardt, Oct 31, 2025
  34. 04/13 object-file: move `fetch_if_missing`Patrick Steinhardt, Oct 31, 2025
  35. 05/13 object-file: introduce `struct odb_loose_source`Patrick Steinhardt, Oct 31, 2025
  36. 06/13 object-file: move loose object cache into loose sourcePatrick Steinhardt, Oct 31, 2025
  37. 07/13 object-file: hide internals when we need to reprepare loose sourcesPatrick Steinhardt, Oct 31, 2025
  38. 08/13 object-file: move loose object map into loose sourcePatrick Steinhardt, Oct 31, 2025
  39. 09/13 object-file: read objects via the loose object sourcePatrick Steinhardt, Oct 31, 2025
  40. 10/13 object-file: rename `has_loose_object()`Patrick Steinhardt, Oct 31, 2025
  41. 11/13 object-file: refactor freshening of objectsPatrick Steinhardt, Oct 31, 2025
  42. 12/13 object-file: rename `write_object_file()`Patrick Steinhardt, Oct 31, 2025
  43. 13/13 object-file: refactor writing objects via a streamPatrick Steinhardt, Oct 31, 2025
  44. 00/13 Carve out loose object sourcePatrick Steinhardt, Nov 3, 2025
  45. 01/13 odb: fix subtle logic to check whether an alternate is usablePatrick Steinhardt, Nov 3, 2025
  46. 02/13 odb: introduce `odb_source_new()`Patrick Steinhardt, Nov 3, 2025
  47. 03/13 odb: adjust naming to free object sourcesPatrick Steinhardt, Nov 3, 2025
  48. 04/13 object-file: move `fetch_if_missing`Patrick Steinhardt, Nov 3, 2025
  49. 05/13 object-file: introduce `struct odb_source_loose`Patrick Steinhardt, Nov 3, 2025
  50. 06/13 object-file: move loose object cache into loose sourcePatrick Steinhardt, Nov 3, 2025
  51. 07/13 object-file: hide internals when we need to reprepare loose sourcesPatrick Steinhardt, Nov 3, 2025
  52. 08/13 object-file: move loose object map into loose sourcePatrick Steinhardt, Nov 3, 2025
  53. 09/13 object-file: read objects via the loose object sourcePatrick Steinhardt, Nov 3, 2025
  54. 10/13 object-file: rename `has_loose_object()`Patrick Steinhardt, Nov 3, 2025
  55. 11/13 object-file: refactor freshening of objectsPatrick Steinhardt, Nov 3, 2025
  56. 12/13 object-file: rename `write_object_file()`Patrick Steinhardt, Nov 3, 2025
  57. 13/13 object-file: refactor writing objects via a streamPatrick Steinhardt, Nov 3, 2025
  58. Karthik NayakNov 3, 2025

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.