Re: [WIP PATCH] revision-walk: --parent option to find children of a parent
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Sep 30, 2010, 14:32 UTC
- Message-ID
- <20100930143234.GH4850@burratino>
- In-Reply-To
- <99aa4cd5a60b2b2d3eae962acb8a49c2a62a8f77.1285842569.git.git@drmicha.warpmail.net>
Hi,
Michael J Gruber wrote:
> Introduce a new --parent=<commit> option for the revision walker which > limits the commits to those which have <commit> as one of their parents.
So this lists the direct children for a given commit. Could you mention a use case? Why would one want to use this instead of
the_commit=$(git rev-parse --verify <commit>) && git rev-list --parents ... ^<commit> | grep -F " $the_commit"
?
Show 7 quoted lines
> --- a/revision.c
> +++ b/revision.c
> @@ -1149,6 +1149,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];Could this be given narrower scope?
Show 12 quoted lines
> @@ -1989,6 +1999,14 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
> return commit_ignore;
> if (revs->merges_only && !(commit->parents && commit->parents->next))
> 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;
> + }The implementation looks good.