fsck (receive-pack): allow demoting errors to warnings
[git/git.git] / fsck.c
1 #include "cache.h"
2 #include "object.h"
3 #include "blob.h"
4 #include "tree.h"
5 #include "tree-walk.h"
6 #include "commit.h"
7 #include "tag.h"
8 #include "fsck.h"
9 #include "refs.h"
10 #include "utf8.h"
11
12 #define FOREACH_MSG_ID(FUNC) \
13 /* errors */ \
14 FUNC(BAD_DATE, ERROR) \
15 FUNC(BAD_DATE_OVERFLOW, ERROR) \
16 FUNC(BAD_EMAIL, ERROR) \
17 FUNC(BAD_NAME, ERROR) \
18 FUNC(BAD_OBJECT_SHA1, ERROR) \
19 FUNC(BAD_PARENT_SHA1, ERROR) \
20 FUNC(BAD_TAG_OBJECT, ERROR) \
21 FUNC(BAD_TIMEZONE, ERROR) \
22 FUNC(BAD_TREE, ERROR) \
23 FUNC(BAD_TREE_SHA1, ERROR) \
24 FUNC(BAD_TYPE, ERROR) \
25 FUNC(DUPLICATE_ENTRIES, ERROR) \
26 FUNC(MISSING_AUTHOR, ERROR) \
27 FUNC(MISSING_COMMITTER, ERROR) \
28 FUNC(MISSING_EMAIL, ERROR) \
29 FUNC(MISSING_GRAFT, ERROR) \
30 FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
31 FUNC(MISSING_OBJECT, ERROR) \
32 FUNC(MISSING_PARENT, ERROR) \
33 FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
34 FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
35 FUNC(MISSING_TAG, ERROR) \
36 FUNC(MISSING_TAG_ENTRY, ERROR) \
37 FUNC(MISSING_TAG_OBJECT, ERROR) \
38 FUNC(MISSING_TREE, ERROR) \
39 FUNC(MISSING_TYPE, ERROR) \
40 FUNC(MISSING_TYPE_ENTRY, ERROR) \
41 FUNC(NUL_IN_HEADER, ERROR) \
42 FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
43 FUNC(TREE_NOT_SORTED, ERROR) \
44 FUNC(UNKNOWN_TYPE, ERROR) \
45 FUNC(UNTERMINATED_HEADER, ERROR) \
46 FUNC(ZERO_PADDED_DATE, ERROR) \
47 /* warnings */ \
48 FUNC(BAD_FILEMODE, WARN) \
49 FUNC(BAD_TAG_NAME, WARN) \
50 FUNC(EMPTY_NAME, WARN) \
51 FUNC(FULL_PATHNAME, WARN) \
52 FUNC(HAS_DOT, WARN) \
53 FUNC(HAS_DOTDOT, WARN) \
54 FUNC(HAS_DOTGIT, WARN) \
55 FUNC(MISSING_TAGGER_ENTRY, WARN) \
56 FUNC(NULL_SHA1, WARN) \
57 FUNC(ZERO_PADDED_FILEMODE, WARN)
58
59 #define MSG_ID(id, msg_type) FSCK_MSG_##id,
60 enum fsck_msg_id {
61 FOREACH_MSG_ID(MSG_ID)
62 FSCK_MSG_MAX
63 };
64 #undef MSG_ID
65
66 #define STR(x) #x
67 #define MSG_ID(id, msg_type) { STR(id), NULL, FSCK_##msg_type },
68 static struct {
69 const char *id_string;
70 const char *downcased;
71 int msg_type;
72 } msg_id_info[FSCK_MSG_MAX + 1] = {
73 FOREACH_MSG_ID(MSG_ID)
74 { NULL, NULL, -1 }
75 };
76 #undef MSG_ID
77
78 static int parse_msg_id(const char *text)
79 {
80 int i;
81
82 if (!msg_id_info[0].downcased) {
83 /* convert id_string to lower case, without underscores. */
84 for (i = 0; i < FSCK_MSG_MAX; i++) {
85 const char *p = msg_id_info[i].id_string;
86 int len = strlen(p);
87 char *q = xmalloc(len);
88
89 msg_id_info[i].downcased = q;
90 while (*p)
91 if (*p == '_')
92 p++;
93 else
94 *(q)++ = tolower(*(p)++);
95 *q = '\0';
96 }
97 }
98
99 for (i = 0; i < FSCK_MSG_MAX; i++)
100 if (!strcmp(text, msg_id_info[i].downcased))
101 return i;
102
103 return -1;
104 }
105
106 static int fsck_msg_type(enum fsck_msg_id msg_id,
107 struct fsck_options *options)
108 {
109 int msg_type;
110
111 assert(msg_id >= 0 && msg_id < FSCK_MSG_MAX);
112
113 if (options->msg_type)
114 msg_type = options->msg_type[msg_id];
115 else {
116 msg_type = msg_id_info[msg_id].msg_type;
117 if (options->strict && msg_type == FSCK_WARN)
118 msg_type = FSCK_ERROR;
119 }
120
121 return msg_type;
122 }
123
124 static int parse_msg_type(const char *str)
125 {
126 if (!strcmp(str, "error"))
127 return FSCK_ERROR;
128 else if (!strcmp(str, "warn"))
129 return FSCK_WARN;
130 else
131 die("Unknown fsck message type: '%s'", str);
132 }
133
134 int is_valid_msg_type(const char *msg_id, const char *msg_type)
135 {
136 if (parse_msg_id(msg_id) < 0)
137 return 0;
138 parse_msg_type(msg_type);
139 return 1;
140 }
141
142 void fsck_set_msg_type(struct fsck_options *options,
143 const char *msg_id, const char *msg_type)
144 {
145 int id = parse_msg_id(msg_id), type;
146
147 if (id < 0)
148 die("Unhandled message id: %s", msg_id);
149 type = parse_msg_type(msg_type);
150
151 if (!options->msg_type) {
152 int i;
153 int *msg_type = xmalloc(sizeof(int) * FSCK_MSG_MAX);
154 for (i = 0; i < FSCK_MSG_MAX; i++)
155 msg_type[i] = fsck_msg_type(i, options);
156 options->msg_type = msg_type;
157 }
158
159 options->msg_type[id] = type;
160 }
161
162 void fsck_set_msg_types(struct fsck_options *options, const char *values)
163 {
164 char *buf = xstrdup(values), *to_free = buf;
165 int done = 0;
166
167 while (!done) {
168 int len = strcspn(buf, " ,|"), equal;
169
170 done = !buf[len];
171 if (!len) {
172 buf++;
173 continue;
174 }
175 buf[len] = '\0';
176
177 for (equal = 0;
178 equal < len && buf[equal] != '=' && buf[equal] != ':';
179 equal++)
180 buf[equal] = tolower(buf[equal]);
181 buf[equal] = '\0';
182
183 if (equal == len)
184 die("Missing '=': '%s'", buf);
185
186 fsck_set_msg_type(options, buf, buf + equal + 1);
187 buf += len + 1;
188 }
189 free(to_free);
190 }
191
192 __attribute__((format (printf, 4, 5)))
193 static int report(struct fsck_options *options, struct object *object,
194 enum fsck_msg_id id, const char *fmt, ...)
195 {
196 va_list ap;
197 struct strbuf sb = STRBUF_INIT;
198 int msg_type = fsck_msg_type(id, options), result;
199
200 va_start(ap, fmt);
201 strbuf_vaddf(&sb, fmt, ap);
202 result = options->error_func(object, msg_type, sb.buf);
203 strbuf_release(&sb);
204 va_end(ap);
205
206 return result;
207 }
208
209 static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
210 {
211 struct tree_desc desc;
212 struct name_entry entry;
213 int res = 0;
214
215 if (parse_tree(tree))
216 return -1;
217
218 init_tree_desc(&desc, tree->buffer, tree->size);
219 while (tree_entry(&desc, &entry)) {
220 int result;
221
222 if (S_ISGITLINK(entry.mode))
223 continue;
224 if (S_ISDIR(entry.mode))
225 result = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);
226 else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))
227 result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
228 else {
229 result = error("in tree %s: entry %s has bad mode %.6o",
230 sha1_to_hex(tree->object.sha1), entry.path, entry.mode);
231 }
232 if (result < 0)
233 return result;
234 if (!res)
235 res = result;
236 }
237 return res;
238 }
239
240 static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options)
241 {
242 struct commit_list *parents;
243 int res;
244 int result;
245
246 if (parse_commit(commit))
247 return -1;
248
249 result = options->walk((struct object *)commit->tree, OBJ_TREE, data, options);
250 if (result < 0)
251 return result;
252 res = result;
253
254 parents = commit->parents;
255 while (parents) {
256 result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options);
257 if (result < 0)
258 return result;
259 if (!res)
260 res = result;
261 parents = parents->next;
262 }
263 return res;
264 }
265
266 static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
267 {
268 if (parse_tag(tag))
269 return -1;
270 return options->walk(tag->tagged, OBJ_ANY, data, options);
271 }
272
273 int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
274 {
275 if (!obj)
276 return -1;
277 switch (obj->type) {
278 case OBJ_BLOB:
279 return 0;
280 case OBJ_TREE:
281 return fsck_walk_tree((struct tree *)obj, data, options);
282 case OBJ_COMMIT:
283 return fsck_walk_commit((struct commit *)obj, data, options);
284 case OBJ_TAG:
285 return fsck_walk_tag((struct tag *)obj, data, options);
286 default:
287 error("Unknown object type for %s", sha1_to_hex(obj->sha1));
288 return -1;
289 }
290 }
291
292 /*
293 * The entries in a tree are ordered in the _path_ order,
294 * which means that a directory entry is ordered by adding
295 * a slash to the end of it.
296 *
297 * So a directory called "a" is ordered _after_ a file
298 * called "a.c", because "a/" sorts after "a.c".
299 */
300 #define TREE_UNORDERED (-1)
301 #define TREE_HAS_DUPS (-2)
302
303 static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, const char *name2)
304 {
305 int len1 = strlen(name1);
306 int len2 = strlen(name2);
307 int len = len1 < len2 ? len1 : len2;
308 unsigned char c1, c2;
309 int cmp;
310
311 cmp = memcmp(name1, name2, len);
312 if (cmp < 0)
313 return 0;
314 if (cmp > 0)
315 return TREE_UNORDERED;
316
317 /*
318 * Ok, the first <len> characters are the same.
319 * Now we need to order the next one, but turn
320 * a '\0' into a '/' for a directory entry.
321 */
322 c1 = name1[len];
323 c2 = name2[len];
324 if (!c1 && !c2)
325 /*
326 * git-write-tree used to write out a nonsense tree that has
327 * entries with the same name, one blob and one tree. Make
328 * sure we do not have duplicate entries.
329 */
330 return TREE_HAS_DUPS;
331 if (!c1 && S_ISDIR(mode1))
332 c1 = '/';
333 if (!c2 && S_ISDIR(mode2))
334 c2 = '/';
335 return c1 < c2 ? 0 : TREE_UNORDERED;
336 }
337
338 static int fsck_tree(struct tree *item, struct fsck_options *options)
339 {
340 int retval;
341 int has_null_sha1 = 0;
342 int has_full_path = 0;
343 int has_empty_name = 0;
344 int has_dot = 0;
345 int has_dotdot = 0;
346 int has_dotgit = 0;
347 int has_zero_pad = 0;
348 int has_bad_modes = 0;
349 int has_dup_entries = 0;
350 int not_properly_sorted = 0;
351 struct tree_desc desc;
352 unsigned o_mode;
353 const char *o_name;
354
355 init_tree_desc(&desc, item->buffer, item->size);
356
357 o_mode = 0;
358 o_name = NULL;
359
360 while (desc.size) {
361 unsigned mode;
362 const char *name;
363 const unsigned char *sha1;
364
365 sha1 = tree_entry_extract(&desc, &name, &mode);
366
367 has_null_sha1 |= is_null_sha1(sha1);
368 has_full_path |= !!strchr(name, '/');
369 has_empty_name |= !*name;
370 has_dot |= !strcmp(name, ".");
371 has_dotdot |= !strcmp(name, "..");
372 has_dotgit |= (!strcmp(name, ".git") ||
373 is_hfs_dotgit(name) ||
374 is_ntfs_dotgit(name));
375 has_zero_pad |= *(char *)desc.buffer == '0';
376 update_tree_entry(&desc);
377
378 switch (mode) {
379 /*
380 * Standard modes..
381 */
382 case S_IFREG | 0755:
383 case S_IFREG | 0644:
384 case S_IFLNK:
385 case S_IFDIR:
386 case S_IFGITLINK:
387 break;
388 /*
389 * This is nonstandard, but we had a few of these
390 * early on when we honored the full set of mode
391 * bits..
392 */
393 case S_IFREG | 0664:
394 if (!options->strict)
395 break;
396 default:
397 has_bad_modes = 1;
398 }
399
400 if (o_name) {
401 switch (verify_ordered(o_mode, o_name, mode, name)) {
402 case TREE_UNORDERED:
403 not_properly_sorted = 1;
404 break;
405 case TREE_HAS_DUPS:
406 has_dup_entries = 1;
407 break;
408 default:
409 break;
410 }
411 }
412
413 o_mode = mode;
414 o_name = name;
415 }
416
417 retval = 0;
418 if (has_null_sha1)
419 retval += report(options, &item->object, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
420 if (has_full_path)
421 retval += report(options, &item->object, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
422 if (has_empty_name)
423 retval += report(options, &item->object, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
424 if (has_dot)
425 retval += report(options, &item->object, FSCK_MSG_HAS_DOT, "contains '.'");
426 if (has_dotdot)
427 retval += report(options, &item->object, FSCK_MSG_HAS_DOTDOT, "contains '..'");
428 if (has_dotgit)
429 retval += report(options, &item->object, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
430 if (has_zero_pad)
431 retval += report(options, &item->object, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
432 if (has_bad_modes)
433 retval += report(options, &item->object, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
434 if (has_dup_entries)
435 retval += report(options, &item->object, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
436 if (not_properly_sorted)
437 retval += report(options, &item->object, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
438 return retval;
439 }
440
441 static int require_end_of_header(const void *data, unsigned long size,
442 struct object *obj, struct fsck_options *options)
443 {
444 const char *buffer = (const char *)data;
445 unsigned long i;
446
447 for (i = 0; i < size; i++) {
448 switch (buffer[i]) {
449 case '\0':
450 return report(options, obj,
451 FSCK_MSG_NUL_IN_HEADER,
452 "unterminated header: NUL at offset %ld", i);
453 case '\n':
454 if (i + 1 < size && buffer[i + 1] == '\n')
455 return 0;
456 }
457 }
458
459 return report(options, obj,
460 FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
461 }
462
463 static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
464 {
465 char *end;
466
467 if (**ident == '<')
468 return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
469 *ident += strcspn(*ident, "<>\n");
470 if (**ident == '>')
471 return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
472 if (**ident != '<')
473 return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
474 if ((*ident)[-1] != ' ')
475 return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
476 (*ident)++;
477 *ident += strcspn(*ident, "<>\n");
478 if (**ident != '>')
479 return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
480 (*ident)++;
481 if (**ident != ' ')
482 return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
483 (*ident)++;
484 if (**ident == '0' && (*ident)[1] != ' ')
485 return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
486 if (date_overflows(strtoul(*ident, &end, 10)))
487 return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
488 if (end == *ident || *end != ' ')
489 return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
490 *ident = end + 1;
491 if ((**ident != '+' && **ident != '-') ||
492 !isdigit((*ident)[1]) ||
493 !isdigit((*ident)[2]) ||
494 !isdigit((*ident)[3]) ||
495 !isdigit((*ident)[4]) ||
496 ((*ident)[5] != '\n'))
497 return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
498 (*ident) += 6;
499 return 0;
500 }
501
502 static int fsck_commit_buffer(struct commit *commit, const char *buffer,
503 unsigned long size, struct fsck_options *options)
504 {
505 unsigned char tree_sha1[20], sha1[20];
506 struct commit_graft *graft;
507 unsigned parent_count, parent_line_count = 0;
508 int err;
509
510 if (require_end_of_header(buffer, size, &commit->object, options))
511 return -1;
512
513 if (!skip_prefix(buffer, "tree ", &buffer))
514 return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
515 if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
516 return report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
517 buffer += 41;
518 while (skip_prefix(buffer, "parent ", &buffer)) {
519 if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
520 return report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
521 buffer += 41;
522 parent_line_count++;
523 }
524 graft = lookup_commit_graft(commit->object.sha1);
525 parent_count = commit_list_count(commit->parents);
526 if (graft) {
527 if (graft->nr_parent == -1 && !parent_count)
528 ; /* shallow commit */
529 else if (graft->nr_parent != parent_count)
530 return report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
531 } else {
532 if (parent_count != parent_line_count)
533 return report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
534 }
535 if (!skip_prefix(buffer, "author ", &buffer))
536 return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
537 err = fsck_ident(&buffer, &commit->object, options);
538 if (err)
539 return err;
540 if (!skip_prefix(buffer, "committer ", &buffer))
541 return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
542 err = fsck_ident(&buffer, &commit->object, options);
543 if (err)
544 return err;
545 if (!commit->tree)
546 return report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
547
548 return 0;
549 }
550
551 static int fsck_commit(struct commit *commit, const char *data,
552 unsigned long size, struct fsck_options *options)
553 {
554 const char *buffer = data ? data : get_commit_buffer(commit, &size);
555 int ret = fsck_commit_buffer(commit, buffer, size, options);
556 if (!data)
557 unuse_commit_buffer(commit, buffer);
558 return ret;
559 }
560
561 static int fsck_tag_buffer(struct tag *tag, const char *data,
562 unsigned long size, struct fsck_options *options)
563 {
564 unsigned char sha1[20];
565 int ret = 0;
566 const char *buffer;
567 char *to_free = NULL, *eol;
568 struct strbuf sb = STRBUF_INIT;
569
570 if (data)
571 buffer = data;
572 else {
573 enum object_type type;
574
575 buffer = to_free =
576 read_sha1_file(tag->object.sha1, &type, &size);
577 if (!buffer)
578 return report(options, &tag->object,
579 FSCK_MSG_MISSING_TAG_OBJECT,
580 "cannot read tag object");
581
582 if (type != OBJ_TAG) {
583 ret = report(options, &tag->object,
584 FSCK_MSG_TAG_OBJECT_NOT_TAG,
585 "expected tag got %s",
586 typename(type));
587 goto done;
588 }
589 }
590
591 if (require_end_of_header(buffer, size, &tag->object, options))
592 goto done;
593
594 if (!skip_prefix(buffer, "object ", &buffer)) {
595 ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
596 goto done;
597 }
598 if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
599 ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
600 goto done;
601 }
602 buffer += 41;
603
604 if (!skip_prefix(buffer, "type ", &buffer)) {
605 ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
606 goto done;
607 }
608 eol = strchr(buffer, '\n');
609 if (!eol) {
610 ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
611 goto done;
612 }
613 if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
614 ret = report(options, &tag->object, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
615 if (ret)
616 goto done;
617 buffer = eol + 1;
618
619 if (!skip_prefix(buffer, "tag ", &buffer)) {
620 ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
621 goto done;
622 }
623 eol = strchr(buffer, '\n');
624 if (!eol) {
625 ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
626 goto done;
627 }
628 strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
629 if (check_refname_format(sb.buf, 0))
630 report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
631 "invalid 'tag' name: %.*s",
632 (int)(eol - buffer), buffer);
633 buffer = eol + 1;
634
635 if (!skip_prefix(buffer, "tagger ", &buffer))
636 /* early tags do not contain 'tagger' lines; warn only */
637 report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
638 else
639 ret = fsck_ident(&buffer, &tag->object, options);
640
641 done:
642 strbuf_release(&sb);
643 free(to_free);
644 return ret;
645 }
646
647 static int fsck_tag(struct tag *tag, const char *data,
648 unsigned long size, struct fsck_options *options)
649 {
650 struct object *tagged = tag->tagged;
651
652 if (!tagged)
653 return report(options, &tag->object, FSCK_MSG_BAD_TAG_OBJECT, "could not load tagged object");
654
655 return fsck_tag_buffer(tag, data, size, options);
656 }
657
658 int fsck_object(struct object *obj, void *data, unsigned long size,
659 struct fsck_options *options)
660 {
661 if (!obj)
662 return report(options, obj, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
663
664 if (obj->type == OBJ_BLOB)
665 return 0;
666 if (obj->type == OBJ_TREE)
667 return fsck_tree((struct tree *) obj, options);
668 if (obj->type == OBJ_COMMIT)
669 return fsck_commit((struct commit *) obj, (const char *) data,
670 size, options);
671 if (obj->type == OBJ_TAG)
672 return fsck_tag((struct tag *) obj, (const char *) data,
673 size, options);
674
675 return report(options, obj, FSCK_MSG_UNKNOWN_TYPE, "unknown type '%d' (internal fsck error)",
676 obj->type);
677 }
678
679 int fsck_error_function(struct object *obj, int msg_type, const char *message)
680 {
681 if (msg_type == FSCK_WARN) {
682 warning("object %s: %s", sha1_to_hex(obj->sha1), message);
683 return 0;
684 }
685 error("object %s: %s", sha1_to_hex(obj->sha1), message);
686 return 1;
687 }