git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
blob f1f1cf04ff00e0418ff2da21198d78aebc26280e 2593 bytes (raw)
name: builtin/mktag.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
 
#include "builtin.h"
#include "tag.h"
#include "replace-object.h"
#include "object-store.h"
#include "fsck.h"

static int mktag_fsck_error_func(struct fsck_options *o,
				 const struct object_id *oid,
				 enum object_type object_type,
				 int msg_type, const char *message)
{
	switch (msg_type) {
	case FSCK_WARN:
	case FSCK_ERROR:
	case FSCK_EXTRA:
		/*
		 * We treat both warnings and errors as errors, things
		 * like missing "tagger" lines are "only" warnings
		 * under fsck, we've always considered them an error.
		 */
		fprintf_ln(stderr, "error: %s", message);
		return 1;
	default:
		BUG("%d (FSCK_IGNORE?) should never trigger this callback",
		    msg_type);
	}
}

static int verify_object_in_tag(const char *stdin)
{
	struct object_id oid;
	char *eol;
	const char *p;
	int expected_type_id;
	const char *expected_type;
	int ret = -1;
	enum object_type type;
	unsigned long size;
	void *buffer;
	const struct object_id *repl;

	if (!skip_prefix(stdin, "object ", &stdin))
		goto bug;
	if (parse_oid_hex(stdin, &oid, &p) || *p != '\n')
		goto bug;
	stdin = p + 1;
	if (!skip_prefix(stdin, "type ", &stdin))
		goto bug;
	eol = strchr(stdin, '\n');
	expected_type_id = type_from_string_gently(stdin, eol - stdin, 1);
	if (expected_type_id < 0)
		goto bug;
	expected_type = type_name(expected_type_id);

	buffer = read_object_file(&oid, &type, &size);
	repl = lookup_replace_object(the_repository, &oid);

	if (buffer) {
		if (type == type_from_string(expected_type)) {
			ret = check_object_signature(the_repository, repl,
						     buffer, size,
						     expected_type);
		}
		free(buffer);
	}
	goto ok;
bug:
	BUG("fsck_object() should have ensured a sane tag format already!");
ok:
	return ret;
}

int cmd_mktag(int argc, const char **argv, const char *prefix)
{
	struct object obj;
	struct strbuf buf = STRBUF_INIT;
	struct object_id result;
	struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;

	if (argc != 1)
		usage("git mktag");

	if (strbuf_read(&buf, 0, 0) < 0)
		die_errno("could not read from stdin");

	/*
	 * Fake up an object for fsck_object()
	 */
	obj.parsed = 1;
	obj.type = OBJ_TAG;

	fsck_options.extra = 1;
	fsck_options.error_func = mktag_fsck_error_func;
	if (fsck_object(&obj, buf.buf, buf.len, &fsck_options))
		die("tag on stdin did not pass our strict fsck check");

	if (verify_object_in_tag(buf.buf))
		die("tag on stdin did not refer to a valid object");

	if (write_object_file(buf.buf, buf.len, tag_type, &result) < 0)
		die("unable to write annotated tag object");

	strbuf_release(&buf);
	printf("%s\n", oid_to_hex(&result));
	return 0;
}

debug log:

solving f1f1cf04ff ...
found f1f1cf04ff in https://public-inbox.org/git/20201126012854.399-13-avarab@gmail.com/
found e9a0954dcb in https://public-inbox.org/git/20201126012854.399-10-avarab@gmail.com/
found a1ae80702d in https://public-inbox.org/git/20201126012854.399-9-avarab@gmail.com/
found dc354828f7 in https://public-inbox.org/git/20201126222257.5629-5-avarab@gmail.com/ ||
	https://public-inbox.org/git/20201126012854.399-4-avarab@gmail.com/
found 603b55aca0 in https://public-inbox.org/git/20201126222257.5629-4-avarab@gmail.com/ ||
	https://public-inbox.org/git/20201126012854.399-3-avarab@gmail.com/
found ff7ac8e0e5 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 ff7ac8e0e5dbfe77ca16d2304b944a30c14ca408	builtin/mktag.c

applying [1/5] https://public-inbox.org/git/20201126222257.5629-4-avarab@gmail.com/
diff --git a/builtin/mktag.c b/builtin/mktag.c
index ff7ac8e0e5..603b55aca0 100644

Checking patch builtin/mktag.c...
Applied patch builtin/mktag.c cleanly.

skipping https://public-inbox.org/git/20201126012854.399-3-avarab@gmail.com/ for 603b55aca0
index at:
100644 603b55aca0e91d9ed2272cf8ea0ce9a0fdd9dbe5	builtin/mktag.c

applying [2/5] https://public-inbox.org/git/20201126222257.5629-5-avarab@gmail.com/
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 603b55aca0..dc354828f7 100644

Checking patch builtin/mktag.c...
Applied patch builtin/mktag.c cleanly.

skipping https://public-inbox.org/git/20201126012854.399-4-avarab@gmail.com/ for dc354828f7
index at:
100644 dc354828f7d34ac5c66b73479864f254bf1b8157	builtin/mktag.c

applying [3/5] https://public-inbox.org/git/20201126012854.399-9-avarab@gmail.com/
diff --git a/builtin/mktag.c b/builtin/mktag.c
index dc354828f7..a1ae80702d 100644


applying [4/5] https://public-inbox.org/git/20201126012854.399-10-avarab@gmail.com/
diff --git a/builtin/mktag.c b/builtin/mktag.c
index a1ae80702d..e9a0954dcb 100644


applying [5/5] https://public-inbox.org/git/20201126012854.399-13-avarab@gmail.com/
diff --git a/builtin/mktag.c b/builtin/mktag.c
index e9a0954dcb..f1f1cf04ff 100644

Checking patch builtin/mktag.c...
Applied patch builtin/mktag.c cleanly.
Checking patch builtin/mktag.c...
Applied patch builtin/mktag.c cleanly.
Checking patch builtin/mktag.c...
Applied patch builtin/mktag.c cleanly.

index at:
100644 f1f1cf04ff00e0418ff2da21198d78aebc26280e	builtin/mktag.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).