commit e52d343e4dfd46e567fd2a3a02f2760492b89293 from: Stefan Sperling date: Thu Nov 29 09:23:41 2018 UTC make 'got log' show the number of lines in a log message commit - 06ca4d091887ecc59f63c7fa459c57e58122d31b commit + e52d343e4dfd46e567fd2a3a02f2760492b89293 blob - b4d4bc167688eeb9100d55de06a3e87d2c0e62b7 blob + 8e6e385e7a449469ddc931e52de70a8e71957d35 --- got/got.c +++ got/got.c @@ -337,6 +337,17 @@ get_datestr(time_t *time, char *datebuf) if (p) *p = '\0'; return s; +} + +static int +count_lines(char *s) +{ + int nlines = 0; + while (*s) { + if (*s++ == '\n') + nlines++; + } + return nlines; } static const struct got_error * @@ -346,12 +357,17 @@ print_commit(struct got_commit_object *commit, struct const struct got_error *err = NULL; char *id_str, *datestr, *logmsg0, *logmsg, *line; char datebuf[26]; + int nlines = 3 + commit->nparents - 1; + + if (strcmp(commit->author, commit->committer) != 0) + nlines++; + nlines += count_lines(commit->logmsg); err = got_object_id_str(&id_str, id); if (err) return err; - printf("-----------------------------------------------\n"); + printf("----------------------------------------------- %d\n", nlines); printf("commit %s\n", id_str); free(id_str); printf("from: %s\n", commit->author);