Skip to content

Commit cbdda02

Browse files
author
Junio C Hamano
committed
diff-files --stat: do not dump core with unmerged index.
Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 1cd9508 commit cbdda02

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

diff.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ struct diffstat_t {
202202
int alloc;
203203
struct diffstat_file {
204204
char *name;
205+
unsigned is_unmerged:1;
206+
unsigned is_binary:1;
205207
unsigned int added, deleted;
206208
} **files;
207209
};
@@ -248,6 +250,8 @@ static void show_stats(struct diffstat_t* data)
248250
for (i = 0; i < data->nr; i++) {
249251
struct diffstat_file *file = data->files[i];
250252

253+
if (file->is_binary || file->is_unmerged)
254+
continue;
251255
if (max_change < file->added + file->deleted)
252256
max_change = file->added + file->deleted;
253257
len = strlen(file->name);
@@ -292,11 +296,15 @@ static void show_stats(struct diffstat_t* data)
292296
if (max + len > 70)
293297
max = 70 - len;
294298

295-
if (added < 0) {
296-
/* binary file */
299+
if (data->files[i]->is_binary) {
297300
printf(" %s%-*s | Bin\n", prefix, len, name);
298301
goto free_diffstat_file;
299-
} else if (added + deleted == 0) {
302+
}
303+
else if (data->files[i]->is_unmerged) {
304+
printf(" %s%-*s | Unmerged\n", prefix, len, name);
305+
goto free_diffstat_file;
306+
}
307+
else if (added + deleted == 0) {
300308
total_files--;
301309
goto free_diffstat_file;
302310
}
@@ -424,11 +432,16 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
424432

425433
data = diffstat_add(diffstat, name_a ? name_a : name_b);
426434

435+
if (!one || !two) {
436+
data->is_unmerged = 1;
437+
return;
438+
}
439+
427440
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
428441
die("unable to read files to diff");
429442

430443
if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))
431-
data->added = -1;
444+
data->is_binary = 1;
432445
else {
433446
/* Crazy xdl interfaces.. */
434447
xpparam_t xpp;

0 commit comments

Comments
 (0)