Skip to content

Commit 0ecd180

Browse files
stefanbellergitster
authored andcommitted
unpack-trees: simplify 'all other failures' case
In the 'if (current)' block of twoway_merge, we handle the boring errors by checking if the entry from the old tree, current index, and new tree are present, to get a pathname for the error message from one of them: if (oldtree) return o->gently ? -1 : reject_merge(oldtree, o); if (current) return o->gently ? -1 : reject_merge(current, o); if (newtree) return o->gently ? -1 : reject_merge(newtree, o); return -1; Since this is guarded by 'if (current)', the second test is guaranteed to succeed. Moreover, any of the three entries, if present, would have the same path because there is no rename detection in this code path. Even if some day in the future the entries' paths differ, the 'current' path used in the index and worktree would presumably be the most recognizable for the end user. Simplify by just using 'current'. Noticed by coverity, Id:290002 Signed-off-by: Stefan Beller <[email protected]> Improved-by: Junio C Hamano <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6aaa39 commit 0ecd180

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

unpack-trees.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,16 +1791,8 @@ int twoway_merge(const struct cache_entry * const *src,
17911791
/* 20 or 21 */
17921792
return merged_entry(newtree, current, o);
17931793
}
1794-
else {
1795-
/* all other failures */
1796-
if (oldtree)
1797-
return o->gently ? -1 : reject_merge(oldtree, o);
1798-
if (current)
1799-
return o->gently ? -1 : reject_merge(current, o);
1800-
if (newtree)
1801-
return o->gently ? -1 : reject_merge(newtree, o);
1802-
return -1;
1803-
}
1794+
else
1795+
return o->gently ? -1 : reject_merge(current, o);
18041796
}
18051797
else if (newtree) {
18061798
if (oldtree && !o->initial_checkout) {

0 commit comments

Comments
 (0)