add more informative error messages to git-mktag
Signed-off-by: Björn Engelmann <BjEngelmann@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Björn Engelmann committed
May 23, 2006 at 20:20 UTC
cfba045930423551ec9936fa15cbea7c04a841cf
1 file changed
+15
-11
mktag.c
+15
-11
@@ -46,41 +46,45 @@ static int verify_tag(char *buffer, unsigned long size)
46
const char *object, *type_line, *tag_line, *tagger_line;
47
48
if (size < 64)
49
- return -1;
49
+ return error("wanna fool me ? you obviously got the size wrong !\n");
50
+
51
buffer[size] = 0;
52
53
/* Verify object line */
54
object = buffer;
55
if (memcmp(object, "object ", 7))
55
- return -1;
56
+ return error("char%d: does not start with \"object \"\n", 0);
57
+
58
if (get_sha1_hex(object + 7, sha1))
57
- return -1;
59
+ return error("char%d: could not get SHA1 hash\n", 7);
60
61
/* Verify type line */
62
type_line = object + 48;
63
if (memcmp(type_line - 1, "\ntype ", 6))
62
- return -1;
64
+ return error("char%d: could not find \"\\ntype \"\n", 47);
65
66
/* Verify tag-line */
67
tag_line = strchr(type_line, '\n');
68
if (!tag_line)
67
- return -1;
69
+ return error("char%td: could not find next \"\\n\"\n", type_line - buffer);
70
tag_line++;
71
if (memcmp(tag_line, "tag ", 4) || tag_line[4] == '\n')
70
- return -1;
72
+ return error("char%td: no \"tag \" found\n", tag_line - buffer);
73
74
/* Get the actual type */
75
typelen = tag_line - type_line - strlen("type \n");
76
if (typelen >= sizeof(type))
75
- return -1;
77
+ return error("char%td: type too long\n", type_line+5 - buffer);
78
+
79
memcpy(type, type_line+5, typelen);
80
type[typelen] = 0;
81
82
/* Verify that the object matches */
83
if (get_sha1_hex(object + 7, sha1))
81
- return -1;
84
+ return error("char%d: could not get SHA1 hash but this is really odd since i got it before !\n", 7);
85
+
86
if (verify_object(sha1, type))
83
- return -1;
87
+ return error("char%d: could not verify object %s\n", 7, sha1);
88
89
/* Verify the tag-name: we don't allow control characters or spaces in it */
90
tag_line += 4;
@@ -90,14 +94,14 @@ static int verify_tag(char *buffer, unsigned long size)
94
break;
95
if (c > ' ')
96
continue;
93
- return -1;
97
+ return error("char%td: could not verify tag name\n", tag_line - buffer);
98
}
99
100
/* Verify the tagger line */
101
tagger_line = tag_line;
102
103
if (memcmp(tagger_line, "tagger", 6) || (tagger_line[6] == '\n'))
100
- return -1;
104
+ return error("char%td: could not find \"tagger\"\n", tagger_line - buffer);
105
106
/* The actual stuff afterwards we don't care about.. */
107
return 0;