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 <gitster@pobox.com>
Junio C Hamano committed
Dec 11, 2014 at 13:11 UTC
0b86fe8923c25639f77d5f18f086c3346a5ccd61
1 file changed
+6
-2
diff-lib.c
+6
-2
@@ -101,6 +101,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
101
struct cache_entry *ce = active_cache[i];
102
int changed;
103
unsigned dirty_submodule = 0;
104
+ const unsigned char *old_sha1, *new_sha1;
105
106
if (diff_can_quit_early(&revs->diffopt))
107
break;
@@ -224,9 +225,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
225
continue;
226
}
227
oldmode = ce->ce_mode;
228
+ old_sha1 = ce->sha1;
229
+ new_sha1 = changed ? null_sha1 : ce->sha1;
230
diff_change(&revs->diffopt, oldmode, newmode,
228
- ce->sha1, (changed ? null_sha1 : ce->sha1),
229
- !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)),
231
+ old_sha1, new_sha1,
232
+ !is_null_sha1(old_sha1),
233
+ !is_null_sha1(new_sha1),
234
ce->name, 0, dirty_submodule);
235
236
}