commit 1e77374764c1364e5046de218e02281841d1bea4ebfef115ff8fcb1517afe21e 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 - a53692a957efbbbba0b5c35d09dd6c401035c5ac446d0f4611e2be538c3692f9 commit + 1e77374764c1364e5046de218e02281841d1bea4ebfef115ff8fcb1517afe21e blob - 0a0ce7a9ae4cfe8bbd2f27c9b5d698bf4c2083b123025460d40c93d848e635f2 blob + ca2c4df18b2ae9208bf90ff344549f63710729756d2c7683decd88456c935599 --- 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);