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

Re: [PATCH v3 07/18] rerere: stop looping unnecessarily

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 24, 2015, 20:06 UTC
Message-ID
<xmqq380dmiau.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1437171880-21590-8-git-send-email-gitster@pobox.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 39 quoted lines
> handle_cache() loops 3 times starting from an index entry that is
> unmerged, while ignoring an entry for a path that is different from
> what we are looking for.
>
> As the index is sorted, once we see a different path, we know we saw
> all stages for the path we are interested in.  Just loop while we
> see the same path and then break, instead of continuing for 3 times.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  rerere.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/rerere.c b/rerere.c
> index 4c45f55..7b1419c 100644
> --- a/rerere.c
> +++ b/rerere.c
> @@ -329,24 +329,21 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
>  		return -1;
>  	pos = -pos - 1;
>  
> -	for (i = 0; i < 3; i++) {
> +	while (pos < active_nr) {
>  		enum object_type type;
>  		unsigned long size;
> -		int j;
>  
> -		if (active_nr <= pos)
> -			break;
>  		ce = active_cache[pos++];
>  		if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
> -			continue;
> -		j = ce_stage(ce) - 1;
> -		mmfile[j].ptr = read_sha1_file(ce->sha1, &type, &size);
> -		mmfile[j].size = size;
> +			break;
> +		i = ce_stage(ce) - 1;
> +		mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
> +		mmfile[i].size = size;

If the conflicted index has multiple stage #1 entries, this will leak what was previously read. As the array is initialized to NULLs, perhaps

	i = ce_stage(ce) - 1;
        if (!mmfile[i].ptr) {
		mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
                mmfile[i].size = size;
	}

should be sufficient. This does change the semantics, in that we used to use the last stage #1 entry as the common ancestor when doing the plain-vanilla three-way merge, but with the leak fix, we will use the first stage #1 entry. But it does not change it in any meaningful way---we are using only one of multiple stage #1 entries arbitrarily picked either way.

Show 10 quoted lines
>  	}
> -	for (i = 0; i < 3; i++) {
> +	for (i = 0; i < 3; i++)
>  		if (!mmfile[i].ptr && !mmfile[i].size)
>  			mmfile[i].ptr = xstrdup("");
> -	}
> +
>  	/*
>  	 * NEEDSWORK: handle conflicts from merges with
>  	 * merge.renormalize set, too
Previous: Junio C HamanoNext: Junio C Hamano
Message 26 of 39 in “"rerere" minor clean-up”
  1. 00/13 "rerere" minor clean-upJunio C Hamano, Jul 1, 2015
  2. 01/13 rerere: fix an off-by-one non-bugJunio C Hamano, Jul 1, 2015
  3. 02/13 rerere: plug conflict ID leaksJunio C Hamano, Jul 1, 2015
  4. 03/13 rerere: lift PATH_MAX limitationJunio C Hamano, Jul 1, 2015
  5. 04/13 rerere: write out each record of MERGE_RR in one goJunio C Hamano, Jul 1, 2015
  6. 05/13 rerere: report autoupdated paths only after actually updating themJunio C Hamano, Jul 1, 2015
  7. 06/13 rerere: drop want_sp parameter from is_cmarker()Junio C Hamano, Jul 1, 2015
  8. 07/13 rerere: stop looping unnecessarilyJunio C Hamano, Jul 1, 2015
  9. 08/13 rerere: explain the rerere I/O abstractionJunio C Hamano, Jul 1, 2015
  10. 09/13 rerere: explain MERGE_RR management helpersJunio C Hamano, Jul 1, 2015
  11. 10/13 rerere: explain the primary codepathJunio C Hamano, Jul 1, 2015
  12. 11/13 rerere: explain "rerere forget" codepathJunio C Hamano, Jul 1, 2015
  13. 12/13 rerere: explain the remainderJunio C Hamano, Jul 1, 2015
  14. 13/13 rerere: refactor "replay" part of do_plain_rerere()Junio C Hamano, Jul 1, 2015
  15. 00/18 "rerere" preparatory clean-upJunio C Hamano, Jul 17, 2015
  16. 01/18 rerere: fix an off-by-one non-bugJunio C Hamano, Jul 17, 2015
  17. Junio C HamanoJul 24, 2015
  18. 02/18 rerere: plug conflict ID leaksJunio C Hamano, Jul 17, 2015
  19. 03/18 rerere: lift PATH_MAX limitationJunio C Hamano, Jul 17, 2015
  20. 04/18 rerere: write out each record of MERGE_RR in one goJunio C Hamano, Jul 17, 2015
  21. 05/18 rerere: report autoupdated paths only after actually updating themJunio C Hamano, Jul 17, 2015
  22. 06/18 rerere: drop want_sp parameter from is_cmarker()Junio C Hamano, Jul 17, 2015
  23. Philip OakleyJul 18, 2015
  24. Eric SunshineJul 18, 2015
  25. 07/18 rerere: stop looping unnecessarilyJunio C Hamano, Jul 17, 2015
  26. Junio C HamanoJul 24, 2015
  27. 08/18 rerere: explain the rerere I/O abstractionJunio C Hamano, Jul 17, 2015
  28. Junio C HamanoJul 24, 2015
  29. 09/18 rerere: explain MERGE_RR management helpersJunio C Hamano, Jul 17, 2015
  30. 10/18 rerere: explain the primary codepathJunio C Hamano, Jul 17, 2015
  31. 11/18 rerere: explain "rerere forget" codepathJunio C Hamano, Jul 17, 2015
  32. 12/18 rerere: explain the remainderJunio C Hamano, Jul 17, 2015
  33. 13/18 rerere: refactor "replay" part of do_plain_rerere()Junio C Hamano, Jul 17, 2015
  34. 14/18 rerere: further de-dent do_plain_rerere()Junio C Hamano, Jul 17, 2015
  35. 15/18 rerere: further clarify do_rerere_one_path()Junio C Hamano, Jul 17, 2015
  36. 16/18 rerere: call conflict-ids IDsJunio C Hamano, Jul 17, 2015
  37. 17/18 rerere: use "struct rerere_id" instead of "char *" for conflict IDJunio C Hamano, Jul 17, 2015
  38. Eric SunshineJul 18, 2015
  39. 18/18 rerere: un-nest merge() furtherJunio C Hamano, Jul 17, 2015

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.