All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jaime Soriano Pastor <jsorianopastor@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] Loop index increases monotonically when reading unmerged entries
Date: Mon, 25 Aug 2014 10:09:59 -0700	[thread overview]
Message-ID: <xmqq1ts4o5qw.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <CAPuZ2NEPcRm4S8m76kJ+8L7zR2RiVwu3Z6bNbZgfzAcVTYgOKA@mail.gmail.com> (Jaime Soriano Pastor's message of "Sun, 24 Aug 2014 20:04:22 +0200")

Jaime Soriano Pastor <jsorianopastor@gmail.com> writes:

> I think this line is dangerous, if add_cache_entry is not able to
> remove higher-stages it will be looping forever, as happens in the
> case of this thread.
> I cannot see why it's even needed, and removing it doesn't break any test.
>
> On Sun, Aug 24, 2014 at 7:57 PM, Jaime Soriano Pastor
> <jsorianopastor@gmail.com> wrote:
>> Signed-off-by: Jaime Soriano Pastor <jsorianopastor@gmail.com>
>> ---
>>  read-cache.c | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/read-cache.c b/read-cache.c
>> index c1a9619..3d70386 100644
>> --- a/read-cache.c
>> +++ b/read-cache.c
>> @@ -1971,7 +1971,6 @@ int read_index_unmerged(struct index_state *istate)
>>                 if (add_index_entry(istate, new_ce, 0))
>>                         return error("%s: cannot drop to stage #0",
>>                                      new_ce->name);
>> -               i = index_name_pos(istate, new_ce->name, len);

I think the original idea was that regardless of how many entries
with the same name were removed because of the replacement (or
addition) of "new_ce", by making "i" point at the newly added
"new_ce", we would make sure that the loop will continue from the
next entry.  The if/return expected that add_index_entry() will get
rid of all the other entries with the same name as "new_ce" has or it
will return an error.

Without the "bug" in add_index_entry(), because "new_ce" always has
the same name as "ce", the entry we found at "i" by the loop, we know
that index_name_pos() will give the same "i" we already have, so
removing this line should be a no-op.

Now, add_index_entry() in your case did not notice that it failed to
remove all other entries with the same name as "new_ce", resulting
in your "looping forever".  Among the "merged and unmerged entries
with the same name exists in the index file" class of index file
corruption, we could treat the "merged and unmerged entries with the
same name not just exists but next to each other, unmerged ones
coming immediately after merged one" case specially (i.e. declaring
that it is more likely for a broken software to leave both next to
each other than otherwise) and try to accomodate it as your original
patch did.  I am not absolutely sure if such a special case is worth
it, and with your updated "[1/2] read_index_from(): check order of
entries when reading index" we will not be doing so, which is good.

With that safety in place, the "bug" in add_index_entry() will
disappear; it is safe not to adjust "i" by calling index_name_pos()
and this patch, "[2/2] read_index_unmerged(): remove unnecessary
loop index adjustment", will be a good thing to do.

Thanks.

>>         }
>>         return unmerged;
>>  }
>> --
>> 2.0.4.1.g0b8a4f9.dirty
>>

  reply	other threads:[~2014-08-25 17:11 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12 15:31 [PATCH] read-cache.c: Ensure unmerged entries are removed Jaime Soriano Pastor
2014-08-12 15:31 ` Jaime Soriano Pastor
2014-08-12 18:39   ` Junio C Hamano
2014-08-13 22:10     ` Jaime Soriano Pastor
2014-08-13 23:04       ` Junio C Hamano
2014-08-15 19:50         ` Jaime Soriano Pastor
2014-08-15 21:45           ` Junio C Hamano
2014-08-16 14:51             ` Jaime Soriano Pastor
2014-08-18 16:34               ` Junio C Hamano
2014-08-18 17:23                 ` Jaime Soriano Pastor
2014-08-20 11:25                   ` [PATCH 0/4] Handling unmerged files with merged entries Jaime Soriano Pastor
2014-08-20 11:26                     ` [PATCH 1/4] read_index_unmerged doesn't loop forever if merged stage exists for unmerged file Jaime Soriano Pastor
2014-08-20 11:26                     ` [PATCH 2/4] Error out when adding a file with merged and unmerged entries Jaime Soriano Pastor
2014-08-20 11:26                     ` [PATCH 3/4] Added tests for the case of merged and unmerged entries for the same file Jaime Soriano Pastor
2014-08-20 21:00                       ` Junio C Hamano
2014-08-21 13:51                         ` Jaime Soriano Pastor
2014-08-21 22:21                           ` Junio C Hamano
2014-08-20 11:26                     ` [PATCH 4/4] git update-index --cacheinfo can be used to select a stage when there are merged and unmerged entries Jaime Soriano Pastor
2014-08-20 21:08                       ` Junio C Hamano
2014-08-21 13:57                         ` Jaime Soriano Pastor
2014-08-20 22:19                     ` [PATCH 0/4] Handling unmerged files with merged entries Junio C Hamano
2014-08-21 13:42                       ` Jaime Soriano Pastor
2014-08-21 13:43                         ` [PATCH] Check order when reading index Jaime Soriano Pastor
2014-08-21 13:49                           ` Jaime Soriano Pastor
2014-08-21 13:59                           ` Duy Nguyen
2014-08-21 18:51                           ` Junio C Hamano
2014-08-24 17:57                             ` [PATCH 1/2] " Jaime Soriano Pastor
2014-08-24 17:57                               ` [PATCH 2/2] Loop index increases monotonically when reading unmerged entries Jaime Soriano Pastor
2014-08-24 18:04                                 ` Jaime Soriano Pastor
2014-08-25 17:09                                   ` Junio C Hamano [this message]
2014-08-25 17:21                               ` [PATCH 1/2] Check order when reading index Junio C Hamano
2014-08-25 19:44                                 ` Jeff King
2014-08-25 20:52                                   ` Junio C Hamano
2014-08-26 12:08                                     ` Jaime Soriano Pastor
2014-08-26 12:20                                       ` Jeff King
2014-08-26 16:53                                         ` Junio C Hamano
2014-08-26 17:22                                           ` Jaime Soriano Pastor
2014-08-26 17:43                                             ` Junio C Hamano
2014-08-27 19:48                                               ` [PATCH 1/2] read_index_from(): catch out of order entries when reading an index file Jaime Soriano Pastor
2014-08-27 19:48                                                 ` [PATCH 2/2] read_index_unmerged(): remove unnecessary loop index adjustment Jaime Soriano Pastor
2014-08-29  2:16                                                 ` [PATCH 1/2] read_index_from(): catch out of order entries when reading an index file Eric Sunshine
2014-08-29  8:54                                                   ` [PATCH] " Jaime Soriano Pastor
2014-08-29 17:06                                                     ` Junio C Hamano
2014-08-27 19:52                                               ` [PATCH 1/2] Check order when reading index Jaime Soriano Pastor
2014-08-27 21:11                                                 ` Junio C Hamano
2014-08-27 22:13                                                   ` Jaime Soriano Pastor
2014-08-25 20:26                                 ` Jaime Soriano Pastor
2014-08-21 18:40                       ` [PATCH 0/4] Handling unmerged files with merged entries Johannes Sixt
2014-08-21 22:18                         ` Junio C Hamano
2014-08-12 18:31 ` [PATCH] read-cache.c: Ensure unmerged entries are removed Junio C Hamano
2014-08-13 22:10   ` Jaime Soriano Pastor

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

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

  git send-email \
    --in-reply-to=xmqq1ts4o5qw.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jsorianopastor@gmail.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.