Skip to content

Commit 9e3fb59

Browse files
authored
Merge pull request libgit2#4373 from cjhoward92/examples/log-show-log-size
example-log: add support for --log-size
2 parents 79e09e1 + 12a888d commit 9e3fb59

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

PROJECTS.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ These are good small projects to get started with libgit2.
3636
trick to this one will be doing it in a manner that is clean and
3737
simple, but still handles the various cases correctly (e.g. `-B/70%`
3838
is apparently a legal setting).
39-
* Implement the `--log-size` option for `examples/log.c`. I think all
40-
the data is available, you would just need to add the code into the
41-
`print_commit()` routine (along with a way of passing the option
42-
into that function).
4339
* As an extension to the matching idea for `examples/log.c`, add the
4440
`-i` option to use `strcasestr()` for matches.
4541
* For `examples/log.c`, implement the `--first-parent` option now that

examples/log.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static int add_revision(struct log_state *s, const char *revstr);
5050
/** log_options holds other command line options that affect log output */
5151
struct log_options {
5252
int show_diff;
53+
int show_log_size;
5354
int skip, limit;
5455
int min_parents, max_parents;
5556
git_time_t before;
@@ -63,7 +64,7 @@ struct log_options {
6364
static int parse_options(
6465
struct log_state *s, struct log_options *opt, int argc, char **argv);
6566
static void print_time(const git_time *intime, const char *prefix);
66-
static void print_commit(git_commit *commit);
67+
static void print_commit(git_commit *commit, struct log_options *opts);
6768
static int match_with_parent(git_commit *commit, int i, git_diff_options *);
6869

6970
/** utility functions for filtering */
@@ -148,7 +149,7 @@ int main(int argc, char *argv[])
148149
break;
149150
}
150151

151-
print_commit(commit);
152+
print_commit(commit, &opt);
152153

153154
if (opt.show_diff) {
154155
git_tree *a = NULL, *b = NULL;
@@ -337,7 +338,7 @@ static void print_time(const git_time *intime, const char *prefix)
337338
}
338339

339340
/** Helper to print a commit object. */
340-
static void print_commit(git_commit *commit)
341+
static void print_commit(git_commit *commit, struct log_options *opts)
341342
{
342343
char buf[GIT_OID_HEXSZ + 1];
343344
int i, count;
@@ -347,6 +348,10 @@ static void print_commit(git_commit *commit)
347348
git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
348349
printf("commit %s\n", buf);
349350

351+
if (opts->show_log_size) {
352+
printf("log size %d\n", (int)strlen(git_commit_message(commit)));
353+
}
354+
350355
if ((count = (int)git_commit_parentcount(commit)) > 1) {
351356
printf("Merge:");
352357
for (i = 0; i < count; ++i) {
@@ -470,6 +475,8 @@ static int parse_options(
470475
/** Found valid --min_parents. */;
471476
else if (!strcmp(a, "-p") || !strcmp(a, "-u") || !strcmp(a, "--patch"))
472477
opt->show_diff = 1;
478+
else if (!strcmp(a, "--log-size"))
479+
opt->show_log_size = 1;
473480
else
474481
usage("Unsupported argument", a);
475482
}

0 commit comments

Comments
 (0)