3
3
#include <sys/types.h>
4
4
#include <dirent.h>
5
5
6
- #include "revision.h"
6
+ #include "commit.h"
7
+ #include "tree.h"
8
+ #include "blob.h"
9
+
10
+ #define REACHABLE 0x0001
7
11
8
12
static int show_unreachable = 0 ;
9
13
static unsigned char head_sha1 [20 ];
@@ -13,96 +17,54 @@ static void check_connectivity(void)
13
17
int i ;
14
18
15
19
/* Look up all the requirements, warn about missing objects.. */
16
- for (i = 0 ; i < nr_revs ; i ++ ) {
17
- struct revision * rev = revs [i ];
20
+ for (i = 0 ; i < nr_objs ; i ++ ) {
21
+ struct object * obj = objs [i ];
18
22
19
- if (show_unreachable && !(rev -> flags & REACHABLE )) {
20
- printf ("unreachable %s\n" , sha1_to_hex (rev -> sha1 ));
23
+ if (show_unreachable && !(obj -> flags & REACHABLE )) {
24
+ printf ("unreachable %s\n" , sha1_to_hex (obj -> sha1 ));
21
25
continue ;
22
26
}
23
27
24
- switch (rev -> flags & (SEEN | USED )) {
25
- case 0 :
26
- printf ("bad %s\n" , sha1_to_hex (rev -> sha1 ));
27
- break ;
28
- case USED :
29
- printf ("missing %s\n" , sha1_to_hex (rev -> sha1 ));
30
- break ;
31
- case SEEN :
32
- printf ("dangling %s\n" , sha1_to_hex (rev -> sha1 ));
33
- break ;
28
+ if (!obj -> parsed ) {
29
+ printf ("missing %s %s\n" , obj -> type ,
30
+ sha1_to_hex (obj -> sha1 ));
31
+ }
32
+ if (!obj -> used ) {
33
+ printf ("dangling %s %s\n" , obj -> type ,
34
+ sha1_to_hex (obj -> sha1 ));
34
35
}
35
36
}
36
37
}
37
38
38
- static void mark_needs_sha1 (unsigned char * parent , const char * tag , unsigned char * child )
39
- {
40
- struct revision * child_rev = add_relationship (lookup_rev (parent ), child );
41
- child_rev -> flags |= USED ;
42
- }
43
-
44
- static int mark_sha1_seen (unsigned char * sha1 , char * tag )
45
- {
46
- struct revision * rev = lookup_rev (sha1 );
47
-
48
- rev -> flags |= SEEN ;
49
- return 0 ;
50
- }
51
-
52
39
static int fsck_tree (unsigned char * sha1 , void * data , unsigned long size )
53
40
{
54
- int warn_old_tree = 1 ;
55
-
56
- while (size ) {
57
- int len = 1 + strlen (data );
58
- unsigned char * file_sha1 = data + len ;
59
- char * path = strchr (data , ' ' );
60
- unsigned int mode ;
61
- if (size < len + 20 || !path || sscanf (data , "%o" , & mode ) != 1 )
62
- return -1 ;
63
-
64
- /* Warn about trees that don't do the recursive thing.. */
65
- if (warn_old_tree && strchr (path , '/' )) {
66
- fprintf (stderr , "warning: fsck-cache: tree %s has full pathnames in it\n" , sha1_to_hex (sha1 ));
67
- warn_old_tree = 0 ;
68
- }
69
-
70
- data += len + 20 ;
71
- size -= len + 20 ;
72
- mark_needs_sha1 (sha1 , S_ISDIR (mode ) ? "tree" : "blob" , file_sha1 );
41
+ struct tree * item = lookup_tree (sha1 );
42
+ if (parse_tree (item ))
43
+ return -1 ;
44
+ if (item -> has_full_path ) {
45
+ fprintf (stderr , "warning: fsck-cache: tree %s "
46
+ "has full pathnames in it\n" , sha1_to_hex (sha1 ));
73
47
}
74
48
return 0 ;
75
49
}
76
50
77
51
static int fsck_commit (unsigned char * sha1 , void * data , unsigned long size )
78
52
{
79
- int parents ;
80
- unsigned char tree_sha1 [20 ];
81
- unsigned char parent_sha1 [20 ];
82
-
83
- if (memcmp (data , "tree " , 5 ))
53
+ struct commit * commit = lookup_commit (sha1 );
54
+ if (parse_commit (commit ))
84
55
return -1 ;
85
- if (get_sha1_hex ( data + 5 , tree_sha1 ) < 0 )
56
+ if (! commit -> tree )
86
57
return -1 ;
87
- mark_needs_sha1 (sha1 , "tree" , tree_sha1 );
88
- data += 5 + 40 + 1 ; /* "tree " + <hex sha1> + '\n' */
89
- parents = 0 ;
90
- while (!memcmp (data , "parent " , 7 )) {
91
- if (get_sha1_hex (data + 7 , parent_sha1 ) < 0 )
92
- return -1 ;
93
- mark_needs_sha1 (sha1 , "commit" , parent_sha1 );
94
- data += 7 + 40 + 1 ; /* "parent " + <hex sha1> + '\n' */
95
- parents ++ ;
96
- }
97
- if (!parents )
58
+ if (!commit -> parents )
98
59
printf ("root %s\n" , sha1_to_hex (sha1 ));
99
60
return 0 ;
100
61
}
101
62
102
- static int fsck_entry (unsigned char * sha1 , char * tag , void * data , unsigned long size )
63
+ static int fsck_entry (unsigned char * sha1 , char * tag , void * data ,
64
+ unsigned long size )
103
65
{
104
66
if (!strcmp (tag , "blob" )) {
105
- /* Nothing to check */ ;
67
+ lookup_blob ( sha1 ); /* Nothing to check; but notice it. */
106
68
} else if (!strcmp (tag , "tree" )) {
107
69
if (fsck_tree (sha1 , data , size ) < 0 )
108
70
return -1 ;
@@ -111,7 +73,7 @@ static int fsck_entry(unsigned char *sha1, char *tag, void *data, unsigned long
111
73
return -1 ;
112
74
} else
113
75
return -1 ;
114
- return mark_sha1_seen ( sha1 , tag ) ;
76
+ return 0 ;
115
77
}
116
78
117
79
static int fsck_name (char * hex )
@@ -125,7 +87,8 @@ static int fsck_name(char *hex)
125
87
unsigned long size ;
126
88
void * buffer = NULL ;
127
89
if (!check_sha1_signature (sha1 , map , mapsize ))
128
- buffer = unpack_sha1_file (map , mapsize , type , & size );
90
+ buffer = unpack_sha1_file (map , mapsize , type ,
91
+ & size );
129
92
munmap (map , mapsize );
130
93
if (buffer && !fsck_entry (sha1 , type , buffer , size ))
131
94
return 0 ;
@@ -186,7 +149,10 @@ int main(int argc, char **argv)
186
149
continue ;
187
150
}
188
151
if (!get_sha1_hex (argv [i ], head_sha1 )) {
189
- mark_reachable (lookup_rev (head_sha1 ), REACHABLE );
152
+ struct object * obj =
153
+ & lookup_commit (head_sha1 )-> object ;
154
+ obj -> used = 1 ;
155
+ mark_reachable (obj , REACHABLE );
190
156
heads ++ ;
191
157
continue ;
192
158
}
0 commit comments