git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] commit-reach: create repo_is_descendant_of()

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 29, 2020, 13:40 UTC
Message-ID
<20200629134035.GA59624@syl.lan>
In-Reply-To
<8f7fd8f5941426c3ed7fc28c6e4afd62bcd4bb8d.1592414670.git.gitgitgadget@gmail.com>
On Wed, Jun 17, 2020 at 05:24:28PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 43 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com>
>
> The next change will make repo_in_merge_bases() depend on the logic in
> is_descendant_of(), but we need to make the method independent of
> the_repository first.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  commit-reach.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/commit-reach.c b/commit-reach.c
> index 4ca7e706a18..13722430aa5 100644
> --- a/commit-reach.c
> +++ b/commit-reach.c
> @@ -283,7 +283,9 @@ struct commit_list *repo_get_merge_bases(struct repository *r,
>  /*
>   * Is "commit" a descendant of one of the elements on the "with_commit" list?
>   */
> -int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
> +static int repo_is_descendant_of(struct repository *r,
> +				 struct commit *commit,
> +				 struct commit_list *with_commit)
>  {
>  	if (!with_commit)
>  		return 1;
> @@ -301,13 +303,18 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
>
>  			other = with_commit->item;
>  			with_commit = with_commit->next;
> -			if (in_merge_bases(other, commit))
> +			if (repo_in_merge_bases(r, other, commit))
>  				return 1;
>  		}
>  		return 0;
>  	}
>  }
>
> +int is_descendant_of(struct commit *commit, struct commit_list *with_commit)
> +{
> +	return repo_is_descendant_of(the_repository, commit, with_commit);
> +}
> +

I don't think that it makes a big deal either way, but I wonder about moving 'repo_is_descendant_of' to the header file, and making 'is_descendant_of' be 'static inline int' as you defined it here.

Since this has already graduated up to master already, I don't think that it's worth going back just to shuffle this code around, but I was wondering if you had any specific reason for doing it this way.

Show 6 quoted lines
>  /*
>   * Is "commit" an ancestor of one of the "references"?
>   */
> --
> gitgitgadget
>

Thanks, Taylor

Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 3 of 8 in “Accelerate "git merge-base --is-ancestor"”
  1. 0/2 Accelerate "git merge-base --is-ancestor"Derrick Stolee via GitGitGadget, Jun 17, 2020
  2. 1/2 commit-reach: create repo_is_descendant_of()Derrick Stolee via GitGitGadget, Jun 17, 2020
  3. Taylor BlauJun 29, 2020
  4. Derrick StoleeJun 30, 2020
  5. 2/2 commit-reach: use fast logic in repo_in_merge_baseDerrick Stolee via GitGitGadget, Jun 17, 2020
  6. Junio C HamanoJun 17, 2020
  7. Derrick StoleeJun 18, 2020
  8. Abhishek KumarJun 19, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.