commit 56275f3b8784d02cc619785d1926615cb54fd059 from: Mark Jamsek date: Fri Feb 14 13:36:57 2025 UTC fix diffstat path order bug in field width computation The order in which get_diffstat() receives paths may not be the same as the lexicographic order of the changed paths path list, so do not use RB_MAX() to get the path that will be used in the current max path len check. Use the path entry returned by the current got_pathlist_insert() call instead. In such cases that get_diffstat() does not receive paths in lexicographic order, this can produce a bogus diffstat max_path_len if the last lexicographically sorted path entry doesn't have the longest pathname of all changed paths in the diff, which manifests as misaligned diffstat path separators as reported by stsp on IRC. ok stsp@ commit - f1028607764f02c97ecb72a8d85a6bbf1bbe5b58 commit + 56275f3b8784d02cc619785d1926615cb54fd059 blob - 658c27563232e250780c4d2b9306e9643b58167f blob + c2ccdab78896af45f70d3c4742e99cb041535eac --- lib/diff.c +++ lib/diff.c @@ -118,11 +118,9 @@ get_diffstat(struct got_diffstat_cb_arg *ds, const cha err = got_pathlist_insert(&pe, ds->paths, path, change); if (err || pe == NULL) { free(change); - if (err) - return err; + return err; } - pe = RB_MAX(got_pathlist_head, ds->paths); diffstat_field_width(&ds->max_path_len, &ds->add_cols, &ds->rm_cols, pe->path_len, change->add, change->rm);