From: Mark Jamsek Subject: diffstat output tweak To: Game of Trees Date: Sun, 15 Jan 2023 21:46:45 +1100 I noticed git diffstat only pluralises {dele,inser}tion(s) when more than 1 change occurs. And, relatedly, when there aren't any {dele,inser}tions, that substring is elided altogether. For an example of the latter, see this diff[0] to tech@ where there were no deletions and observe how that part of the summary is absent: ----8<-------- regress/lib/libz/Makefile | 15 +++++++++++++++ regress/lib/libz/utils_unittest.cc | 3 +++ 2 files changed, 18 insertions(+) -------->8---- For an example of the former, see this diff[1] to tech@ where the total change was just 1 insertion and 1 deletion: ----8<-------- ssh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -------->8---- I agree with the second example (i.e., don't use a plural noun after 1), but I don't particularly like the idea of eliding a summary total altogether, and prefer we continue displaying "0 {dele,inser}tions". On that note, I think 0 should keep the plural form (e.g., 0 insertions, not 0 insertion). In short, the below diff changes the top into the bottom: 1 file changed, 1 insertions(+), 1 deletions(-) 1 file changed, 1 insertion(+), 1 deletion(-) ok? ----------------------------------------------- commit ba0c0161716ca82e858e5bf748fa7bf3cd33862e (main) from: Mark Jamsek date: Sun Jan 15 10:32:04 2023 UTC don't use plural noun after 1 in diffstat total Use singular form when appropriate; for example, turn the top into the bottom: 1 file changed, 1 insertions(+), 1 deletions(-) 1 file changed, 1 insertion(+), 1 deletion(-) diff 760079985fc2d63ebd4155a76d4f0d20fbc2f4c5 ba0c0161716ca82e858e5bf748fa7bf3cd33862e commit - 760079985fc2d63ebd4155a76d4f0d20fbc2f4c5 commit + ba0c0161716ca82e858e5bf748fa7bf3cd33862e blob - a20fdf567d2fb43a228a54708fee12c13f94796b blob + e432b18620ea668642106a045956a1a96bef04bc --- got/got.c +++ got/got.c @@ -4168,8 +4168,9 @@ print_diffstat(struct got_diffstat_cb_arg *dsa, struct printf(" %c %s%*c | %*d+ %*d-\n", cp->status, pe->path, pad, ' ', dsa->add_cols + 1, cp->add, dsa->rm_cols + 1, cp->rm); } - printf("\n%d file%s changed, %d insertions(+), %d deletions(-)\n\n", - dsa->nfiles, dsa->nfiles > 1 ? "s" : "", dsa->ins, dsa->del); + printf("\n%d file%s changed, %d insertion%s(+), %d deletion%s(-)\n\n", + dsa->nfiles, dsa->nfiles > 1 ? "s" : "", dsa->ins, + dsa->ins != 1 ? "s" : "", dsa->del, dsa->del != 1 ? "s" : ""); if (fflush(stdout) != 0) return got_error_from_errno("fflush"); blob - 3bf0246d75b75fc92ca14ca210759bab8aebcdc2 blob + 8766355007a2f2ff1724f384dc2bae3e21660b51 --- tog/tog.c +++ tog/tog.c @@ -4720,8 +4720,9 @@ write_commit_info(struct got_diff_line **lines, size_t goto done; n = fprintf(outfile, - "%d file%s changed, %d insertions(+), %d deletions(-)\n", - dsa.nfiles, dsa.nfiles > 1 ? "s" : "", dsa.ins, dsa.del); + "%d file%s changed, %d insertion%s(+), %d deletion%s(-)\n", + dsa.nfiles, dsa.nfiles > 1 ? "s" : "", dsa.ins, + dsa.ins != 1 ? "s" : "", dsa.del, dsa.del != 1 ? "s" : ""); if (n < 0) { err = got_error_from_errno("fprintf"); goto done; [0]: https://marc.info/?l=openbsd-tech&m=166714432227960&w=2 [1]: https://marc.info/?l=openbsd-tech&m=166492712423323&w=2 -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68