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

Re: [PATCH v3 2/3] replay: make atomic ref updates the default behavior

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 13, 2025, 22:05 UTC
Message-ID
<xmqqms5uzcd7.fsf@gitster.g>
In-Reply-To
<20251013183311.33329-3-siddharthasthana31@gmail.com>
Siddharth Asthana <siddharthasthana31@gmail.com> writes:
Show 8 quoted lines
> For users needing the traditional pipeline workflow, add a new
> `--update-refs=<mode>` option that preserves the original behavior:
>
>   git replay --update-refs=print --onto main topic1..topic2 | git update-ref --stdin
>
> The mode can be:
>   * `yes` (default): Update refs directly using an atomic transaction
>   * `print`: Output update-ref commands for pipeline use

Is it only me who still finds this awkward? A question "update?" that gets answered "yes" is quite understandable, but it is not immediately obvious what it means to answer "print" to the same question. When the user gives the latter mode as the answer to the question, the question being answered is not really "do you want to update refs?" at all.

The question the command wants the user to answer is more like "what action do you want to see performed on the refs?", isn't it? The user would answer to the question with "please update them" to get the default mode, while "please print them" may be the answer the user would give to get the useful-for-dry-run-and-development mode.

Perhaps phrase it more like "--ref-action=(update|print)"?  I dunno.
Show 10 quoted lines
>  --advance <branch>::
>  	Starting point at which to create the new commits; must be a
>  	branch name.
>  +
> -When `--advance` is specified, the update-ref command(s) in the output
> -will update the branch passed as an argument to `--advance` to point at
> -the new commits (in other words, this mimics a cherry-pick operation).
> +When `--advance` is specified, the branch passed as an argument will be
> +updated to point at the new commits (or an update command will be printed
> +if `--update-refs=print` is used). This mimics a cherry-pick operation.

I do not find it clear what the reference to cherry-pick is trying to convey. It is like cherry-picking <something> while the <branch> is checked out (hence the branch advances as the result of acquiring these commits from <something>)? Let me see if I understood you by attempting to rephrase.

    The history is replayed on top of the <branch> and <branch> is
    updated to point at the tip of resulting history.

But what's the significance of saying so? Did you want to contrast it with "rebase --onto <branch>", i.e. merely specifying the starting point without <branch> itself moving as the result? If so, it is probably a notable distinction worth pointing out, but just saying "mimics a cherry-pick operation" alone is probably not enough to get the intended audience understand what you wanted to tell them.

    Side note.  I casually wrote "is updated to point" but with the
    option not to update (but show the way to update refs), we'd
    probably need to find a good phrase to express "where the
    command _wants_ to see the refs pointing at as the result",
    without referring to who/how the refs are made to point at these
    points.
> -To simply rebase `mybranch` onto `target`:
> +To simply rebase `mybranch` onto `target` (default behavior):
"the default"?
Show 27 quoted lines
> diff --git a/builtin/replay.c b/builtin/replay.c
> index b64fc72063..457225363e 100644
> --- a/builtin/replay.c
> +++ b/builtin/replay.c
> @@ -284,6 +284,26 @@ static struct commit *pick_regular_commit(struct repository *repo,
>  	return create_commit(repo, result->tree, pickme, replayed_base);
>  }
>  
> +static int handle_ref_update(const char *mode,
> +			     struct ref_transaction *transaction,
> +			     const char *refname,
> +			     const struct object_id *new_oid,
> +			     const struct object_id *old_oid,
> +			     struct strbuf *err)
> +{
> +	if (!strcmp(mode, "print")) {
> +		printf("update %s %s %s\n",
> +		       refname,
> +		       oid_to_hex(new_oid),
> +		       oid_to_hex(old_oid));
> +		return 0;
> +	}
> +
> +	/* mode == "yes" - update refs directly */
> +	return ref_transaction_update(transaction, refname, new_oid, old_oid,
> +				      NULL, NULL, 0, "git replay", err);
> +}
Hmph, would it be easier to follow if the above is symmetric, i.e.,
	if (...) {
		what happens in the "print" mode
	} else {
		what happens in the "update ourselves" mode
	}
I wonder?

In any case, do not pass mode as "const char *" around in the call chain. Instead, reduce it down to an enum or integer (with CPP macro) at the earliest possible place after you saw the command line option. That would allow you to even do

	switch (ref_action) {
	case PRINT_INSN:
		printf("update ...");
		return 0;
	case UPDATE_OURSELVES:
		return ref_transaction_update(...);
	default:
		BUG("Bad ref_action %d", ref_action);
	}
to future-proof for the third option.
Show 5 quoted lines
> +		OPT_STRING(0, "update-refs", &update_refs_mode,
> +			   N_("mode"),
> +			   N_("control ref update behavior (yes|print)")),
>  		OPT_END()
>  	};

This one is fine, but then immediately after parse_options() returns, do something like

	if (!strcmp(update_refs_mode, "print"))
		ref_action = PRINT_INSN;
	else if (!strcmp(update_refs_mode, "yes"))
		ref_action = UPDATE_OURSELVES;
	else
		die(_("unknown option --update-ref='%s'"),
		    update_refs_mode);

so that you do not have to keep strcmp() with "print", which risks you to mistype "prnit" and no compiler would protect against that.

Previous: Siddharth AsthanaNext: Siddharth Asthana
Message 65 of 125 in “replay: add --update-refs option”
  1. 0/2 replay: add --update-refs optionSiddharth Asthana, Sep 8, 2025
  2. 1/2 replay: add --update-refs optionSiddharth Asthana, Sep 8, 2025
  3. Patrick SteinhardtSep 8, 2025
  4. Siddharth AsthanaSep 9, 2025
  5. Patrick SteinhardtSep 9, 2025
  6. Elijah NewrenSep 9, 2025
  7. Siddharth AsthanaSep 10, 2025
  8. 2/2 replay: document --update-refs and --batch optionsSiddharth Asthana, Sep 8, 2025
  9. Christian CouderSep 8, 2025
  10. Siddharth AsthanaSep 9, 2025
  11. Christian CouderSep 9, 2025
  12. Siddharth AsthanaSep 10, 2025
  13. Kristoffer HaugsbakkSep 8, 2025
  14. Siddharth AsthanaSep 9, 2025
  15. Andrei RybakSep 9, 2025
  16. Siddharth AsthanaSep 10, 2025
  17. Christian CouderSep 8, 2025
  18. Siddharth AsthanaSep 9, 2025
  19. Kristoffer HaugsbakkSep 8, 2025
  20. Siddharth AsthanaSep 9, 2025
  21. Elijah NewrenSep 9, 2025
  22. Christian CouderSep 9, 2025
  23. Elijah NewrenSep 9, 2025
  24. Junio C HamanoSep 9, 2025
  25. Elijah NewrenSep 9, 2025
  26. 0/1 replay: make atomic ref updates the default behaviorSiddharth Asthana, Sep 26, 2025
  27. 1/1 replay: make atomic ref updates the default behaviorSiddharth Asthana, Sep 26, 2025
  28. Christian CouderSep 30, 2025
  29. Siddharth AsthanaOct 2, 2025
  30. Christian CouderOct 3, 2025
  31. Elijah NewrenOct 2, 2025
  32. Christian CouderOct 3, 2025
  33. Phillip WoodSep 30, 2025
  34. Karthik NayakOct 2, 2025
  35. Siddharth AsthanaOct 2, 2025
  36. Siddharth AsthanaOct 2, 2025
  37. Phillip WoodOct 8, 2025
  38. Siddharth AsthanaOct 8, 2025
  39. Elijah NewrenOct 8, 2025
  40. Siddharth AsthanaOct 8, 2025
  41. Phillip WoodOct 9, 2025
  42. Elijah NewrenOct 2, 2025
  43. Junio C HamanoOct 2, 2025
  44. Siddharth AsthanaOct 2, 2025
  45. Siddharth AsthanaOct 2, 2025
  46. Christian CouderOct 3, 2025
  47. Siddharth AsthanaOct 8, 2025
  48. Elijah NewrenOct 3, 2025
  49. Junio C HamanoOct 3, 2025
  50. Siddharth AsthanaOct 8, 2025
  51. Junio C HamanoOct 8, 2025
  52. Siddharth AsthanaOct 8, 2025
  53. Elijah NewrenOct 8, 2025
  54. Siddharth AsthanaOct 8, 2025
  55. Kristoffer HaugsbakkOct 2, 2025
  56. Siddharth AsthanaOct 2, 2025
  57. Kristoffer HaugsbakkOct 3, 2025
  58. Siddharth AsthanaOct 8, 2025
  59. Elijah NewrenOct 8, 2025
  60. Kristoffer HaugsbakkOct 8, 2025
  61. Siddharth AsthanaOct 8, 2025
  62. 0/3 replay: make atomic ref updates the defaultSiddharth Asthana, Oct 13, 2025
  63. 1/3 replay: use die_for_incompatible_opt2() for option validationSiddharth Asthana, Oct 13, 2025
  64. 2/3 replay: make atomic ref updates the default behaviorSiddharth Asthana, Oct 13, 2025
  65. Junio C HamanoOct 13, 2025
  66. Siddharth AsthanaOct 15, 2025
  67. 3/3 replay: add replay.defaultAction config optionSiddharth Asthana, Oct 13, 2025
  68. Junio C HamanoOct 13, 2025
  69. Siddharth AsthanaOct 15, 2025
  70. Christian CouderOct 15, 2025
  71. Junio C HamanoOct 15, 2025
  72. 0/3 replay: make atomic ref updates the defaultSiddharth Asthana, Oct 22, 2025
  73. 1/3 replay: use die_for_incompatible_opt2() for option validationSiddharth Asthana, Oct 22, 2025
  74. 2/3 replay: make atomic ref updates the default behaviorSiddharth Asthana, Oct 22, 2025
  75. Junio C HamanoOct 22, 2025
  76. Siddharth AsthanaOct 28, 2025
  77. Christian CouderOct 24, 2025
  78. Junio C HamanoOct 24, 2025
  79. Siddharth AsthanaOct 28, 2025
  80. Siddharth AsthanaOct 28, 2025
  81. 3/3 replay: add replay.refAction config optionSiddharth Asthana, Oct 22, 2025
  82. Christian CouderOct 24, 2025
  83. Junio C HamanoOct 24, 2025
  84. Siddharth AsthanaOct 28, 2025
  85. Siddharth AsthanaOct 28, 2025
  86. Phillip WoodOct 24, 2025
  87. Phillip WoodOct 24, 2025
  88. Siddharth AsthanaOct 28, 2025
  89. Siddharth AsthanaOct 28, 2025
  90. Junio C HamanoOct 23, 2025
  91. Junio C HamanoOct 25, 2025
  92. Siddharth AsthanaOct 28, 2025
  93. Christian CouderOct 24, 2025
  94. 0/3 replay: make atomic ref updates the defaultSiddharth Asthana, Oct 28, 2025
  95. 1/3 replay: use die_for_incompatible_opt2() for option validationSiddharth Asthana, Oct 28, 2025
  96. 2/3 replay: make atomic ref updates the default behaviorSiddharth Asthana, Oct 28, 2025
  97. 3/3 replay: add replay.refAction config optionSiddharth Asthana, Oct 28, 2025
  98. Christian CouderOct 29, 2025
  99. Siddharth AsthanaOct 29, 2025
  100. 0/3 replay: make atomic ref updates the defaultSiddharth Asthana, Oct 30, 2025
  101. 1/3 replay: use die_for_incompatible_opt2() for option validationSiddharth Asthana, Oct 30, 2025
  102. Elijah NewrenOct 31, 2025
  103. Siddharth AsthanaNov 5, 2025
  104. 2/3 replay: make atomic ref updates the default behaviorSiddharth Asthana, Oct 30, 2025
  105. Elijah NewrenOct 31, 2025
  106. Junio C HamanoOct 31, 2025
  107. Siddharth AsthanaNov 5, 2025
  108. Phillip WoodNov 3, 2025
  109. Siddharth AsthanaNov 3, 2025
  110. Phillip WoodNov 4, 2025
  111. 3/3 replay: add replay.refAction config optionSiddharth Asthana, Oct 30, 2025
  112. Christian CouderOct 31, 2025
  113. Siddharth AsthanaNov 5, 2025
  114. Elijah NewrenOct 31, 2025
  115. Siddharth AsthanaNov 5, 2025
  116. Elijah NewrenOct 31, 2025
  117. 0/3 replay: make atomic ref updates the defaultSiddharth Asthana, Nov 5, 2025
  118. 1/3 replay: use die_for_incompatible_opt2() for option validationSiddharth Asthana, Nov 5, 2025
  119. 2/3 replay: make atomic ref updates the default behaviorSiddharth Asthana, Nov 5, 2025
  120. 3/3 replay: add replay.refAction config optionSiddharth Asthana, Nov 5, 2025
  121. Elijah NewrenNov 6, 2025
  122. Siddharth AsthanaNov 8, 2025
  123. Elijah NewrenNov 8, 2025
  124. Phillip WoodNov 7, 2025
  125. Siddharth AsthanaNov 8, 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.