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