Skip to content

Commit d9f62df

Browse files
peffgitster
authored andcommitted
show_dirstat: simplify same-content check
We use two nested conditionals to store a content_changed variable, but only bother to look at the result once, directly after we set it. We can drop the variable entirely and just use a single "if". This needless complexity is the result of 2ff3a80 (Teach --dirstat not to completely ignore rearranged lines within a file, 2011-04-11). Before that, we held onto the content_changed variable much longer. While we're touching the condition, we can swap out oidcmp() for !oideq(). Our coccinelle patches didn't previously find this case because of the intermediate variable, but now it's a simple boolean in a conditional. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6a29d7b commit d9f62df

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

diff.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,16 +2933,11 @@ static void show_dirstat(struct diff_options *options)
29332933
struct diff_filepair *p = q->queue[i];
29342934
const char *name;
29352935
unsigned long copied, added, damage;
2936-
int content_changed;
29372936

29382937
name = p->two->path ? p->two->path : p->one->path;
29392938

2940-
if (p->one->oid_valid && p->two->oid_valid)
2941-
content_changed = oidcmp(&p->one->oid, &p->two->oid);
2942-
else
2943-
content_changed = 1;
2944-
2945-
if (!content_changed) {
2939+
if (p->one->oid_valid && p->two->oid_valid &&
2940+
oideq(&p->one->oid, &p->two->oid)) {
29462941
/*
29472942
* The SHA1 has not changed, so pre-/post-content is
29482943
* identical. We can therefore skip looking at the
@@ -2989,7 +2984,7 @@ static void show_dirstat(struct diff_options *options)
29892984
* made to the preimage.
29902985
* If the resulting damage is zero, we know that
29912986
* diffcore_count_changes() considers the two entries to
2992-
* be identical, but since content_changed is true, we
2987+
* be identical, but since the oid changed, we
29932988
* know that there must have been _some_ kind of change,
29942989
* so we force all entries to have damage > 0.
29952990
*/

0 commit comments

Comments
 (0)