| 2951 | } |
| 2952 | |
| 2953 | static void show_stats(struct diffstat_t *data, struct diff_options *options) |
| 2954 | { |
| 2955 | int i, len, add, del, adds = 0, dels = 0; |
| 2956 | uintmax_t max_change = 0, max_len = 0; |
| 2957 | int total_files = data->nr, count; |
| 2958 | int width, name_width, graph_width, number_width = 0, bin_width = 0; |
| 2959 | const char *reset, *add_c, *del_c; |
| 2960 | int extra_shown = 0; |
| 2961 | const char *line_prefix = diff_line_prefix(options); |
| 2962 | struct strbuf out = STRBUF_INIT; |
| 2963 | |
| 2964 | if (data->nr == 0) |
| 2965 | return; |
| 2966 | |
| 2967 | count = options->stat_count ? options->stat_count : data->nr; |
| 2968 | |
| 2969 | reset = diff_get_color_opt(options, DIFF_RESET); |
| 2970 | add_c = diff_get_color_opt(options, DIFF_FILE_NEW); |
| 2971 | del_c = diff_get_color_opt(options, DIFF_FILE_OLD); |
| 2972 | |
| 2973 | /* |
| 2974 | * Find the longest filename and max number of changes |
| 2975 | */ |
| 2976 | for (i = 0; (i < count) && (i < data->nr); i++) { |
| 2977 | struct diffstat_file *file = data->files[i]; |
| 2978 | uintmax_t change = file->added + file->deleted; |
| 2979 | |
| 2980 | if (!file->is_interesting && (change == 0)) { |
| 2981 | count++; /* not shown == room for one more */ |
| 2982 | continue; |
| 2983 | } |
| 2984 | fill_print_name(file); |
| 2985 | len = utf8_strwidth(file->print_name); |
| 2986 | if (max_len < len) |
| 2987 | max_len = len; |
| 2988 | |
| 2989 | if (file->is_unmerged) { |
| 2990 | /* "Unmerged" is 8 characters */ |
| 2991 | bin_width = bin_width < 8 ? 8 : bin_width; |
| 2992 | continue; |
| 2993 | } |
| 2994 | if (file->is_binary) { |
| 2995 | /* "Bin XXX -> YYY bytes" */ |
| 2996 | int w = 14 + decimal_width(file->added) |
| 2997 | + decimal_width(file->deleted); |
| 2998 | bin_width = bin_width < w ? w : bin_width; |
| 2999 | /* Display change counts aligned with "Bin" */ |
| 3000 | number_width = 3; |
| 3001 | continue; |
| 3002 | } |
| 3003 | |
| 3004 | if (max_change < change) |
| 3005 | max_change = change; |
| 3006 | } |
| 3007 | count = i; /* where we can stop scanning in data->files[] */ |
| 3008 | |
| 3009 | /* |
| 3010 | * We have width = stat_width or term_columns() columns total minus the |
no test coverage detected