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

Re: [PATCH 2/2] Loop index increases monotonically when reading unmerged entries

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 25, 2014, 17:09 UTC
Message-ID
<xmqq1ts4o5qw.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAPuZ2NEPcRm4S8m76kJ+8L7zR2RiVwu3Z6bNbZgfzAcVTYgOKA@mail.gmail.com>
Jaime Soriano Pastor <jsorianopastor@gmail.com> writes:
Show 21 quoted lines
> 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.
Show 6 quoted lines
>>         }
>>         return unmerged;
>>  }
>> --
>> 2.0.4.1.g0b8a4f9.dirty
>>
Previous: Jaime Soriano PastorNext: Junio C Hamano
Message 30 of 51 in “read-cache.c: Ensure unmerged entries are removed”
  1. read-cache.c: Ensure unmerged entries are removedJaime Soriano Pastor, Aug 12, 2014
  2. read-cache.c: Ensure unmerged entries are removedJaime Soriano Pastor, Aug 12, 2014
  3. Junio C HamanoAug 12, 2014
  4. Jaime Soriano PastorAug 13, 2014
  5. Junio C HamanoAug 13, 2014
  6. Jaime Soriano PastorAug 15, 2014
  7. Junio C HamanoAug 15, 2014
  8. Jaime Soriano PastorAug 16, 2014
  9. Junio C HamanoAug 18, 2014
  10. Jaime Soriano PastorAug 18, 2014
  11. 0/4 Handling unmerged files with merged entriesJaime Soriano Pastor, Aug 20, 2014
  12. 1/4 read_index_unmerged doesn't loop forever if merged stage exists for unmerged fileJaime Soriano Pastor, Aug 20, 2014
  13. 2/4 Error out when adding a file with merged and unmerged entriesJaime Soriano Pastor, Aug 20, 2014
  14. 3/4 Added tests for the case of merged and unmerged entries for the same fileJaime Soriano Pastor, Aug 20, 2014
  15. Junio C HamanoAug 20, 2014
  16. Jaime Soriano PastorAug 21, 2014
  17. Junio C HamanoAug 21, 2014
  18. 4/4 git update-index --cacheinfo can be used to select a stage when there are merged and unmerged entriesJaime Soriano Pastor, Aug 20, 2014
  19. Junio C HamanoAug 20, 2014
  20. Jaime Soriano PastorAug 21, 2014
  21. Junio C HamanoAug 20, 2014
  22. Jaime Soriano PastorAug 21, 2014
  23. Check order when reading indexJaime Soriano Pastor, Aug 21, 2014
  24. Jaime Soriano PastorAug 21, 2014
  25. Duy NguyenAug 21, 2014
  26. Junio C HamanoAug 21, 2014
  27. 1/2 Check order when reading indexJaime Soriano Pastor, Aug 24, 2014
  28. 2/2 Loop index increases monotonically when reading unmerged entriesJaime Soriano Pastor, Aug 24, 2014
  29. Jaime Soriano PastorAug 24, 2014
  30. Junio C HamanoAug 25, 2014
  31. Junio C HamanoAug 25, 2014
  32. Jeff KingAug 25, 2014
  33. Junio C HamanoAug 25, 2014
  34. Jaime Soriano PastorAug 26, 2014
  35. Jeff KingAug 26, 2014
  36. Junio C HamanoAug 26, 2014
  37. Jaime Soriano PastorAug 26, 2014
  38. Junio C HamanoAug 26, 2014
  39. 1/2 read_index_from(): catch out of order entries when reading an index fileJaime Soriano Pastor, Aug 27, 2014
  40. 2/2 read_index_unmerged(): remove unnecessary loop index adjustmentJaime Soriano Pastor, Aug 27, 2014
  41. Eric SunshineAug 29, 2014
  42. read_index_from(): catch out of order entries when reading an index fileJaime Soriano Pastor, Aug 29, 2014
  43. Junio C HamanoAug 29, 2014
  44. Jaime Soriano PastorAug 27, 2014
  45. Junio C HamanoAug 27, 2014
  46. Jaime Soriano PastorAug 27, 2014
  47. Jaime Soriano PastorAug 25, 2014
  48. Johannes SixtAug 21, 2014
  49. Junio C HamanoAug 21, 2014
  50. Junio C HamanoAug 12, 2014
  51. Jaime Soriano PastorAug 13, 2014

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.