Revision b67b9612e1a90ae093445abeaeff930e9f4cf936 authored by Junio C Hamano on 26 January 2009, 08:08:24 UTC, committed by Junio C Hamano on 27 January 2009, 08:48:00 UTC
A patch that changes the filetype (e.g. regular file to symlink) of a path
must be split into a deletion event followed by a creation event, which
means that we need to have two independent metainfo lines for each.
However, the code reused the single set of metainfo lines.

As the blob object names recorded on the index lines are usually not used
nor validated on the receiving end, this is not an issue with normal use
of the resulting patch.  However, when accepting a binary patch to delete
a blob, git-apply verified that the postimage blob object name on the
index line is 0{40}, hence a patch that deletes a regular file blob that
records binary contents to create a blob with different filetype (e.g. a
symbolic link) failed to apply.  "git am -3" also uses the blob object
names recorded on the index line, so it would also misbehave when
synthesizing a preimage tree.

This moves the code to generate metainfo lines around, so that two
independent sets of metainfo lines are used for the split halves.

Additional tests by Jeff King.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b938f62
Raw File
builtin-symbolic-ref.c
#include "builtin.h"
#include "cache.h"
#include "refs.h"
#include "parse-options.h"

static const char * const git_symbolic_ref_usage[] = {
	"git symbolic-ref [options] name [ref]",
	NULL
};

static void check_symref(const char *HEAD, int quiet)
{
	unsigned char sha1[20];
	int flag;
	const char *refs_heads_master = resolve_ref(HEAD, sha1, 0, &flag);

	if (!refs_heads_master)
		die("No such ref: %s", HEAD);
	else if (!(flag & REF_ISSYMREF)) {
		if (!quiet)
			die("ref %s is not a symbolic ref", HEAD);
		else
			exit(1);
	}
	puts(refs_heads_master);
}

int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
{
	int quiet = 0;
	const char *msg = NULL;
	struct option options[] = {
		OPT__QUIET(&quiet),
		OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
		OPT_END(),
	};

	git_config(git_default_config, NULL);
	argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
	if (msg &&!*msg)
		die("Refusing to perform update with empty message");
	switch (argc) {
	case 1:
		check_symref(argv[0], quiet);
		break;
	case 2:
		create_symref(argv[0], argv[1], msg);
		break;
	default:
		usage_with_options(git_symbolic_ref_usage, options);
	}
	return 0;
}
back to top