summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-04-26 06:40:09 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-04-26 06:40:09 (GMT)
commit710158e3ca3f45a30e08a50dadf427fe95311b9c (patch)
tree25eb164566aaa03c751ce75ce37d39ad55822908
parente9b5b75ca87f45292de8ecde5d4d0512ac9542cd (diff)
downloadgit-710158e3ca3f45a30e08a50dadf427fe95311b9c.zip
git-710158e3ca3f45a30e08a50dadf427fe95311b9c.tar.gz
git-710158e3ca3f45a30e08a50dadf427fe95311b9c.tar.bz2
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>
-rw-r--r--diff.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/diff.c b/diff.c
index 13b216f..6762fce 100644
--- a/diff.c
+++ b/diff.c
@@ -485,7 +485,8 @@ static void builtin_diff(const char *name_a,
static void builtin_diffstat(const char *name_a, const char *name_b,
struct diff_filespec *one,
struct diff_filespec *two,
- struct diffstat_t *diffstat)
+ struct diffstat_t *diffstat,
+ int complete_rewrite)
{
mmfile_t mf1, mf2;
struct diffstat_file *data;
@@ -496,7 +497,13 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
data->is_unmerged = 1;
return;
}
-
+ if (complete_rewrite) {
+ diff_populate_filespec(one, 0);
+ diff_populate_filespec(two, 0);
+ data->deleted = count_lines(one->data, one->size);
+ data->added = count_lines(two->data, two->size);
+ return;
+ }
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
die("unable to read files to diff");
@@ -1055,10 +1062,11 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
{
const char *name;
const char *other;
+ int complete_rewrite = 0;
if (DIFF_PAIR_UNMERGED(p)) {
/* unmerged */
- builtin_diffstat(p->one->path, NULL, NULL, NULL, diffstat);
+ builtin_diffstat(p->one->path, NULL, NULL, NULL, diffstat, 0);
return;
}
@@ -1068,7 +1076,9 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o,
diff_fill_sha1_info(p->one);
diff_fill_sha1_info(p->two);
- builtin_diffstat(name, other, p->one, p->two, diffstat);
+ if (p->status == DIFF_STATUS_MODIFIED && p->score)
+ complete_rewrite = 1;
+ builtin_diffstat(name, other, p->one, p->two, diffstat, complete_rewrite);
}
void diff_setup(struct diff_options *options)