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

Re: [PATCH v4 6/6] builtin/clone: teach git-clone(1) the --revision= option

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 31, 2025, 21:05 UTC
Message-ID
<xmqq1pwi7kyv.fsf@gitster.g>
In-Reply-To
<20250131-toon-clone-refs-v4-6-2a4ff851498f@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
>  		OPT_STRING('b', "branch", &option_branch, N_("branch"),
>  			   N_("checkout <branch> instead of the remote's HEAD")),
> +		OPT_STRING(0, "revision", &option_rev, N_("rev"),
> +			   N_("clone single revision <rev> and check out")),

OK, this thing comes as a string; we'll parse it down to a commit later, hopefully?

Show 5 quoted lines
> -	refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix,
> -			branch_top.buf);
> +	if (!option_rev)
> +		refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix,
> +				branch_top.buf);
> +	die_for_incompatible_opt2(!!option_rev, "--revision",
> +				  !!option_branch, "--branch");
> +	die_for_incompatible_opt2(!!option_rev, "--revision",
> +				  option_mirror, "--mirror");

So here is where we mark the new thing incompatible with these two, and when either of them is given with "--revision", we would bail out. OK.

> +	// TODO --no-single-branch
Style.
Show 11 quoted lines
> @@ -1381,7 +1396,15 @@ int cmd_clone(int argc,
>  	if (transport->smart_options && !deepen && !filter_options.choice)
>  		transport->smart_options->check_self_contained_and_connected = 1;
>  
> -	strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
> +	if (option_rev) {
> +		option_tags = 0;
> +		option_branch = 0;
> +		option_single_branch = 0;
> +		opts.wants_head = 0;
> +		opts.detach = 1;

option_branch is of type "char *" so sparse rightfully complains that you are assigning an integer 0 to it, which follows stronger rules than plain vanilla C standard to help us avoid mistakes.

But stepping back a bit, hasn't we already been ruled out earlier that when option_rev is set, we cannot possibly be affected by the "--branch" option that was given at the same time? I do not now about other assignments we see in this block, but are there others that are unnecessary? For example, you do not clear option_mirror in this block. Is option_branch so special that it needs clearing, and if so why?

Thanks.
Previous: Toon ClaesNext: Jean-Noël AVILA
Message 19 of 57 in “builtin/clone: teach git-clone(1) the --revision= option”
  1. builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Nov 29, 2024
  2. Patrick SteinhardtDec 2, 2024
  3. Jeff KingDec 2, 2024
  4. Michal SuchánekDec 3, 2024
  5. Toon ClaesDec 19, 2024
  6. builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Dec 19, 2024
  7. Junio C HamanoDec 19, 2024
  8. 0/6 Enable doing a shallow clone of a specific git revisionToon Claes, Jan 31, 2025
  9. 1/6 clone: cut down on global variables in clone.cToon Claes, Jan 31, 2025
  10. 2/6 clone: make it possible to specify --tagsToon Claes, Jan 31, 2025
  11. Jean-Noël AVILAFeb 1, 2025
  12. 3/6 clone: refactor wanted_peer_refs()Toon Claes, Jan 31, 2025
  13. Patrick SteinhardtFeb 3, 2025
  14. 4/6 clone: add tags refspec earlier to fetch refspecToon Claes, Jan 31, 2025
  15. Patrick SteinhardtFeb 3, 2025
  16. 5/6 clone: introduce struct clone_opts in builtin/clone.cToon Claes, Jan 31, 2025
  17. Patrick SteinhardtFeb 3, 2025
  18. 6/6 builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Jan 31, 2025
  19. Junio C HamanoJan 31, 2025
  20. Jean-Noël AVILAFeb 1, 2025
  21. Patrick SteinhardtFeb 3, 2025
  22. 0/7 Enable doing a shallow clone of a specific git revisionToon Claes, Feb 4, 2025
  23. 1/7 clone: cut down on global variables in clone.cToon Claes, Feb 4, 2025
  24. 2/7 clone: make it possible to specify --tagsToon Claes, Feb 4, 2025
  25. Patrick SteinhardtFeb 5, 2025
  26. Toon ClaesFeb 5, 2025
  27. Jean-Noël AVILAFeb 5, 2025
  28. 3/7 clone: refactor wanted_peer_refs()Toon Claes, Feb 4, 2025
  29. 4/7 clone: add tags refspec earlier to fetch refspecToon Claes, Feb 4, 2025
  30. Patrick SteinhardtFeb 5, 2025
  31. 5/7 clone: introduce struct clone_opts in builtin/clone.cToon Claes, Feb 4, 2025
  32. 6/7 parse-options: introduce die_for_incompatible_opt2()Toon Claes, Feb 4, 2025
  33. Patrick SteinhardtFeb 5, 2025
  34. 7/7 builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Feb 4, 2025
  35. Patrick SteinhardtFeb 5, 2025
  36. Toon ClaesFeb 5, 2025
  37. Patrick SteinhardtFeb 5, 2025
  38. Junio C HamanoFeb 5, 2025
  39. 0/7 Enable doing a shallow clone of a specific git revisionToon Claes, Feb 5, 2025
  40. 1/7 clone: cut down on global variables in clone.cToon Claes, Feb 5, 2025
  41. 2/7 clone: make it possible to specify --tagsToon Claes, Feb 5, 2025
  42. 3/7 clone: refactor wanted_peer_refs()Toon Claes, Feb 5, 2025
  43. 4/7 clone: add tags refspec earlier to fetch refspecToon Claes, Feb 5, 2025
  44. 5/7 clone: introduce struct clone_opts in builtin/clone.cToon Claes, Feb 5, 2025
  45. 6/7 parse-options: introduce die_for_incompatible_opt2()Toon Claes, Feb 5, 2025
  46. 7/7 builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Feb 5, 2025
  47. Junio C HamanoFeb 5, 2025
  48. 0/7 Enable doing a shallow clone of a specific git revisionToon Claes, Feb 6, 2025
  49. 1/7 clone: cut down on global variables in clone.cToon Claes, Feb 6, 2025
  50. 2/7 clone: make it possible to specify --tagsToon Claes, Feb 6, 2025
  51. 3/7 clone: refactor wanted_peer_refs()Toon Claes, Feb 6, 2025
  52. 4/7 clone: add tags refspec earlier to fetch refspecToon Claes, Feb 6, 2025
  53. 5/7 clone: introduce struct clone_opts in builtin/clone.cToon Claes, Feb 6, 2025
  54. 6/7 parse-options: introduce die_for_incompatible_opt2()Toon Claes, Feb 6, 2025
  55. 7/7 builtin/clone: teach git-clone(1) the --revision= optionToon Claes, Feb 6, 2025
  56. Patrick SteinhardtFeb 6, 2025
  57. Junio C HamanoFeb 6, 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.