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

[PATCH] diff: remove another ternary expression always evaluating to true

From
Stefan Beller <stefanbeller@googlemail.com>
Date
Aug 8, 2013, 18:55 UTC
Message-ID
<1375988103-29947-1-git-send-email-stefanbeller@googlemail.com>

The condition before the changed line dereferences 'one' to query the mode, so if the condition evaluates to true, the variable one must not be null. Therefore we do not need the ternary operator depending on one, giving either one->path or two->path. This always evaluates to one->path, so we can remove the ternary operator.

The condition and the usage of the ternary operator have been introduced by the same commit (752c0c24, 2009-10-19, Add the --submodule option to the diff option family). As that commit message refers to a GitTogether I'd assume that patch was crafted in a hurry, so maybe overlooking the need for a ternary operator there.

Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
---
 diff.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 80f8439..f30b7e4 100644
--- a/diff.c
+++ b/diff.c
@@ -2252,8 +2252,7 @@ static void builtin_diff(const char *name_a,
 			(!two->mode || S_ISGITLINK(two->mode))) {
 		const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);
 		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
-		show_submodule_summary(o->file, one ? one->path : two->path,
-				line_prefix,
+		show_submodule_summary(o->file, one->path, line_prefix,
 				one->sha1, two->sha1, two->dirty_submodule,
 				meta, del, add, reset);
 		return;
-- 
1.8.4.rc1.25.gd121ba2
Next: Johannes Schindelin
Message 1 of 8 in “diff: remove another ternary expression always evaluating to true”
  1. diff: remove another ternary expression always evaluating to trueStefan Beller, Aug 8, 2013
  2. Johannes SchindelinAug 8, 2013
  3. Stefan BellerAug 8, 2013
  4. Johannes SchindelinAug 8, 2013
  5. Junio C HamanoAug 8, 2013
  6. diff: fix a possible null pointer dereferenceStefan Beller, Aug 8, 2013
  7. Philip OakleyAug 8, 2013
  8. Stefan BellerAug 8, 2013

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.