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

Re: [PATCH/RFC 5/6] fetch: pass refspec to http server

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Apr 17, 2016, 02:33 UTC
Message-ID
<CAPig+cSxkuWB5qqVY3-m9ESmmHMKwXM+qtbRsZ1j1osjp2i3HQ@mail.gmail.com>
In-Reply-To
<1460747949-3514-6-git-send-email-dturner@twopensource.com>
On Fri, Apr 15, 2016 at 3:19 PM, David Turner <dturner@twopensource.com> wrote:
Show 21 quoted lines
> When fetching over http, send the requested refspec to the server.
> The server will then only send refs matching that refspec.  It is
> permitted for old servers to ignore that parameter, and the client
> will automatically handle this.
>
> When the server has many refs, and the client only wants a few, this
> can save bandwidth and reduce fetch latency.
>
> Signed-off-by: David Turner <dturner@twopensource.com>
> ---
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> @@ -302,9 +302,27 @@ static struct ref *get_ref_map(struct transport *transport,
> -       remote_refs = transport_get_remote_refs(transport, NULL, 0);
> +       qualified_refspecs = xcalloc(refspec_count, sizeof(*qualified_refspecs));
> +       for (i = 0; i < refspec_count; i++) {
> +               if (starts_with(refspecs[i].src, "refs/")) {
> +                       qualified_refspecs[i].src = xstrdup(refspecs[i].src);
> +               } else {
> +                       struct strbuf buf = STRBUF_INIT;
> +                       strbuf_addf(&buf, "refs/heads/%s", refspecs[i].src);
> +                       qualified_refspecs[i].src = strbuf_detach(&buf, NULL);
Alternately, replace these three lines with:
    qualified_refspecs[i].src = xstrfmt("refs/heads/%s", refspecs[i].src);
and drop the braces.
Show 18 quoted lines
> +               }
> +       }
> +
> +       remote_refs = transport_get_remote_refs(transport, qualified_refspecs,
> +                                               refspec_count);
> +
> +       for (i = 0; i < refspec_count; i++) {
> +               free(qualified_refspecs[i].src);
> +       }
> +       free(qualified_refspecs);
> diff --git a/t/t5552-http-fetch-branch.sh b/t/t5552-http-fetch-branch.sh
> @@ -0,0 +1,42 @@
> +test_expect_success 'make some more commits' '
> +       (
> +               cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
> +               test_commit 2 &&
> +               git checkout -b another_branch &&
> +               test_commit 3
Broken &&-chain.
Show 13 quoted lines
> +               git checkout -b a_third_branch &&
> +               test_commit 4
> +       )
> +'
> +
> +test_expect_success 'fetch with refspec only fetches requested branch' '
> +       test_when_finished "rm trace" &&
> +       (
> +               cd clone &&
> +               GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" git fetch origin another_branch &&
> +               ! grep "refs/heads/master" ../trace
> +       )
> +'
This could be done without the subshell, perhaps?
    GIT_TRACE_PACKET=blah git -C clone fetch ...
Previous: David TurnerNext: David Turner
Message 31 of 36 in “fetch with refspec”
  1. 0/6 fetch with refspecDavid Turner, Apr 15, 2016
  2. 1/6 http-backend: use argv_array functionsDavid Turner, Apr 15, 2016
  3. Junio C HamanoApr 18, 2016
  4. David TurnerApr 19, 2016
  5. 2/6 remote-curl.c: fix variable shadowingDavid Turner, Apr 15, 2016
  6. Junio C HamanoApr 18, 2016
  7. David TurnerApr 19, 2016
  8. 3/6 http-backend: handle refspec argumentDavid Turner, Apr 15, 2016
  9. Eric SunshineApr 17, 2016
  10. David TurnerApr 19, 2016
  11. 4/6 transport: add refspec list parameters to functionsDavid Turner, Apr 15, 2016
  12. Junio C HamanoApr 18, 2016
  13. Jeff KingApr 19, 2016
  14. Stefan BellerApr 19, 2016
  15. Junio C HamanoApr 19, 2016
  16. David TurnerApr 19, 2016
  17. Jeff KingApr 19, 2016
  18. David TurnerApr 19, 2016
  19. Jeff KingApr 20, 2016
  20. David TurnerApr 20, 2016
  21. Jeff KingApr 20, 2016
  22. David TurnerApr 25, 2016
  23. Stefan BellerApr 25, 2016
  24. Stefan BellerApr 27, 2016
  25. Jeff KingApr 27, 2016
  26. Junio C HamanoApr 27, 2016
  27. David TurnerApr 29, 2016
  28. Stefan BellerApr 29, 2016
  29. David TurnerApr 19, 2016
  30. 5/6 fetch: pass refspec to http serverDavid Turner, Apr 15, 2016
  31. Eric SunshineApr 17, 2016
  32. David TurnerApr 19, 2016
  33. 6/6 clone: send refspec for single-branch clonesDavid Turner, Apr 15, 2016
  34. Eric SunshineApr 17, 2016
  35. David TurnerApr 19, 2016
  36. Stefan BellerApr 15, 2016

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.