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

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:03

Christian Couder [off-list ref] writes:
Before this patch "git merge-base" accepted only 2 arguments, so
only merge bases between 2 references could be computed.

The purpose of this patch is to make "git merge-base" accept more
than 2 arguments, so that the merge bases between the first given
reference and all the other references can be computed.
I have trouble with this wording, but I'll comment on the documentation
part in a separate message.
+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...
quoted hunk
 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.

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

From: Christian Couder <hidden>
Date: 2016-06-15 22:45:04

Le lundi 28 juillet 2008, Junio C Hamano a écrit :
Christian Couder [off-list ref] writes:
quoted
+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...
quoted
 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help