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

Re: [PATCH v3 2/8] upload-pack: implement ref-in-want

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Jun 25, 2018, 17:40 UTC
Message-ID
<20180625174056.53053-1-jonathantanmy@google.com>
In-Reply-To
<20180620213235.10952-3-bmwill@google.com>
Show 6 quoted lines
> +    wanted-refs section
> +	* This section is only included if the client has requested a
> +	  ref using a 'want-ref' line and if a packfile section is also
> +	  included in the response.
> +
> +	* Always begins with the section header "wanted-refs"
Add a period at the end to be consistent with the others.
Show 5 quoted lines
> +	* The server will send a ref listing ("<oid> <refname>") for
> +	  each reference requested using 'want-ref' lines.
> +
> +	* The server MUST NOT send any refs which were not requested
> +	  using 'want-ref' lines.

We might want tag following refs to be included here in the future, but at that time, I think we can amend this to say that if include-tag-ref is sent by the user, the server may send additional refs, otherwise the server must not do so. So this is fine.

Show 20 quoted lines
> +test_expect_success 'mix want and want-ref' '
> +	cat >expected_refs <<-EOF &&
> +	$(git rev-parse f) refs/heads/master
> +	EOF
> +	git rev-parse e f | sort >expected_commits &&
> +
> +	test-pkt-line pack >in <<-EOF &&
> +	command=fetch
> +	0001
> +	no-progress
> +	want-ref refs/heads/master
> +	want $(git rev-parse e)
> +	have $(git rev-parse a)
> +	done
> +	0000
> +	EOF
> +
> +	git serve --stateless-rpc >out <in &&
> +	check_output
> +'

Overall the tests look good, although I might be a bit biased since they are based on what I wrote a while ago [1]. I was wondering about the behavior when the client mixes "want" and "want-ref" (as will happen if they fetch both a ref by name and an exact SHA-1), and this test indeed shows the expected behavior.

[1] https://public-inbox.org/git/d0d42b3bb4cf755f122591e191354c53848f197d.1485381677.git.jonathantanmy@google.com/
Show 19 quoted lines
> +test_expect_success 'want-ref with ref we already have commit for' '
> +	cat >expected_refs <<-EOF &&
> +	$(git rev-parse c) refs/heads/o/foo
> +	EOF
> +	>expected_commits &&
> +
> +	test-pkt-line pack >in <<-EOF &&
> +	command=fetch
> +	0001
> +	no-progress
> +	want-ref refs/heads/o/foo
> +	have $(git rev-parse c)
> +	done
> +	0000
> +	EOF
> +
> +	git serve --stateless-rpc >out <in &&
> +	check_output
> +'

Likewise for this test - the ref is still reported, but the packfile does not contain the requested object.

>  struct upload_pack_data {
>  	struct object_array wants;
> +	struct string_list wanted_refs;

Document here that this is a map from ref names to owned struct object_id instances.

Show 19 quoted lines
> +static int parse_want_ref(const char *line, struct string_list *wanted_refs)
> +{
> +	const char *arg;
> +	if (skip_prefix(line, "want-ref ", &arg)) {
> +		struct object_id oid;
> +		struct string_list_item *item;
> +		struct object *o;
> +
> +		if (read_ref(arg, &oid))
> +			die("unknown ref %s", arg);
> +
> +		item = string_list_append(wanted_refs, arg);
> +		item->util = oiddup(&oid);
> +
> +		o = parse_object_or_die(&oid, arg);
> +		if (!(o->flags & WANTED)) {
> +			o->flags |= WANTED;
> +			add_object_array(o, NULL, &want_obj);
> +		}

Makes sense - besides adding it to wanted_refs, this adds the object to want_obj, just like how the other code paths for "want" adds it.

Show 17 quoted lines
> +static void send_wanted_ref_info(struct upload_pack_data *data)
> +{
> +	const struct string_list_item *item;
> +
> +	if (!data->wanted_refs.nr)
> +		return;
> +
> +	packet_write_fmt(1, "wanted-refs\n");
> +
> +	for_each_string_list_item(item, &data->wanted_refs) {
> +		packet_write_fmt(1, "%s %s\n",
> +				 oid_to_hex(item->util),
> +				 item->string);
> +	}
> +
> +	packet_delim(1);
> +}

The documentation states that the "wanted-refs" section is only sent if there is at least one "want-ref" from the client, and each "want-ref" causes one entry to be added to data->wanted_refs, so this is correct.

Thanks - besides adding the period in the documentation, this patch looks good to me.

Previous: Brandon WilliamsNext: Jonathan Tan
Message 48 of 122 in “ref-in-want”
  1. 0/8 ref-in-wantBrandon Williams, Jun 5, 2018
  2. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 5, 2018
  3. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 5, 2018
  4. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 5, 2018
  5. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 5, 2018
  6. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 5, 2018
  7. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 5, 2018
  8. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 5, 2018
  9. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 5, 2018
  10. Ramsay JonesJun 5, 2018
  11. Ævar Arnfjörð BjarmasonJun 5, 2018
  12. Brandon WilliamsJun 6, 2018
  13. Ævar Arnfjörð BjarmasonJun 6, 2018
  14. Brandon WilliamsJun 6, 2018
  15. 0/8 ref-in-wantBrandon Williams, Jun 13, 2018
  16. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 13, 2018
  17. Stefan BellerJun 14, 2018
  18. Brandon WilliamsJun 14, 2018
  19. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 13, 2018
  20. Stefan BellerJun 14, 2018
  21. Brandon WilliamsJun 14, 2018
  22. Junio C HamanoJun 15, 2018
  23. Junio C HamanoJun 15, 2018
  24. Brandon WilliamsJun 19, 2018
  25. Junio C HamanoJun 19, 2018
  26. Brandon WilliamsJun 19, 2018
  27. Junio C HamanoJun 21, 2018
  28. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 13, 2018
  29. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 13, 2018
  30. Stefan BellerJun 14, 2018
  31. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 13, 2018
  32. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 13, 2018
  33. Stefan BellerJun 14, 2018
  34. Brandon WilliamsJun 14, 2018
  35. Jonathan NiederJun 22, 2018
  36. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 13, 2018
  37. Stefan BellerJun 14, 2018
  38. Jonathan TanJun 14, 2018
  39. Brandon WilliamsJun 19, 2018
  40. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 13, 2018
  41. Stefan BellerJun 14, 2018
  42. Junio C HamanoJun 15, 2018
  43. Brandon WilliamsJun 18, 2018
  44. 0/8 ref-in-wantBrandon Williams, Jun 20, 2018
  45. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 20, 2018
  46. Jonathan NiederJun 22, 2018
  47. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 20, 2018
  48. Jonathan TanJun 25, 2018
  49. Jonathan TanJun 25, 2018
  50. Brandon WilliamsJun 25, 2018
  51. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 20, 2018
  52. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 20, 2018
  53. Jonathan TanJun 25, 2018
  54. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 20, 2018
  55. Jonathan NiederJun 22, 2018
  56. Jonathan NiederJun 22, 2018
  57. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 20, 2018
  58. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 20, 2018
  59. Jonathan NiederJun 22, 2018
  60. Brandon WilliamsJun 25, 2018
  61. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 20, 2018
  62. Jonathan TanJun 25, 2018
  63. Brandon WilliamsJun 25, 2018
  64. 0/8 ref-in-wantBrandon Williams, Jun 25, 2018
  65. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 25, 2018
  66. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 25, 2018
  67. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 25, 2018
  68. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 25, 2018
  69. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 25, 2018
  70. Jonathan TanJun 25, 2018
  71. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 25, 2018
  72. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 25, 2018
  73. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 25, 2018
  74. Jonathan TanJun 25, 2018
  75. Jonathan TanJun 25, 2018
  76. 0/8 ref-in-wantBrandon Williams, Jun 26, 2018
  77. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 26, 2018
  78. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 26, 2018
  79. Junio C HamanoJun 26, 2018
  80. Brandon WilliamsJun 27, 2018
  81. Junio C HamanoJun 27, 2018
  82. Brandon WilliamsJun 27, 2018
  83. Stefan BellerJun 27, 2018
  84. Jonathan TanJun 27, 2018
  85. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 26, 2018
  86. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 26, 2018
  87. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 26, 2018
  88. Junio C HamanoJun 26, 2018
  89. Brandon WilliamsJun 27, 2018
  90. Jonathan TanJun 27, 2018
  91. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 26, 2018
  92. Jonathan TanJun 27, 2018
  93. Brandon WilliamsJun 27, 2018
  94. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 26, 2018
  95. Junio C HamanoJun 26, 2018
  96. Brandon WilliamsJun 27, 2018
  97. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 26, 2018
  98. Junio C HamanoJun 26, 2018
  99. 0/8 ref-in-wantBrandon Williams, Jun 27, 2018
  100. 1/8 test-pkt-line: add unpack-sideband subcommandBrandon Williams, Jun 27, 2018
  101. 2/8 upload-pack: implement ref-in-wantBrandon Williams, Jun 27, 2018
  102. 3/8 upload-pack: test negotiation with changing repositoryBrandon Williams, Jun 27, 2018
  103. 5/8 fetch: refactor fetch_refs into two functionsBrandon Williams, Jun 27, 2018
  104. 4/8 fetch: refactor the population of peer ref OIDsBrandon Williams, Jun 27, 2018
  105. 7/8 fetch-pack: put shallow info in output parameterBrandon Williams, Jun 27, 2018
  106. 6/8 fetch: refactor to make function args narrowerBrandon Williams, Jun 27, 2018
  107. 8/8 fetch-pack: implement ref-in-wantBrandon Williams, Jun 27, 2018
  108. Duy NguyenJul 22, 2018
  109. Brandon WilliamsJul 23, 2018
  110. Duy NguyenJul 23, 2018
  111. Jonathan NiederJul 23, 2018
  112. fetch-pack: mark die strings for translationBrandon Williams, Jul 23, 2018
  113. Stefan BellerJul 23, 2018
  114. Jonathan NiederJul 23, 2018
  115. Junio C HamanoJul 23, 2018
  116. Junio C HamanoJul 23, 2018
  117. Brandon WilliamsJul 23, 2018
  118. Jonathan TanJun 15, 2018
  119. Brandon WilliamsJun 19, 2018
  120. Jonathan TanJun 19, 2018
  121. Brandon WilliamsJun 19, 2018
  122. Jonathan TanJun 19, 2018

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.