Commit 1436b0e1 by Carson Howard

example-log: add support for --log-size

parent 8ac8c78c
...@@ -49,7 +49,7 @@ static int add_revision(struct log_state *s, const char *revstr); ...@@ -49,7 +49,7 @@ static int add_revision(struct log_state *s, const char *revstr);
/** log_options holds other command line options that affect log output */ /** log_options holds other command line options that affect log output */
struct log_options { struct log_options {
int show_diff; int show_diff, show_log_size;
int skip, limit; int skip, limit;
int min_parents, max_parents; int min_parents, max_parents;
git_time_t before; git_time_t before;
...@@ -63,7 +63,7 @@ struct log_options { ...@@ -63,7 +63,7 @@ struct log_options {
static int parse_options( static int parse_options(
struct log_state *s, struct log_options *opt, int argc, char **argv); struct log_state *s, struct log_options *opt, int argc, char **argv);
static void print_time(const git_time *intime, const char *prefix); static void print_time(const git_time *intime, const char *prefix);
static void print_commit(git_commit *commit); static void print_commit(git_commit *commit, int show_log_size);
static int match_with_parent(git_commit *commit, int i, git_diff_options *); static int match_with_parent(git_commit *commit, int i, git_diff_options *);
/** utility functions for filtering */ /** utility functions for filtering */
...@@ -148,7 +148,7 @@ int main(int argc, char *argv[]) ...@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
break; break;
} }
print_commit(commit); print_commit(commit, opt.show_log_size);
if (opt.show_diff) { if (opt.show_diff) {
git_tree *a = NULL, *b = NULL; git_tree *a = NULL, *b = NULL;
...@@ -337,7 +337,7 @@ static void print_time(const git_time *intime, const char *prefix) ...@@ -337,7 +337,7 @@ static void print_time(const git_time *intime, const char *prefix)
} }
/** Helper to print a commit object. */ /** Helper to print a commit object. */
static void print_commit(git_commit *commit) static void print_commit(git_commit *commit, int show_log_size)
{ {
char buf[GIT_OID_HEXSZ + 1]; char buf[GIT_OID_HEXSZ + 1];
int i, count; int i, count;
...@@ -347,6 +347,11 @@ static void print_commit(git_commit *commit) ...@@ -347,6 +347,11 @@ static void print_commit(git_commit *commit)
git_oid_tostr(buf, sizeof(buf), git_commit_id(commit)); git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
printf("commit %s\n", buf); printf("commit %s\n", buf);
if (show_log_size) {
printf("log size %d", (int)strlen(git_commit_message(commit)));
printf("\n");
}
if ((count = (int)git_commit_parentcount(commit)) > 1) { if ((count = (int)git_commit_parentcount(commit)) > 1) {
printf("Merge:"); printf("Merge:");
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
...@@ -470,6 +475,8 @@ static int parse_options( ...@@ -470,6 +475,8 @@ static int parse_options(
/** Found valid --min_parents. */; /** Found valid --min_parents. */;
else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch")) else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch"))
opt->show_diff = 1; opt->show_diff = 1;
else if (!strcmp(a, "--log-size"))
opt->show_log_size = 1;
else else
usage("Unsupported argument", a); usage("Unsupported argument", a);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment