make 'got log' show the number of lines in a log message
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
diff --git a/got/got.c b/got/got.c
index b4d4bc1..8e6e385 100644
--- a/got/got.c
+++ b/got/got.c
@@ -339,6 +339,17 @@ get_datestr(time_t *time, char *datebuf)
return s;
}
+static int
+count_lines(char *s)
+{
+ int nlines = 0;
+ while (*s) {
+ if (*s++ == '\n')
+ nlines++;
+ }
+ return nlines;
+}
+
static const struct got_error *
print_commit(struct got_commit_object *commit, struct got_object_id *id,
struct got_repository *repo, int show_patch, int diff_context)
@@ -346,12 +357,17 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
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);