diff options
author | Juan Rubén <juanruben.segovia@gmail.com> | 2014-02-21 00:22:07 +0100 |
---|---|---|
committer | Juan Rubén <juanruben.segovia@gmail.com> | 2014-02-23 23:26:12 +0100 |
commit | c7c833947ec7ac446761242c02d32916661daeb7 (patch) | |
tree | 226a4eb8de0a1366ac04ab921411847693c11581 | |
parent | e0ebaaa53ea1154a1f392dae463453ac6c428d78 (diff) | |
download | libgit2-c7c833947ec7ac446761242c02d32916661daeb7.tar.gz |
Add option to limit blame to first parent
-rw-r--r-- | examples/blame.c | 5 | ||||
-rw-r--r-- | include/git2/blame.h | 2 | ||||
-rw-r--r-- | src/blame_git.c | 6 |
3 files changed, 11 insertions, 2 deletions
diff --git a/examples/blame.c b/examples/blame.c index 1f5db69a1..f04c41772 100644 --- a/examples/blame.c +++ b/examples/blame.c @@ -31,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[]); @@ -52,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); @@ -146,6 +148,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 only care about the first parent\n"); fprintf(stderr, "\n"); exit(1); } @@ -174,6 +177,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); diff --git a/include/git2/blame.h b/include/git2/blame.h index b98c6f0d7..873a94ddd 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -40,6 +40,8 @@ typedef enum { * commit (like `git blame -CCC`). Implies SAME_COMMIT_COPIES. * NOT IMPLEMENTED. */ GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES = (1<<3), + + GIT_BLAME_FIRST_PARENT = (1<<4), } git_blame_flag_t; /** diff --git a/src/blame_git.c b/src/blame_git.c index 800f1f039..c275293c3 100644 --- a/src/blame_git.c +++ b/src/blame_git.c @@ -485,12 +485,14 @@ static void pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt git_blame__origin *sg_buf[16]; git_blame__origin *porigin, **sg_origin = sg_buf; - GIT_UNUSED(opt); - num_parents = git_commit_parentcount(commit); if (!git_oid_cmp(git_commit_id(commit), &blame->options.oldest_commit)) /* Stop at oldest specified commit */ num_parents = 0; + else if (opt & GIT_BLAME_FIRST_PARENT) + /* Limit search to the first parent */ + num_parents = 1; + if (!num_parents) { git_oid_cpy(&blame->options.oldest_commit, git_commit_id(commit)); goto finish; |