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

Re: [RFC/PATCH v3] merge-base: teach "git merge-base" to accept more than 2 arguments

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jul 29, 2008, 05:24 UTC
Message-ID
<200807290724.16157.chriscool@tuxfamily.org>
In-Reply-To
<7vabg2wovf.fsf@gitster.siamese.dyndns.org>
Le lundi 28 juillet 2008, Junio C Hamano a écrit :
Show 35 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
>
> > +static struct commit *get_commit_reference(const char *arg)
> > +{
> > +	unsigned char revkey[20];
> > +	if (get_sha1(arg, revkey))
> > +		die("Not a valid object name %s", arg);
> > +	return lookup_commit_reference(revkey);
> > +}
>
> This returns a NULL when you feed a tree to the command, and...
>
> >  int cmd_merge_base(int argc, const char **argv, const char *prefix)
> >  {
> > +	struct commit **rev;
> >  	int show_all = 0;
> > +	int rev_nr = 0;
> >
> >  	git_config(git_default_config, NULL);
> >
> > @@ -38,15 +48,18 @@ int cmd_merge_base(int argc, const char **argv,
> > const char *prefix) usage(merge_base_usage);
> >  		argc--; argv++;
> >  	}
> > +	if (argc < 3)
> >  		usage(merge_base_usage);
> > +
> > +	rev = xmalloc((argc - 1) * sizeof(*rev));
> > +
> > +	do {
> > +		struct commit *r = get_commit_reference(argv[1]);
> > +		if (!r)
> > +			return 1;
>
> ... the command silently exits with 1.
In "master" there is:
	rev1 = lookup_commit_reference(rev1key);
	rev2 = lookup_commit_reference(rev2key);
	if (!rev1 || !rev2)
		return 1;
	return show_merge_base(rev1, rev2, show_all);

so I think you found a bug in the current code. I will post a patch to fix it soon.

It will "die" (with an error ùmessage) in case "lookup_commit_reference" returns NULL. I hope it's ok.

Thanks, Christian.

Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 7 in “merge-base: teach "git merge-base" to accept more than 2 arguments”
  1. merge-base: teach "git merge-base" to accept more than 2 argumentsChristian Couder, Jul 28, 2008
  2. Junio C HamanoJul 28, 2008
  3. Christian CouderJul 29, 2008
  4. Junio C HamanoJul 28, 2008
  5. Johannes SchindelinJul 28, 2008
  6. Christian CouderJul 30, 2008
  7. Johannes SchindelinJul 30, 2008

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.