| 4180 | } |
| 4181 | |
| 4182 | static void builtin_diffstat(const char *name_a, const char *name_b, |
| 4183 | struct diff_filespec *one, |
| 4184 | struct diff_filespec *two, |
| 4185 | struct diffstat_t *diffstat, |
| 4186 | struct diff_options *o, |
| 4187 | struct diff_filepair *p) |
| 4188 | { |
| 4189 | mmfile_t mf1, mf2; |
| 4190 | struct diffstat_file *data; |
| 4191 | int may_differ; |
| 4192 | int complete_rewrite = 0; |
| 4193 | |
| 4194 | if (!DIFF_PAIR_UNMERGED(p)) { |
| 4195 | if (p->status == DIFF_STATUS_MODIFIED && p->score) |
| 4196 | complete_rewrite = 1; |
| 4197 | } |
| 4198 | |
| 4199 | data = diffstat_add(diffstat, name_a, name_b); |
| 4200 | data->is_interesting = p->status != DIFF_STATUS_UNKNOWN; |
| 4201 | if (o->flags.stat_with_summary) |
| 4202 | data->comments = get_compact_summary(p, data->is_renamed); |
| 4203 | |
| 4204 | if (!one || !two) { |
| 4205 | data->is_unmerged = 1; |
| 4206 | return; |
| 4207 | } |
| 4208 | |
| 4209 | /* saves some reads if true, not a guarantee of diff outcome */ |
| 4210 | may_differ = !(one->oid_valid && two->oid_valid && |
| 4211 | oideq(&one->oid, &two->oid)); |
| 4212 | |
| 4213 | if (diff_filespec_is_binary(o->repo, one) || |
| 4214 | diff_filespec_is_binary(o->repo, two)) { |
| 4215 | data->is_binary = 1; |
| 4216 | if (!may_differ) { |
| 4217 | data->added = 0; |
| 4218 | data->deleted = 0; |
| 4219 | } else { |
| 4220 | data->added = diff_filespec_size(o->repo, two); |
| 4221 | data->deleted = diff_filespec_size(o->repo, one); |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | else if (complete_rewrite) { |
| 4226 | diff_populate_filespec(o->repo, one, NULL); |
| 4227 | diff_populate_filespec(o->repo, two, NULL); |
| 4228 | data->deleted = count_lines(one->data, one->size); |
| 4229 | data->added = count_lines(two->data, two->size); |
| 4230 | } |
| 4231 | |
| 4232 | else if (may_differ) { |
| 4233 | /* Crazy xdl interfaces.. */ |
| 4234 | xpparam_t xpp; |
| 4235 | xdemitconf_t xecfg; |
| 4236 | |
| 4237 | if (fill_mmfile(o->repo, &mf1, one) < 0 || |
| 4238 | fill_mmfile(o->repo, &mf2, two) < 0) |
| 4239 | die("unable to read files to diff"); |
no test coverage detected