Staging
v0.8.1
Revision ff58b9aaf8bf4ce7471a21baa502cb9ddaa9873a authored by Jeff King on 12 February 2008, 05:45:18 UTC, committed by Junio C Hamano on 13 February 2008, 21:54:58 UTC
It makes no sense to suggest "git reset HEAD" since we have
no HEAD commit. This actually used to work but regressed in
f26a0012.

wt_status_print_cached_header was updated to take the whole
wt_status struct rather than just the reference field.
Previously the various code paths were sometimes sending in
s->reference and sometimes sending in NULL, making the
decision on whether this was an initial commit before we
even got to this function. Now we must check the initial
flag here.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 077b725
Raw File
builtin-merge-base.c
#include "builtin.h"
#include "cache.h"
#include "commit.h"

static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
{
	struct commit_list *result = get_merge_bases(rev1, rev2, 0);

	if (!result)
		return 1;

	while (result) {
		printf("%s\n", sha1_to_hex(result->item->object.sha1));
		if (!show_all)
			return 0;
		result = result->next;
	}

	return 0;
}

static const char merge_base_usage[] =
"git-merge-base [--all] <commit-id> <commit-id>";

int cmd_merge_base(int argc, const char **argv, const char *prefix)
{
	struct commit *rev1, *rev2;
	unsigned char rev1key[20], rev2key[20];
	int show_all = 0;

	git_config(git_default_config);

	while (1 < argc && argv[1][0] == '-') {
		const char *arg = argv[1];
		if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
			show_all = 1;
		else
			usage(merge_base_usage);
		argc--; argv++;
	}
	if (argc != 3)
		usage(merge_base_usage);
	if (get_sha1(argv[1], rev1key))
		die("Not a valid object name %s", argv[1]);
	if (get_sha1(argv[2], rev2key))
		die("Not a valid object name %s", argv[2]);
	rev1 = lookup_commit_reference(rev1key);
	rev2 = lookup_commit_reference(rev2key);
	if (!rev1 || !rev2)
		return 1;
	return show_merge_base(rev1, rev2, show_all);
}
back to top