From: Junio C Hamano Date: Thu, 11 Dec 2014 21:11:06 +0000 (-0800) Subject: run_diff_files(): clarify computation of sha1 validity X-Git-Tag: v2.4.0-rc0~100^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0b86fe8923c25639f77d5f18f086c3346a5ccd61 run_diff_files(): clarify computation of sha1 validity 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. Signed-off-by: Junio C Hamano --- diff --git a/diff-lib.c b/diff-lib.c index 875aff8643..a85c4971ac 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); }