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

Re: [PATCH 02/13] refs: introduce `.ref` field for the base iterator

From
Justin Tobler <jltobler@gmail.com>
Date
Oct 7, 2025, 20:19 UTC
Message-ID
<q6ti6bevxr4kbsi7pe7slwmvyqhc2sslma3tk3xshohnqadtuv@canofgr644do>
In-Reply-To
<20251007-b4-pks-ref-filter-skip-parsing-objects-v1-2-916cc7c6886b@pks.im>
On 25/10/07 12:58PM, Patrick Steinhardt wrote:
> The base iterator has a couple of fields that tracks the name, target,
> object ID and flags for the current reference. Due do this design we
s/Due do/Due to/
Show 10 quoted lines
> have to create a new `struct reference` whenever we want to hand over
> that reference to the callback function, which is tedious and not very
> efficient.
> 
> Convert the structure to instead contain a `stuct reference` as member.
> This member is expected to be populated by the implementations of the
> iterator and is handed over to the callback directly.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
[snip]
Show 35 quoted lines
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 0ddcf22aed..d34fbe55d6 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -962,26 +962,23 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
>  
>  	while ((ok = ref_iterator_advance(iter->iter0)) == ITER_OK) {
>  		if (iter->flags & DO_FOR_EACH_PER_WORKTREE_ONLY &&
> -		    parse_worktree_ref(iter->iter0->refname, NULL, NULL,
> +		    parse_worktree_ref(iter->iter0->ref.name, NULL, NULL,
>  				       NULL) != REF_WORKTREE_CURRENT)
>  			continue;
>  
>  		if ((iter->flags & DO_FOR_EACH_OMIT_DANGLING_SYMREFS) &&
> -		    (iter->iter0->flags & REF_ISSYMREF) &&
> -		    (iter->iter0->flags & REF_ISBROKEN))
> +		    (iter->iter0->ref.flags & REF_ISSYMREF) &&
> +		    (iter->iter0->ref.flags & REF_ISBROKEN))
>  			continue;
>  
>  		if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
> -		    !ref_resolves_to_object(iter->iter0->refname,
> +		    !ref_resolves_to_object(iter->iter0->ref.name,
>  					    iter->repo,
> -					    iter->iter0->oid,
> -					    iter->iter0->flags))
> +					    iter->iter0->ref.oid,
> +					    iter->iter0->ref.flags))
>  			continue;
>  
> -		iter->base.refname = iter->iter0->refname;
> -		iter->base.oid = iter->iter0->oid;
> -		iter->base.flags = iter->iter0->flags;
> -		iter->base.referent = iter->iter0->referent;
> +		iter->base.ref = iter->iter0->ref;

Ok, so here we already have a `struct reference` setup and thus we directly propagate to the base when advacing the iterator. Makes sense.

Show 11 quoted lines
>  
>  		return ITER_OK;
>  	}
> @@ -1368,30 +1365,29 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
>   * Return true if the specified reference should be packed.
>   */
>  static int should_pack_ref(struct files_ref_store *refs,
> -			   const char *refname,
> -			   const struct object_id *oid, unsigned int ref_flags,
> +			   const struct reference *ref,
>  			   struct pack_refs_opts *opts)

This hunk is simplifies the arguments required by should_pack_ref() by using `struct reference`. The change seems sensible, it might be worth mentioning in the commit message though.

Show 29 quoted lines
>  {
>  	struct string_list_item *item;
>  
>  	/* Do not pack per-worktree refs: */
> -	if (parse_worktree_ref(refname, NULL, NULL, NULL) !=
> +	if (parse_worktree_ref(ref->name, NULL, NULL, NULL) !=
>  	    REF_WORKTREE_SHARED)
>  		return 0;
>  
>  	/* Do not pack symbolic refs: */
> -	if (ref_flags & REF_ISSYMREF)
> +	if (ref->flags & REF_ISSYMREF)
>  		return 0;
>  
>  	/* Do not pack broken refs: */
> -	if (!ref_resolves_to_object(refname, refs->base.repo, oid, ref_flags))
> +	if (!ref_resolves_to_object(ref->name, refs->base.repo, ref->oid, ref->flags))
>  		return 0;
>  
> -	if (ref_excluded(opts->exclusions, refname))
> +	if (ref_excluded(opts->exclusions, ref->name))
>  		return 0;
>  
>  	for_each_string_list_item(item, opts->includes)
> -		if (!wildmatch(item->string, refname, 0))
> +		if (!wildmatch(item->string, ref->name, 0))
>  			return 1;
>  
>  	return 0;
[snip]
Show 13 quoted lines
> @@ -476,14 +468,7 @@ int do_for_each_ref_iterator(struct ref_iterator *iter,
>  
>  	current_ref_iter = iter;
>  	while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
> -		struct reference ref = {
> -			.name = iter->refname,
> -			.target = iter->referent,
> -			.oid = iter->oid,
> -			.flags = iter->flags,
> -		};
> -
> -		retval = fn(&ref, cb_data);
> +		retval = fn(&iter->ref, cb_data);

Now we propagate `struct reference` directly when invoking the for each callback. Makes sense.

>  		if (retval)
>  			goto out;
>  	}
-Justin
Previous: Patrick SteinhardtNext: Taylor Blau
Message 12 of 106 in “refs: improvements and fixes for peeling tags”
  1. 00/13 refs: improvements and fixes for peeling tagsPatrick Steinhardt, Oct 7, 2025
  2. 01/13 refs: introduce wrapper struct for `each_ref_fn`Patrick Steinhardt, Oct 7, 2025
  3. Justin ToblerOct 7, 2025
  4. Patrick SteinhardtOct 8, 2025
  5. Taylor BlauOct 7, 2025
  6. shejialuoOct 8, 2025
  7. Patrick SteinhardtOct 9, 2025
  8. 02/13 refs: introduce `.ref` field for the base iteratorPatrick Steinhardt, Oct 7, 2025
  9. Karthik NayakOct 7, 2025
  10. Patrick SteinhardtOct 8, 2025
  11. Patrick SteinhardtOct 8, 2025
  12. Justin ToblerOct 7, 2025
  13. Taylor BlauOct 7, 2025
  14. 03/13 refs: refactor reference status flagsPatrick Steinhardt, Oct 7, 2025
  15. Karthik NayakOct 7, 2025
  16. Patrick SteinhardtOct 8, 2025
  17. 04/13 refs: expose peeled object ID via the iteratorPatrick Steinhardt, Oct 7, 2025
  18. Karthik NayakOct 7, 2025
  19. Patrick SteinhardtOct 8, 2025
  20. Karthik NayakOct 15, 2025
  21. 05/13 upload-pack: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 7, 2025
  22. Karthik NayakOct 7, 2025
  23. Patrick SteinhardtOct 8, 2025
  24. 06/13 ref-filter: propagate peeled object IDPatrick Steinhardt, Oct 7, 2025
  25. 07/13 builtin/show-ref: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 7, 2025
  26. 08/13 refs: drop `current_ref_iter` hackPatrick Steinhardt, Oct 7, 2025
  27. 09/13 refs: drop infrastructure to peel via iteratorsPatrick Steinhardt, Oct 7, 2025
  28. 10/13 object: add flag to `peel_object()` to verify object typePatrick Steinhardt, Oct 7, 2025
  29. Kristoffer HaugsbakkOct 8, 2025
  30. 11/13 refs: don't store peeled object IDs for invalid tagsPatrick Steinhardt, Oct 7, 2025
  31. 12/13 ref-filter: detect broken tags when dereferencing themPatrick Steinhardt, Oct 7, 2025
  32. 13/13 ref-filter: parse objects on demandPatrick Steinhardt, Oct 7, 2025
  33. Kristoffer HaugsbakkOct 8, 2025
  34. Patrick SteinhardtOct 8, 2025
  35. Junio C HamanoOct 7, 2025
  36. Taylor BlauOct 7, 2025
  37. Junio C HamanoOct 7, 2025
  38. 00/14 refs: improvements and fixes for peeling tagsPatrick Steinhardt, Oct 8, 2025
  39. 01/14 refs: introduce wrapper struct for `each_ref_fn`Patrick Steinhardt, Oct 8, 2025
  40. 02/14 refs: introduce `.ref` field for the base iteratorPatrick Steinhardt, Oct 8, 2025
  41. 03/14 refs: fully reset `struct ref_iterator::ref` on iterationPatrick Steinhardt, Oct 8, 2025
  42. 04/14 refs: refactor reference status flagsPatrick Steinhardt, Oct 8, 2025
  43. 05/14 refs: expose peeled object ID via the iteratorPatrick Steinhardt, Oct 8, 2025
  44. 06/14 upload-pack: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 8, 2025
  45. 07/14 ref-filter: propagate peeled object IDPatrick Steinhardt, Oct 8, 2025
  46. 08/14 builtin/show-ref: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 8, 2025
  47. 09/14 refs: drop `current_ref_iter` hackPatrick Steinhardt, Oct 8, 2025
  48. 10/14 refs: drop infrastructure to peel via iteratorsPatrick Steinhardt, Oct 8, 2025
  49. 11/14 object: add flag to `peel_object()` to verify object typePatrick Steinhardt, Oct 8, 2025
  50. 12/14 refs: don't store peeled object IDs for invalid tagsPatrick Steinhardt, Oct 8, 2025
  51. shejialuoOct 8, 2025
  52. Patrick SteinhardtOct 9, 2025
  53. 13/14 ref-filter: detect broken tags when dereferencing themPatrick Steinhardt, Oct 8, 2025
  54. 14/14 ref-filter: parse objects on demandPatrick Steinhardt, Oct 8, 2025
  55. Jeff KingOct 9, 2025
  56. Patrick SteinhardtOct 9, 2025
  57. Jeff KingOct 9, 2025
  58. Patrick SteinhardtOct 9, 2025
  59. Jeff KingOct 10, 2025
  60. Patrick SteinhardtOct 10, 2025
  61. Jeff KingOct 10, 2025
  62. Junio C HamanoOct 10, 2025
  63. Patrick SteinhardtOct 14, 2025
  64. Junio C HamanoOct 14, 2025
  65. Toon ClaesOct 9, 2025
  66. Junio C HamanoOct 9, 2025
  67. 00/14 refs: improvements and fixes for peeling tagsPatrick Steinhardt, Oct 22, 2025
  68. 01/14 refs: introduce wrapper struct for `each_ref_fn`Patrick Steinhardt, Oct 22, 2025
  69. 02/14 refs: introduce `.ref` field for the base iteratorPatrick Steinhardt, Oct 22, 2025
  70. 03/14 refs: fully reset `struct ref_iterator::ref` on iterationPatrick Steinhardt, Oct 22, 2025
  71. 04/14 refs: refactor reference status flagsPatrick Steinhardt, Oct 22, 2025
  72. 05/14 refs: expose peeled object ID via the iteratorPatrick Steinhardt, Oct 22, 2025
  73. 06/14 upload-pack: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 22, 2025
  74. 07/14 ref-filter: propagate peeled object IDPatrick Steinhardt, Oct 22, 2025
  75. 08/14 builtin/show-ref: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 22, 2025
  76. 09/14 refs: drop `current_ref_iter` hackPatrick Steinhardt, Oct 22, 2025
  77. 10/14 refs: drop infrastructure to peel via iteratorsPatrick Steinhardt, Oct 22, 2025
  78. 11/14 object: add flag to `peel_object()` to verify object typePatrick Steinhardt, Oct 22, 2025
  79. 12/14 refs: don't store peeled object IDs for invalid tagsPatrick Steinhardt, Oct 22, 2025
  80. 13/14 ref-filter: detect broken tags when dereferencing themPatrick Steinhardt, Oct 22, 2025
  81. 14/14 ref-filter: parse objects on demandPatrick Steinhardt, Oct 22, 2025
  82. Junio C HamanoOct 22, 2025
  83. Patrick SteinhardtOct 23, 2025
  84. Karthik NayakOct 22, 2025
  85. Junio C HamanoOct 22, 2025
  86. Patrick SteinhardtOct 23, 2025
  87. 00/14 refs: improvements and fixes for peeling tagsPatrick Steinhardt, Oct 23, 2025
  88. 01/14 refs: introduce wrapper struct for `each_ref_fn`Patrick Steinhardt, Oct 23, 2025
  89. 02/14 refs: introduce `.ref` field for the base iteratorPatrick Steinhardt, Oct 23, 2025
  90. 03/14 refs: fully reset `struct ref_iterator::ref` on iterationPatrick Steinhardt, Oct 23, 2025
  91. 04/14 refs: refactor reference status flagsPatrick Steinhardt, Oct 23, 2025
  92. 05/14 refs: expose peeled object ID via the iteratorPatrick Steinhardt, Oct 23, 2025
  93. 06/14 upload-pack: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 23, 2025
  94. 07/14 ref-filter: propagate peeled object IDPatrick Steinhardt, Oct 23, 2025
  95. 08/14 builtin/show-ref: convert to use `reference_get_peeled_oid()`Patrick Steinhardt, Oct 23, 2025
  96. 09/14 refs: drop `current_ref_iter` hackPatrick Steinhardt, Oct 23, 2025
  97. 10/14 refs: drop infrastructure to peel via iteratorsPatrick Steinhardt, Oct 23, 2025
  98. 11/14 object: add flag to `peel_object()` to verify object typePatrick Steinhardt, Oct 23, 2025
  99. 12/14 refs: don't store peeled object IDs for invalid tagsPatrick Steinhardt, Oct 23, 2025
  100. 13/14 ref-filter: detect broken tags when dereferencing themPatrick Steinhardt, Oct 23, 2025
  101. 14/14 ref-filter: parse objects on demandPatrick Steinhardt, Oct 23, 2025
  102. Jeff KingNov 4, 2025
  103. Junio C HamanoNov 4, 2025
  104. Jeff KingNov 4, 2025
  105. Junio C HamanoOct 23, 2025
  106. Patrick SteinhardtOct 24, 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.