git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, Markus Klein <markus.klein@reelworx.at>
Subject: Re: [PATCH v2 2/2] Avoid a segmentation fault with renaming merges
Date: Mon, 28 Nov 2016 10:42:02 -0800	[thread overview]
Message-ID: <xmqqmvgjjvk5.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1611261348420.117539@virtualbox> (Johannes Schindelin's message of "Sat, 26 Nov 2016 13:53:09 +0100 (CET)")

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> On Sat, 26 Nov 2016, Johannes Schindelin wrote:
>
>> diff --git a/merge-recursive.c b/merge-recursive.c
>> index 9041c2f149..609061f58a 100644
>> --- a/merge-recursive.c
>> +++ b/merge-recursive.c
>> @@ -235,6 +235,8 @@ static int add_cacheinfo(struct merge_options *o,
>>  		struct cache_entry *nce;
>>  
>>  		nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
>> +		if (!nce)
>> +			return err(o, _("addinfo: '%s' is not up-to-date"), path);
>>  		if (nce != ce)
>>  			ret = add_cache_entry(nce, options);
>>  	}
>
> BTW I was not quite sure why we need to refresh the cache entry here, and
> 1335d76e45 (merge: avoid "safer crlf" during recording of merge results,
> 2016-07-08) has a commit message for which I need some time to wrap my
> head around.

This callsite used to call make_cache_entry() with CE_MATCH_REFRESH,
which creates a new cache entry, calls refresh_cache_ent, and
returns the cache entry"; the log message attempts to explain why we
avoid passing CE_MATCH_REFRESH and instead first add it as a merged
entry and then refresh it (and re-add it if ce got changed).  We
used to leave the old (possibly conflicted) entries for the same
path in the index while refreshing the new cache entry, which has
correctly converted result, and the old entries got in the way,
attempting a wrong eol conversion and declaring that the new entry
out-of-date.  By adding the correctly converted result as a merged
entry, which gets rid of the old entries, the refresh operation will
not be corrupted by them.

> Also, an error here may be overkill. Maybe we should simply change the "if
> (nce != ce)" to an "if (nce && nce != ce)" here, as a locally-modified
> file will give a nicer message later, anyway.

Looking at the commit you blamed, what happened in this case before
that change was that

 (1) make_cache_entry() would have called refresh_cache_entry() with
     CE_MATCH_REFRESH and returned a NULL;

 (2) merge-recursive.c::add_cacheinfo() noticed NULL and did

     return error(_("addinfo_cache failed for path '%s'"), path)

But the updated code forgot that refresh_cache_entry() could return
NULL.  So 1335d76e45 ("merge: avoid "safer crlf" during recording of
merge results", 2016-07-08) was not a faithful rewrite.

So I agree that your patch is the right fix; using the old message
lost by mistake in 1335d76e45 may have made it more clear that this
is a fix for a misconversion in that commit, though.

In any case, this does not seem like a new regression (1/2 applied
on v2.10.0 dies the same way), so I am inclined to queue these two
but not ship in the upcoming release for now.

Thanks.


  reply	other threads:[~2016-11-28 18:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25 16:36 [PATCH 0/2] Fix segmentation fault with cherry-pick Johannes Schindelin
2016-11-25 16:36 ` [PATCH 1/2] cherry-pick: demonstrate a segmentation fault Johannes Schindelin
2016-11-26 12:47   ` Johannes Schindelin
2016-11-25 16:36 ` [PATCH 2/2] Avoid a segmentation fault with renaming merges Johannes Schindelin
2016-11-25 16:41 ` [PATCH 0/2] Fix segmentation fault with cherry-pick Johannes Schindelin
2016-11-26 12:47 ` [PATCH v2 " Johannes Schindelin
2016-11-26 12:48   ` [PATCH v2 1/2] cherry-pick: demonstrate a segmentation fault Johannes Schindelin
2016-11-26 12:48   ` [PATCH v2 2/2] Avoid a segmentation fault with renaming merges Johannes Schindelin
2016-11-26 12:53     ` Johannes Schindelin
2016-11-28 18:42       ` Junio C Hamano [this message]
2016-11-28 18:59         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmvgjjvk5.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=markus.klein@reelworx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).