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

Re: [PATCH v2 2/3] Allow for MERGE_MODE to specify more then one mode

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 28, 2012, 02:17 UTC
Message-ID
<7v7gp6jwsn.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1354057217-65886-3-git-send-email-draenog@pld-linux.org>
Kacper Kornet <draenog@pld-linux.org> writes:
Show 31 quoted lines
> Presently only one merge mode exists: non-fast-forward. But in future
> the second one (transpose-parents) will be added, so the need to read
> all lines of MERGE_MODE.
>
> Signed-off-by: Kacper Kornet <draenog@pld-linux.org>
> ---
>  builtin/commit.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 273332f..ee0e884 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1427,7 +1427,6 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  	unsigned char sha1[20];
>  	struct ref_lock *ref_lock;
>  	struct commit_list *parents = NULL, **pptr = &parents;
> -	struct stat statbuf;
>  	int allow_fast_forward = 1;
>  	struct commit *current_head = NULL;
>  	struct commit_extra_header *extra = NULL;
> @@ -1481,11 +1480,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  
>  		if (!reflog_msg)
>  			reflog_msg = "commit (merge)";
> -		if (!stat(git_path("MERGE_MODE"), &statbuf)) {
> -			if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
> -				die_errno(_("could not read MERGE_MODE"));
> -			if (!strcmp(sb.buf, "no-ff"))
> -				allow_fast_forward = 0;
> +		if((fp = fopen(git_path("MERGE_MODE"), "r"))) {
Style: s/if((fp/if ((fp/;
Show 5 quoted lines
> +			while (strbuf_getline(&m, fp, '\n') != EOF) {
> +				if (!strcmp(m.buf, "no-ff"))
> +					allow_fast_forward = 0;
> +			}
> +			fclose(fp);

This needs a bit more careful planning for interacting with other people's programs, I suspect.

Your updated builtin/merge.c may write an extra LF after no-ff to make this parser to grok it, but it is entirely plausible that people have their own Porcelain that writes "no-ff" without LF (because that is what we read from this file, and I suspect the current code would ignore "no-ff\n").

At least strbuf_getline() would give us "no-ff" when either "no-ff" or "no-ff\n" terminates the file, so updated code would be able to grok what other people would write, but if other people want to read MERGE_MODE we write, at least we shouldn't break them when we only write no-ff in it (once you start writing "reverse-parents" in the file, they will be broken anyway, as they do not currently expect such token in this file).

I am starting to wonder if this is worth it, though...
Previous: Kacper KornetNext: Kacper Kornet
Message 4 of 11 in “Add option to change order of parents in merge commit”
  1. 0/3 Add option to change order of parents in merge commitKacper Kornet, Nov 27, 2012
  2. 1/3 Process MERGE_MODE before MERGE_HEADKacper Kornet, Nov 27, 2012
  3. 2/3 Allow for MERGE_MODE to specify more then one modeKacper Kornet, Nov 27, 2012
  4. Junio C HamanoNov 28, 2012
  5. Kacper KornetNov 28, 2012
  6. Junio C HamanoNov 28, 2012
  7. 3/3 Add option to transpose parents of merge commitKacper Kornet, Nov 27, 2012
  8. Junio C HamanoNov 28, 2012
  9. Kacper KornetNov 28, 2012
  10. Johannes SixtNov 28, 2012
  11. Junio C HamanoNov 28, 2012

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.