From 79685cb727b3e24359bb8ba45d483ffd44bc356c Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Thu, 30 Sep 2010 12:18:16 +0200 Subject: [PATCH] revision-walk: --parent option to find children of a parent Introduce a new --parent= option for the revision walker which limits the commits to those which have as one of their parents. This allows to check, e.g., whether is a fork point, or to list all direct forkees easily (without grepping --parents output). --- revision.c | 18 ++++++++++++++++++ revision.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/revision.c b/revision.c index 78397d6486..de8e27cf9e 100644 --- a/revision.c +++ b/revision.c @@ -1304,6 +1304,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg { const char *arg = argv[0]; const char *optarg; + unsigned char sha1[20]; int argcount; /* pseudo revision arguments */ @@ -1406,6 +1407,15 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--parents")) { revs->rewrite_parents = 1; revs->print_parents = 1; + } else if ((argcount = parse_long_opt("parent", argv, &optarg))) { + struct commit *a; + if (get_sha1(optarg, sha1)) + return error("Not a valid object name: %s", optarg); + a = lookup_commit_reference(sha1); + if (!a) + return error("Couldn't look up commit object for '%s'", optarg); + commit_list_insert(a, &(revs->parent_list)); + return argcount; } else if (!strcmp(arg, "--dense")) { revs->dense = 1; } else if (!strcmp(arg, "--sparse")) { @@ -2372,6 +2382,14 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi ((revs->max_parents >= 0) && (n > revs->max_parents))) return commit_ignore; } + if (revs->parent_list) { + struct commit_list *a, *b; + for (b = revs->parent_list; b; b = b->next) + for (a = commit->parents; a; a = a->next) + if (!hashcmp(b->item->object.sha1, a->item->object.sha1)) + return commit_show; + return commit_ignore; + } if (!commit_match(commit, revs)) return commit_ignore; if (revs->prune && revs->dense) { diff --git a/revision.h b/revision.h index 01bd2b7c07..40dc4a5db5 100644 --- a/revision.h +++ b/revision.h @@ -146,6 +146,9 @@ struct rev_info { int show_log_size; struct string_list *mailmap; + /* Filter by parents */ + struct commit_list *parent_list; + /* Filter by commit log message */ struct grep_opt grep_filter; -- 2.11.4.GIT