merge-recursive: clarify code in was_tracked()
It can be puzzling to see that was_tracked() asks to get an index entry by name, but does not take a negative return value for an answer. The reason we have to do this is that cache_name_pos() only looks for entries in stage 0, even if nobody asked for any stage in particular. Let's rewrite the logic a little bit, to handle the easy case early: if cache_name_pos() returned a non-negative position, we know it is a match, and we do not even have to compare the name again (cache_name_pos() did that for us already). We can say right away: yes, this file was tracked. Only if there was no exact match do we need to look harder for any matching entry in stage 2. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7e97e10033
commit
f8d83fb66c
@ -667,23 +667,21 @@ static int was_tracked(const char *path)
|
|||||||
{
|
{
|
||||||
int pos = cache_name_pos(path, strlen(path));
|
int pos = cache_name_pos(path, strlen(path));
|
||||||
|
|
||||||
if (pos < 0)
|
if (0 <= pos)
|
||||||
pos = -1 - pos;
|
/* we have been tracking this path */
|
||||||
while (pos < active_nr &&
|
return 1;
|
||||||
!strcmp(path, active_cache[pos]->name)) {
|
|
||||||
/*
|
/*
|
||||||
* If stage #0, it is definitely tracked.
|
* Look for an unmerged entry for the path,
|
||||||
* If it has stage #2 then it was tracked
|
* specifically stage #2, which would indicate
|
||||||
* before this merge started. All other
|
* that "our" side before the merge started
|
||||||
* cases the path was not tracked.
|
* had the path tracked (and resulted in a conflict).
|
||||||
*/
|
*/
|
||||||
switch (ce_stage(active_cache[pos])) {
|
for (pos = -1 - pos;
|
||||||
case 0:
|
pos < active_nr && !strcmp(path, active_cache[pos]->name);
|
||||||
case 2:
|
pos++)
|
||||||
|
if (ce_stage(active_cache[pos]) == 2)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user