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

Re: [PATCH v2 2/3] merge: split write_merge_state in two

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 22, 2017, 00:20 UTC
Message-ID
<xmqqshgk4fnt.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1fa72c32925d98a5ce8c96a2b504b2e4278dcfff.1503319519.git.git@grubix.eu>
Michael J Gruber <git@grubix.eu> writes:
Show 6 quoted lines
> write_merge_state() writes out the merge heads, mode, and msg. But we
> may want to write out heads, mode without the msg. So, split out heads
> (+mode) into a separate function write_merge_heads() that is called by
> write_merge_state().
>
> No funtional change so far.

"We may want to" leaves readers in suspense. Hopefully 3/3 makes it clear why we may in what situation.

One thing this changes is that we used to write merge-heads first, then message and then finally mode, but now we write merge-heads, then mode and finally message. So killing us in the middle may leave different set of files on the filesystem. It is unclear from the above description and the patch text if that is a potential issue.

Let's keep reading ;-)
Thanks.
Show 42 quoted lines
>
> Signed-off-by: Michael J Gruber <git@grubix.eu>
> ---
>  builtin/merge.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/merge.c b/builtin/merge.c
> index cc57052993..86f0adde3b 100644
> --- a/builtin/merge.c
> +++ b/builtin/merge.c
> @@ -908,7 +908,7 @@ static int setup_with_upstream(const char ***argv)
>  	return i;
>  }
>  
> -static void write_merge_state(struct commit_list *remoteheads)
> +static void write_merge_heads(struct commit_list *remoteheads)
>  {
>  	struct commit_list *j;
>  	struct strbuf buf = STRBUF_INIT;
> @@ -924,8 +924,6 @@ static void write_merge_state(struct commit_list *remoteheads)
>  		strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
>  	}
>  	write_file_buf(git_path_merge_head(), buf.buf, buf.len);
> -	strbuf_addch(&merge_msg, '\n');
> -	write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
>  
>  	strbuf_reset(&buf);
>  	if (fast_forward == FF_NO)
> @@ -933,6 +931,13 @@ static void write_merge_state(struct commit_list *remoteheads)
>  	write_file_buf(git_path_merge_mode(), buf.buf, buf.len);
>  }
>  
> +static void write_merge_state(struct commit_list *remoteheads)
> +{
> +	write_merge_heads(remoteheads);
> +	strbuf_addch(&merge_msg, '\n');
> +	write_file_buf(git_path_merge_msg(), merge_msg.buf, merge_msg.len);
> +}
> +
>  static int default_edit_option(void)
>  {
>  	static const char name[] = "GIT_MERGE_AUTOEDIT";
Previous: Michael J Gruber
Message 22 of 22 in “Git makes a merge commit but as a normal (non-merge) commit”
  1. hIpPyAug 18, 2017
  2. Michael J GruberAug 21, 2017
  3. merge: save merge state earlierMichael J Gruber, Aug 21, 2017
  4. 1/3 Documentation/git-merge: explain --continueMichael J Gruber, Aug 21, 2017
  5. Martin ÅgrenAug 21, 2017
  6. Michael J GruberAug 22, 2017
  7. Martin ÅgrenAug 22, 2017
  8. hIpPyAug 22, 2017
  9. Junio C HamanoAug 22, 2017
  10. 1/4 Documentation/git-merge: explain --continueMichael J Gruber, Aug 23, 2017
  11. 0/4 Keep merge during killsMichael J Gruber, Aug 23, 2017
  12. 2/4 merge: clarify call chainMichael J Gruber, Aug 23, 2017
  13. 3/4 merge: split write_merge_state in twoMichael J Gruber, Aug 23, 2017
  14. 4/4 merge: save merge state earlierMichael J Gruber, Aug 23, 2017
  15. Junio C HamanoAug 22, 2017
  16. 3/3 merge: save merge state earlierMichael J Gruber, Aug 21, 2017
  17. Junio C HamanoAug 22, 2017
  18. Michael J GruberAug 22, 2017
  19. Junio C HamanoAug 22, 2017
  20. 0/3 Keep merge during killsMichael J Gruber, Aug 21, 2017
  21. 2/3 merge: split write_merge_state in twoMichael J Gruber, Aug 21, 2017
  22. Junio C HamanoAug 22, 2017

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.