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

Re: [PATCH 5/5] bundle: generate packfiles via the object database

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 14, 2026, 07:40 UTC
Message-ID
<an7GgQLQfleCPr-a@pks.im>
In-Reply-To
<xmqqmrupsxx9.fsf@gitster.g>
On Thu, Aug 13, 2026 at 11:00:34AM -0700, Junio C Hamano wrote:
Show 93 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/bundle.c b/bundle.c
> > index b64716f252..09afc465c0 100644
> > --- a/bundle.c
> > +++ b/bundle.c
> > @@ -325,50 +325,52 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
> >  
> >  
> >  /* Write the pack data to bundle_fd */
> > -static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options)
> > +static int write_pack_data(int bundle_fd, struct rev_info *revs, int progress)
> >  {
> > -	struct child_process pack_objects = CHILD_PROCESS_INIT;
> > +	struct odb_generate_pack_options opts = ODB_GENERATE_PACK_OPTIONS_INIT;
> > +	struct odb_pack_generator *generator;
> > +	int ret = 0;
> >  	int i;
> >  
> > -	strvec_pushl(&pack_objects.args,
> > -		     "pack-objects",
> > -		     "--stdout", "--thin", "--delta-base-offset",
> > -		     NULL);
> > -	strvec_pushv(&pack_objects.args, pack_options->v);
> > +	opts.thin = 1;
> > +	opts.ofs_delta = 1;
> > +	if (progress)
> > +		opts.progress = ODB_GENERATE_PACK_PROGRESS_VERBOSE;
> >  	if (revs->filter.choice)
> > -		strvec_pushf(&pack_objects.args, "--filter=%s",
> > -			     list_objects_filter_spec(&revs->filter));
> > -	pack_objects.in = -1;
> > -	pack_objects.out = bundle_fd;
> > -	pack_objects.git_cmd = 1;
> > +		opts.filter_spec = list_objects_filter_spec(&revs->filter);
> >  
> >  	/*
> > -	 * start_command() will close our descriptor if it's >1. Duplicate it
> > -	 * to avoid surprising the caller.
> > +	 * The pack generator will consume our descriptor if it's >1.
> > +	 * Duplicate it to avoid surprising the caller.
> >  	 */
> > -	if (pack_objects.out > 1) {
> > -		pack_objects.out = dup(pack_objects.out);
> > -		if (pack_objects.out < 0) {
> > -			error_errno(_("unable to dup bundle descriptor"));
> > -			child_process_clear(&pack_objects);
> > -			return -1;
> > -		}
> > +	opts.pack_fd = bundle_fd;
> > +	if (opts.pack_fd > 1) {
> > +		opts.pack_fd = dup(bundle_fd);
> > +		if (opts.pack_fd < 0)
> > +			return error_errno(_("unable to dup bundle descriptor"));
> >  	}
> >  
> > -	if (start_command(&pack_objects))
> > -		return error(_("Could not spawn pack-objects"));
> > -
> >  	for (i = 0; i < revs->pending.nr; i++) {
> >  		struct object *object = revs->pending.objects[i].item;
> >  		if (object->flags & UNINTERESTING)
> > -			write_or_die(pack_objects.in, "^", 1);
> > -		write_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz);
> > -		write_or_die(pack_objects.in, "\n", 1);
> > +			oid_array_append(&opts.haves, &object->oid);
> > +		else
> > +			oid_array_append(&opts.wants, &object->oid);
> >  	}
> > -	close(pack_objects.in);
> > -	if (finish_command(&pack_objects))
> > -		return error(_("pack-objects died"));
> > -	return 0;
> > +
> > +	if (odb_generate_pack(the_repository->objects, &generator, &opts)) {
> > +		ret = error(_("Could not spawn pack-objects"));
> > +		goto out;
> > +	}
> > +
> > +	if (odb_pack_generator_finish(generator)) {
> > +		ret = error(_("pack-objects died"));
> > +		goto out;
> > +	}
> > +
> > +out:
> > +	odb_generate_pack_options_release(&opts);
> > +	return ret;
> >  }
> 
> This function uses the_repository, both directly and through
> the_hash_algo macro.  I think we could use revs->repo here.  An
> obvious alternative is to give this function a new parameter "struct
> repository *repo" but then we would have to worry about what should
> happen when it and revs->repo go out of sync.
Fair enough.

Ideally, we'd convert the whole file to not use `the_repository` at all anymore. But we unfortunately call `get_log_output_encoding()`, which implicitly depends on that function. I think we can still mostly drop the dependency and then just add an `extern` declaration. I'll do so in the next version.

Thanks!
Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 58 in “odb: make packfile generation pluggable”
  1. 0/5 odb: make packfile generation pluggablePatrick Steinhardt, Aug 7, 2026
  2. 1/5 odb: introduce interface to generate packfilesPatrick Steinhardt, Aug 7, 2026
  3. 2/5 upload-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 7, 2026
  4. 3/5 send-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 7, 2026
  5. 4/5 builtin/bundle: refactor option handling for progress meterPatrick Steinhardt, Aug 7, 2026
  6. 5/5 bundle: generate packfiles via the object databasePatrick Steinhardt, Aug 7, 2026
  7. Junio C HamanoAug 13, 2026
  8. Patrick SteinhardtAug 14, 2026
  9. Junio C HamanoAug 7, 2026
  10. Patrick SteinhardtAug 10, 2026
  11. Taylor BlauAug 12, 2026
  12. Patrick SteinhardtAug 13, 2026
  13. Junio C HamanoAug 13, 2026
  14. 0/6 odb: make packfile generation pluggablePatrick Steinhardt, Aug 17, 2026
  15. 1/6 odb: introduce interface to generate packfilesPatrick Steinhardt, Aug 17, 2026
  16. Elijah NewrenAug 19, 2026
  17. Patrick SteinhardtAug 20, 2026
  18. Elijah NewrenAug 21, 2026
  19. Patrick SteinhardtAug 21, 2026
  20. 2/6 upload-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 17, 2026
  21. 3/6 send-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 17, 2026
  22. 4/6 builtin/bundle: refactor option handling for progress meterPatrick Steinhardt, Aug 17, 2026
  23. 5/6 bundle: get (mostly) rid of `the_repository`Patrick Steinhardt, Aug 17, 2026
  24. Junio C HamanoAug 17, 2026
  25. Patrick SteinhardtAug 18, 2026
  26. Elijah NewrenAug 21, 2026
  27. Patrick SteinhardtAug 21, 2026
  28. 6/6 bundle: generate packfiles via the object databasePatrick Steinhardt, Aug 17, 2026
  29. Justin ToblerAug 19, 2026
  30. Patrick SteinhardtAug 20, 2026
  31. 0/6 odb: make packfile generation pluggablePatrick Steinhardt, Aug 20, 2026
  32. 1/6 odb: introduce interface to generate packfilesPatrick Steinhardt, Aug 20, 2026
  33. Karthik NayakAug 20, 2026
  34. Patrick SteinhardtAug 20, 2026
  35. Junio C HamanoAug 20, 2026
  36. Patrick SteinhardtAug 21, 2026
  37. 2/6 upload-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 20, 2026
  38. Karthik NayakAug 20, 2026
  39. Patrick SteinhardtAug 20, 2026
  40. Karthik NayakAug 20, 2026
  41. 3/6 send-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 20, 2026
  42. 4/6 builtin/bundle: refactor option handling for progress meterPatrick Steinhardt, Aug 20, 2026
  43. Karthik NayakAug 20, 2026
  44. 5/6 bundle: get (mostly) rid of `the_repository`Patrick Steinhardt, Aug 20, 2026
  45. 6/6 bundle: generate packfiles via the object databasePatrick Steinhardt, Aug 20, 2026
  46. Karthik NayakAug 20, 2026
  47. Patrick SteinhardtAug 20, 2026
  48. Karthik NayakAug 20, 2026
  49. Patrick SteinhardtAug 20, 2026
  50. Elijah NewrenAug 21, 2026
  51. 0/6 odb: make packfile generation pluggablePatrick Steinhardt, Aug 21, 2026
  52. 1/6 odb: introduce interface to generate packfilesPatrick Steinhardt, Aug 21, 2026
  53. 2/6 upload-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 21, 2026
  54. 3/6 send-pack: generate packfiles via the object databasePatrick Steinhardt, Aug 21, 2026
  55. 4/6 builtin/bundle: refactor option handling for progress meterPatrick Steinhardt, Aug 21, 2026
  56. 5/6 bundle: get (mostly) rid of `the_repository`Patrick Steinhardt, Aug 21, 2026
  57. 6/6 bundle: generate packfiles via the object databasePatrick Steinhardt, Aug 21, 2026
  58. Karthik NayakAug 21, 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.