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

[PATCH] run_diff_files(): clarify computation of sha1 validity

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2015, 22:17 UTC
Message-ID
<xmqqtwz1mieb.fsf@gitster.dls.corp.google.com>

Remove the need to have duplicated "if there is a change then feed null_sha1 and otherwise sha1 from the cache entry" for the "new" side of the diff by introducing two temporary variables to point at the object name of the old and the new side of the blobs.

This does not intend to change the meaning of the code in any way; just makes the result a bit easier to read.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * A random thing I noticed while reading existing code...
 diff-lib.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index 875aff8..a85c497 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -101,6 +101,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		struct cache_entry *ce = active_cache[i];
 		int changed;
 		unsigned dirty_submodule = 0;
+		const unsigned char *old_sha1, *new_sha1;
 
 		if (diff_can_quit_early(&revs->diffopt))
 			break;
@@ -224,9 +225,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 		}
 		oldmode = ce->ce_mode;
+		old_sha1 = ce->sha1;
+		new_sha1 = changed ? null_sha1 : ce->sha1;
 		diff_change(&revs->diffopt, oldmode, newmode,
-			    ce->sha1, (changed ? null_sha1 : ce->sha1),
-			    !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)),
+			    old_sha1, new_sha1,
+			    !is_null_sha1(old_sha1),
+			    !is_null_sha1(new_sha1),
 			    ce->name, 0, dirty_submodule);
 
 	}
-- 
2.3.0-rc2-170-g6029c0c
Message 1 of 1 in “run_diff_files(): clarify computation of sha1 validity”
  1. run_diff_files(): clarify computation of sha1 validityJunio C Hamano, Feb 4, 2015

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.