{"thread":{"id":"38500","subject":"[PATCH] run_diff_files(): clarify computation of sha1 validity","startedAt":"2015-02-04T22:17:00Z","lastAt":"2015-02-04T22:17:00Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"255612","messageId":"xmqqtwz1mieb.fsf@gitster.dls.corp.google.com","threadId":"38500","inReplyTo":null,"subject":"[PATCH] run_diff_files(): clarify computation of sha1 validity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-04T22:17:00Z","receivedAt":"2015-02-04T22:17:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Remove the need to have duplicated \"if there is a change then feed\nnull_sha1 and otherwise sha1 from the cache entry\" for the \"new\"\nside of the diff by introducing two temporary variables to point\nat the object name of the old and the new side of the blobs.\n\nThis does not intend to change the meaning of the code in any way;\njust makes the result a bit easier to read.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * A random thing I noticed while reading existing code...\n\n diff-lib.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 875aff8..a85c497 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -101,6 +101,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\tstruct cache_entry *ce = active_cache[i];\n \t\tint changed;\n \t\tunsigned dirty_submodule = 0;\n+\t\tconst unsigned char *old_sha1, *new_sha1;\n \n \t\tif (diff_can_quit_early(&revs->diffopt))\n \t\t\tbreak;\n@@ -224,9 +225,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\t\tcontinue;\n \t\t}\n \t\toldmode = ce->ce_mode;\n+\t\told_sha1 = ce->sha1;\n+\t\tnew_sha1 = changed ? null_sha1 : ce->sha1;\n \t\tdiff_change(&revs->diffopt, oldmode, newmode,\n-\t\t\t    ce->sha1, (changed ? null_sha1 : ce->sha1),\n-\t\t\t    !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)),\n+\t\t\t    old_sha1, new_sha1,\n+\t\t\t    !is_null_sha1(old_sha1),\n+\t\t\t    !is_null_sha1(new_sha1),\n \t\t\t    ce->name, 0, dirty_submodule);\n \n \t}\n-- \n2.3.0-rc2-170-g6029c0c\n"}]}