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

Re: [RFC PATCH 1/7] fetch-pack: allow NULL negotiator->add_tip

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2020, 19:53 UTC
Message-ID
<xmqqo8noooni.fsf@gitster.c.googlers.com>
In-Reply-To
<044a782863dd690ed4e430b3793538f701a850c6.1596590295.git.jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
> In a subsequent patch, a null fetch negotiator will be introduced. This
> negotiator, among other things, will not need any tip information and
> will have a NULL add_tip.

After reading the original code that the patch touches, I know what "a NULL add_tip" is, but it would have been nicer to readers if you said "callback" or "method" or "function".

With or without the "if add_tip method is set to NULL, return without doing anything" optimization, it does make sense to refactor two existing places that do identical things.

If all the current negotiators never have NULL in the .add_tip field, however, I'd suspect that it would make it easier to understand if this step is explained as refactoring duplicated code into a single helper _without_ the early-return for optimization, and then the step that introduces the negotiator that does want to lack add_tip method to add the early return. After all, if the null negotiator added a pointer to a no-op function to its .add_tip field, things would still work correctly without the early-return in the new helper function, no?

Show 9 quoted lines
> Teach fetch-pack to allow this, and to take advantage of this by
> avoiding a ref and alternate traversal when it can. To do this, this
> patch combines all invocations of functions that invoke add_tip into one
> function, and that function first checks whether add_tip is NULL.
>
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---
>  fetch-pack.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
Show 46 quoted lines
>
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 80fb3bd899..6c786f5970 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -240,6 +240,16 @@ static void mark_tips(struct fetch_negotiator *negotiator,
>  	return;
>  }
>  
> +static void add_tips_and_alternates(struct fetch_negotiator *negotiator,
> +				    const struct oid_array *negotiation_tips)
> +{
> +	if (!negotiator->add_tip)
> +		return;
> +
> +	mark_tips(negotiator, negotiation_tips);
> +	for_each_cached_alternate(negotiator, insert_one_alternate_object);
> +}
> +
>  static int find_common(struct fetch_negotiator *negotiator,
>  		       struct fetch_pack_args *args,
>  		       int fd[2], struct object_id *result_oid,
> @@ -262,10 +272,8 @@ static int find_common(struct fetch_negotiator *negotiator,
>  			   PACKET_READ_CHOMP_NEWLINE |
>  			   PACKET_READ_DIE_ON_ERR_PACKET);
>  
> -	if (!args->no_dependents) {
> -		mark_tips(negotiator, args->negotiation_tips);
> -		for_each_cached_alternate(negotiator, insert_one_alternate_object);
> -	}
> +	if (!args->no_dependents)
> +		add_tips_and_alternates(negotiator, args->negotiation_tips);
>  
>  	fetching = 0;
>  	for ( ; refs ; refs = refs->next) {
> @@ -1575,9 +1583,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
>  				else
>  					state = FETCH_SEND_REQUEST;
>  
> -				mark_tips(negotiator, args->negotiation_tips);
> -				for_each_cached_alternate(negotiator,
> -							  insert_one_alternate_object);
> +				add_tips_and_alternates(negotiator, args->negotiation_tips);
>  			} else {
>  				filter_refs(args, &ref, sought, nr_sought);
>  				state = FETCH_SEND_REQUEST;
Previous: Jonathan TanNext: Jonathan Tan
Message 15 of 57 in “Modify fetch-pack to no longer die on error?”
  1. Modify fetch-pack to no longer die on error?Jonathan Tan, Jul 24, 2020
  2. Junio C HamanoJul 24, 2020
  3. Junio C HamanoJul 24, 2020
  4. Jeff KingJul 25, 2020
  5. Junio C HamanoJul 25, 2020
  6. Jeff KingJul 27, 2020
  7. Jonathan TanJul 28, 2020
  8. Jeff KingJul 28, 2020
  9. Jonathan TanJul 29, 2020
  10. Jeff KingJul 29, 2020
  11. Junio C HamanoJul 29, 2020
  12. Jonathan TanJul 29, 2020
  13. 0/7 Lazy fetch with subprocessJonathan Tan, Aug 5, 2020
  14. 1/7 fetch-pack: allow NULL negotiator->add_tipJonathan Tan, Aug 5, 2020
  15. Junio C HamanoAug 5, 2020
  16. Jonathan TanAug 7, 2020
  17. 3/7 negotiator/null: add null fetch negotiatorJonathan Tan, Aug 5, 2020
  18. 2/7 fetch-pack: allow NULL negotiator->known_commonJonathan Tan, Aug 5, 2020
  19. Junio C HamanoAug 5, 2020
  20. Junio C HamanoAug 5, 2020
  21. Jonathan TanAug 7, 2020
  22. 4/7 fetch: --stdinJonathan Tan, Aug 5, 2020
  23. Junio C HamanoAug 5, 2020
  24. Jonathan TanAug 7, 2020
  25. Junio C HamanoAug 7, 2020
  26. Jonathan TanAug 7, 2020
  27. 5/7 fetch: submodule configJonathan Tan, Aug 5, 2020
  28. 7/7 promisor-remote: use subprocess to fetchJonathan Tan, Aug 5, 2020
  29. 6/7 fetch: only populate existing_refs if neededJonathan Tan, Aug 5, 2020
  30. 0/7 Lazy fetch with subprocessJonathan Tan, Aug 11, 2020
  31. 1/7 negotiator/null: add null fetch negotiatorJonathan Tan, Aug 11, 2020
  32. Derrick StoleeAug 12, 2020
  33. Junio C HamanoAug 12, 2020
  34. Jonathan TanAug 12, 2020
  35. 2/7 fetch: allow refspecs specified through stdinJonathan Tan, Aug 11, 2020
  36. 3/7 fetch: avoid reading submodule config until neededJonathan Tan, Aug 11, 2020
  37. Junio C HamanoAug 12, 2020
  38. 4/7 fetch: only populate existing_refs if neededJonathan Tan, Aug 11, 2020
  39. Junio C HamanoAug 12, 2020
  40. 5/7 fetch-pack: do not lazy-fetch during ref iterationJonathan Tan, Aug 11, 2020
  41. Junio C HamanoAug 12, 2020
  42. 6/7 promisor-remote: lazy-fetch objects in subprocessJonathan Tan, Aug 11, 2020
  43. Junio C HamanoAug 12, 2020
  44. 7/7 fetch-pack: remove no_dependents codeJonathan Tan, Aug 11, 2020
  45. Derrick StoleeAug 12, 2020
  46. 0/7 Lazy fetch with subprocessJonathan Tan, Aug 18, 2020
  47. 1/7 negotiator/noop: add noop fetch negotiatorJonathan Tan, Aug 18, 2020
  48. 2/7 fetch: allow refspecs specified through stdinJonathan Tan, Aug 18, 2020
  49. 4/7 fetch: only populate existing_refs if neededJonathan Tan, Aug 18, 2020
  50. 5/7 fetch-pack: do not lazy-fetch during ref iterationJonathan Tan, Aug 18, 2020
  51. 3/7 fetch: avoid reading submodule config until neededJonathan Tan, Aug 18, 2020
  52. 6/7 promisor-remote: lazy-fetch objects in subprocessJonathan Tan, Aug 18, 2020
  53. 7/7 fetch-pack: remove no_dependents codeJonathan Tan, Aug 18, 2020
  54. Junio C HamanoAug 18, 2020
  55. Junio C HamanoAug 18, 2020
  56. fixup! promisor-remote: lazy-fetch objects in subprocessJonathan Tan, Aug 18, 2020
  57. Junio C HamanoAug 18, 2020

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.