diff --stat: show complete rewrites consistently.
The patch format shows complete rewrite as deletion of all old lines followed by addition of all new lines. Count lines consistenly with that when doing diffstat. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 25, 2006 at 23:40 UTC
710158e3ca3f45a30e08a50dadf427fe95311b9c
1 file changed
+14
-4
diff.c
+14
-4
@@ -485,7 +485,8 @@ static void builtin_diff(const char *name_a,
485
static void builtin_diffstat(const char *name_a, const char *name_b,
486
struct diff_filespec *one,
487
struct diff_filespec *two,
488
- struct diffstat_t *diffstat)
488
+ struct diffstat_t *diffstat,
489
+ int complete_rewrite)
490
{
491
mmfile_t mf1, mf2;
492
struct diffstat_file *data;
@@ -496,7 +497,13 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
497
data->is_unmerged = 1;
498
return;
499
}
499
-
500
+ if (complete_rewrite) {
501
+ diff_populate_filespec(one, 0);
502
+ diff_populate_filespec(two, 0);
503
+ data->deleted = count_lines(one->data, one->size);
504
+ data->added = count_lines(two->data, two->size);
505
+ return;
506
+ }
507
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
508
die("unable to read files to diff");
509
@@ -1055,10 +1062,11 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
1062
{
1063
const char *name;
1064
const char *other;
1065
+ int complete_rewrite = 0;
1066
1067
if (DIFF_PAIR_UNMERGED(p)) {
1068
/* unmerged */
1061
- builtin_diffstat(p->one->path, NULL, NULL, NULL, diffstat);
1069
+ builtin_diffstat(p->one->path, NULL, NULL, NULL, diffstat, 0);
1070
return;
1071
}
1072
@@ -1068,7 +1076,9 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
1076
diff_fill_sha1_info(p->one);
1077
diff_fill_sha1_info(p->two);
1078
1071
- builtin_diffstat(name, other, p->one, p->two, diffstat);
1079
+ if (p->status == DIFF_STATUS_MODIFIED && p->score)
1080
+ complete_rewrite = 1;
1081
+ builtin_diffstat(name, other, p->one, p->two, diffstat, complete_rewrite);
1082
}
1083
1084
void diff_setup(struct diff_options *options)