diff options
Diffstat (limited to 'examples/blame.c')
-rw-r--r-- | examples/blame.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/examples/blame.c b/examples/blame.c index 06310d540..fda605bce 100644 --- a/examples/blame.c +++ b/examples/blame.c @@ -14,6 +14,11 @@ #include "common.h" +#ifdef _MSC_VER +#define snprintf sprintf_s +#define strcasecmp strcmpi +#endif + /** * This example demonstrates how to invoke the libgit2 blame API to roughly * simulate the output of `git blame` and a few of its command line arguments. @@ -26,6 +31,7 @@ struct opts { int M; int start_line; int end_line; + int F; }; static void parse_opts(struct opts *o, int argc, char *argv[]); @@ -47,6 +53,7 @@ int main(int argc, char *argv[]) parse_opts(&o, argc, argv); if (o.M) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES; if (o.C) blameopts.flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES; + if (o.F) blameopts.flags |= GIT_BLAME_FIRST_PARENT; /** Open the repository. */ check_lg2(git_repository_open_ext(&repo, ".", 0, NULL), "Couldn't open repository", NULL); @@ -100,8 +107,9 @@ int main(int argc, char *argv[]) if (break_on_null_hunk && !hunk) break; if (hunk) { - break_on_null_hunk = 1; char sig[128] = {0}; + break_on_null_hunk = 1; + git_oid_tostr(oid, 10, &hunk->final_commit_id); snprintf(sig, 30, "%s <%s>", hunk->final_signature->name, hunk->final_signature->email); @@ -141,6 +149,7 @@ static void usage(const char *msg, const char *arg) fprintf(stderr, " -L <n,m> process only line range n-m, counting from 1\n"); fprintf(stderr, " -M find line moves within and across files\n"); fprintf(stderr, " -C find line copies within and across files\n"); + fprintf(stderr, " -F follow only the first parent commits\n"); fprintf(stderr, "\n"); exit(1); } @@ -169,6 +178,8 @@ static void parse_opts(struct opts *o, int argc, char *argv[]) o->M = 1; else if (!strcasecmp(a, "-C")) o->C = 1; + else if (!strcasecmp(a, "-F")) + o->F = 1; else if (!strcasecmp(a, "-L")) { i++; a = argv[i]; if (i >= argc) fatal("Not enough arguments to -L", NULL); |