diff.c: omit hidden entries from namelen calculation with --stat

Currently, --stat calculates the longest name from all items but then drops some (mode changes) from the output later on. Instead, drop them from the namelen generation and calculation. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed May 27, 2011 at 14:36 UTC 358e460eebd3c19f228f02461b5f161ea48b0a98
1 file changed +9 -5
diff.c
+9 -5
@@ -1278,6 +1278,10 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1278 for (i = 0; i < data->nr; i++) {
1279 struct diffstat_file *file = data->files[i];
1280 uintmax_t change = file->added + file->deleted;
1281 + if (!data->files[i]->is_renamed &&
1282 + (change == 0)) {
1283 + continue;
1284 + }
1285 fill_print_name(file);
1286 len = strlen(file->print_name);
1287 if (max_len < len)
@@ -1309,6 +1313,11 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1313 uintmax_t deleted = data->files[i]->deleted;
1314 int name_len;
1315
1316 + if (!data->files[i]->is_renamed &&
1317 + (added + deleted == 0)) {
1318 + total_files--;
1319 + continue;
1320 + }
1321 /*
1322 * "scale" the filename
1323 */
@@ -1343,11 +1352,6 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
1352 fprintf(options->file, " Unmerged\n");
1353 continue;
1354 }
1346 - else if (!data->files[i]->is_renamed &&
1347 - (added + deleted == 0)) {
1348 - total_files--;
1349 - continue;
1350 - }
1355
1356 /*
1357 * scale the add/delete