git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Stefan Beller <stefanbeller@gmail.com>
Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de,
	barkalow@iabervon.org, git@vger.kernel.org
Subject: [PATCH 1/3] unpack-trees: simplify 'all other failures' case
Date: Tue, 12 Aug 2014 16:59:31 -0700	[thread overview]
Message-ID: <20140812235931.GE24621@google.com> (raw)
In-Reply-To: <20140812235731.GD24621@google.com>

From: Stefan Beller <stefanbeller@gmail.com>

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 <stefanbeller@gmail.com>
Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 unpack-trees.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index ad3e9a0..f4a9aa9 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1791,16 +1791,8 @@ int twoway_merge(const struct cache_entry * const *src,
 			/* 20 or 21 */
 			return merged_entry(newtree, current, o);
 		}
-		else {
-			/* all other failures */
-			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;
-		}
+		else
+			return o->gently ? -1 : reject_merge(current, o);
 	}
 	else if (newtree) {
 		if (oldtree && !o->initial_checkout) {
-- 

  reply	other threads:[~2014-08-12 23:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-11 19:44 [PATCH] unpack-tree.c: remove dead code Stefan Beller
2014-08-12 18:13 ` Junio C Hamano
2014-08-12 21:15   ` Stefan Beller
2014-08-12 22:24     ` Junio C Hamano
2014-08-12 23:57     ` [PATCH 0/3] " Jonathan Nieder
2014-08-12 23:59       ` Jonathan Nieder [this message]
2014-08-13  0:00       ` [PATCH 2/3] unpack-trees: use 'cuddled' style for if-else cascade Jonathan Nieder
2014-08-13 14:52         ` Ronnie Sahlberg
2014-08-13  0:03       ` [PATCH 3/3] checkout -m: attempt merge when deletion of path was staged Jonathan Nieder
2014-08-13  0:38         ` Junio C Hamano
2014-08-13 17:48         ` Junio C Hamano
2014-08-13 18:59           ` Junio C Hamano
2014-08-13 19:30             ` Johannes Sixt
2014-08-13 20:02               ` Junio C Hamano
2014-08-13  6:41       ` [PATCH 0/3] Re: [PATCH] unpack-tree.c: remove dead code Stefan Beller

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=20140812235931.GE24621@google.com \
    --to=jrnieder@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stefanbeller@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 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 NNTP newsgroup(s).