66#include "tree.h"
77#include "blob.h"
88#include "tag.h"
9+ #include "delta.h"
910
1011#define REACHABLE 0x0001
1112
1213static int show_root = 0 ;
1314static int show_tags = 0 ;
1415static int show_unreachable = 0 ;
16+ static int show_max_delta_depth = 0 ;
1517static int keep_cache_objects = 0 ;
1618static unsigned char head_sha1 [20 ];
1719
20+ static void expand_deltas (void )
21+ {
22+ int i , max_depth = 0 ;
23+
24+ /*
25+ * To be as efficient as possible we look for delta heads and
26+ * recursively process them going backward, and parsing
27+ * resulting objects along the way. This allows for processing
28+ * each delta objects only once regardless of the delta depth.
29+ */
30+ for (i = 0 ; i < nr_objs ; i ++ ) {
31+ struct object * obj = objs [i ];
32+ if (obj -> parsed && !obj -> delta && obj -> attached_deltas ) {
33+ int depth = 0 ;
34+ char type [10 ];
35+ unsigned long size ;
36+ void * buf = read_sha1_file (obj -> sha1 , type , & size );
37+ if (!buf )
38+ continue ;
39+ depth = process_deltas (buf , size , obj -> type ,
40+ obj -> attached_deltas );
41+ if (max_depth < depth )
42+ max_depth = depth ;
43+ }
44+ }
45+ if (show_max_delta_depth )
46+ printf ("maximum delta depth = %d\n" , max_depth );
47+ }
48+
1849static void check_connectivity (void )
1950{
2051 int i ;
@@ -25,7 +56,12 @@ static void check_connectivity(void)
2556 struct object_list * refs ;
2657
2758 if (!obj -> parsed ) {
28- printf ("missing %s %s\n" , obj -> type , sha1_to_hex (obj -> sha1 ));
59+ if (obj -> delta )
60+ printf ("unresolved delta %s\n" ,
61+ sha1_to_hex (obj -> sha1 ));
62+ else
63+ printf ("missing %s %s\n" ,
64+ obj -> type , sha1_to_hex (obj -> sha1 ));
2965 continue ;
3066 }
3167
@@ -43,7 +79,12 @@ static void check_connectivity(void)
4379 continue ;
4480
4581 if (show_unreachable && !(obj -> flags & REACHABLE )) {
46- printf ("unreachable %s %s\n" , obj -> type , sha1_to_hex (obj -> sha1 ));
82+ if (obj -> attached_deltas )
83+ printf ("foreign delta reference %s\n" ,
84+ sha1_to_hex (obj -> sha1 ));
85+ else
86+ printf ("unreachable %s %s\n" ,
87+ obj -> type , sha1_to_hex (obj -> sha1 ));
4788 continue ;
4889 }
4990
@@ -201,6 +242,8 @@ static int fsck_sha1(unsigned char *sha1)
201242 return fsck_commit ((struct commit * ) obj );
202243 if (obj -> type == tag_type )
203244 return fsck_tag ((struct tag * ) obj );
245+ if (!obj -> type && obj -> delta )
246+ return 0 ;
204247 return -1 ;
205248}
206249
@@ -384,6 +427,10 @@ int main(int argc, char **argv)
384427 show_root = 1 ;
385428 continue ;
386429 }
430+ if (!strcmp (arg , "--delta-depth" )) {
431+ show_max_delta_depth = 1 ;
432+ continue ;
433+ }
387434 if (!strcmp (arg , "--cache" )) {
388435 keep_cache_objects = 1 ;
389436 continue ;
@@ -400,6 +447,8 @@ int main(int argc, char **argv)
400447 }
401448 fsck_sha1_list ();
402449
450+ expand_deltas ();
451+
403452 heads = 0 ;
404453 for (i = 1 ; i < argc ; i ++ ) {
405454 const char * arg = argv [i ];
@@ -423,7 +472,7 @@ int main(int argc, char **argv)
423472 }
424473
425474 /*
426- * If we've not been gived any explicit head information, do the
475+ * If we've not been given any explicit head information, do the
427476 * default ones from .git/refs. We also consider the index file
428477 * in this case (ie this implies --cache).
429478 */
0 commit comments