@matheusbsbs / matheus-bagliano / commits / cbdda02404
Fork 0

diff-files --stat: do not dump core with unmerged index.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 15, 2006 at 18:38 UTC cbdda024049947366804d60bdc5e5fc3ab3ee3a5
1 file changed +17 -4
diff.c
+17 -4
@@ -202,6 +202,8 @@ struct diffstat_t {
202 int alloc;
203 struct diffstat_file {
204 char *name;
205 + unsigned is_unmerged:1;
206 + unsigned is_binary:1;
207 unsigned int added, deleted;
208 } **files;
209 };
@@ -248,6 +250,8 @@ static void show_stats(struct diffstat_t* data)
250 for (i = 0; i < data->nr; i++) {
251 struct diffstat_file *file = data->files[i];
252
253 + if (file->is_binary || file->is_unmerged)
254 + continue;
255 if (max_change < file->added + file->deleted)
256 max_change = file->added + file->deleted;
257 len = strlen(file->name);
@@ -292,11 +296,15 @@ static void show_stats(struct diffstat_t* data)
296 if (max + len > 70)
297 max = 70 - len;
298
295 - if (added < 0) {
296 - /* binary file */
299 + if (data->files[i]->is_binary) {
300 printf(" %s%-*s | Bin\n", prefix, len, name);
301 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) {
308 total_files--;
309 goto free_diffstat_file;
310 }
@@ -424,11 +432,16 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
432
433 data = diffstat_add(diffstat, name_a ? name_a : name_b);
434
435 + if (!one || !two) {
436 + data->is_unmerged = 1;
437 + return;
438 + }
439 +
440 if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
441 die("unable to read files to diff");
442
443 if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))
431 - data->added = -1;
444 + data->is_binary = 1;
445 else {
446 /* Crazy xdl interfaces.. */
447 xpparam_t xpp;