3 #include "replace-object.h"
4 #include "object-store.h"
8 static struct fsck_options fsck_options
= FSCK_OPTIONS_STRICT
;
10 static int mktag_config(const char *var
, const char *value
, void *cb
)
12 return fsck_config_internal(var
, value
, cb
, &fsck_options
);
15 static int mktag_fsck_error_func(struct fsck_options
*o
,
16 const struct object_id
*oid
,
17 enum object_type object_type
,
18 int msg_type
, const char *message
)
24 * We treat both warnings and errors as errors, things
25 * like missing "tagger" lines are "only" warnings
26 * under fsck, we've always considered them an error.
28 fprintf_ln(stderr
, "error: tag input does not pass fsck: %s", message
);
31 BUG("%d (FSCK_IGNORE?) should never trigger this callback",
36 static int verify_object_in_tag(struct object_id
*tagged_oid
, int *tagged_type
)
39 enum object_type type
;
42 const struct object_id
*repl
;
44 buffer
= read_object_file(tagged_oid
, &type
, &size
);
46 die("could not read tagged object '%s'",
47 oid_to_hex(tagged_oid
));
48 if (type
!= *tagged_type
)
49 die("object '%s' tagged as '%s', but is a '%s' type",
50 oid_to_hex(tagged_oid
),
51 type_name(*tagged_type
), type_name(type
));
53 repl
= lookup_replace_object(the_repository
, tagged_oid
);
54 ret
= check_object_signature(the_repository
, repl
,
55 buffer
, size
, type_name(*tagged_type
));
61 int cmd_mktag(int argc
, const char **argv
, const char *prefix
)
63 struct strbuf buf
= STRBUF_INIT
;
64 struct object_id tagged_oid
;
66 struct object_id result
;
71 if (strbuf_read(&buf
, 0, 0) < 0)
72 die_errno("could not read from stdin");
74 fsck_options
.error_func
= mktag_fsck_error_func
;
75 fsck_set_msg_type(&fsck_options
, "extraheaderentry", "warn");
76 /* config might set fsck.extraHeaderEntry=* again */
77 git_config(mktag_config
, NULL
);
78 if (fsck_tag_standalone(NULL
, buf
.buf
, buf
.len
, &fsck_options
,
79 &tagged_oid
, &tagged_type
))
80 die("tag on stdin did not pass our strict fsck check");
82 if (verify_object_in_tag(&tagged_oid
, &tagged_type
))
83 die("tag on stdin did not refer to a valid object");
85 if (write_object_file(buf
.buf
, buf
.len
, tag_type
, &result
) < 0)
86 die("unable to write tag file");
89 puts(oid_to_hex(&result
));