66
77#define MAX_CHAIN 50
88
9- static void show_pack_info (struct packed_git * p )
9+ #define VERIFY_PACK_VERBOSE 01
10+ #define VERIFY_PACK_STAT_ONLY 02
11+
12+ static void show_pack_info (struct packed_git * p , unsigned int flags )
1013{
1114 uint32_t nr_objects , i ;
1215 int cnt ;
16+ int stat_only = flags & VERIFY_PACK_STAT_ONLY ;
1317 unsigned long chain_histogram [MAX_CHAIN + 1 ], baseobjects ;
1418
1519 nr_objects = p -> num_objects ;
@@ -32,16 +36,19 @@ static void show_pack_info(struct packed_git *p)
3236 type = packed_object_info_detail (p , offset , & size , & store_size ,
3337 & delta_chain_length ,
3438 base_sha1 );
35- printf ("%s " , sha1_to_hex (sha1 ));
39+ if (!stat_only )
40+ printf ("%s " , sha1_to_hex (sha1 ));
3641 if (!delta_chain_length ) {
37- printf ("%-6s %lu %lu %" PRIuMAX "\n" ,
38- type , size , store_size , (uintmax_t )offset );
42+ if (!stat_only )
43+ printf ("%-6s %lu %lu %" PRIuMAX "\n" ,
44+ type , size , store_size , (uintmax_t )offset );
3945 baseobjects ++ ;
4046 }
4147 else {
42- printf ("%-6s %lu %lu %" PRIuMAX " %u %s\n" ,
43- type , size , store_size , (uintmax_t )offset ,
44- delta_chain_length , sha1_to_hex (base_sha1 ));
48+ if (!stat_only )
49+ printf ("%-6s %lu %lu %" PRIuMAX " %u %s\n" ,
50+ type , size , store_size , (uintmax_t )offset ,
51+ delta_chain_length , sha1_to_hex (base_sha1 ));
4552 if (delta_chain_length <= MAX_CHAIN )
4653 chain_histogram [delta_chain_length ]++ ;
4754 else
@@ -66,10 +73,12 @@ static void show_pack_info(struct packed_git *p)
6673 chain_histogram [0 ] > 1 ? "s" : "" );
6774}
6875
69- static int verify_one_pack (const char * path , int verbose )
76+ static int verify_one_pack (const char * path , unsigned int flags )
7077{
7178 char arg [PATH_MAX ];
7279 int len ;
80+ int verbose = flags & VERIFY_PACK_VERBOSE ;
81+ int stat_only = flags & VERIFY_PACK_STAT_ONLY ;
7382 struct packed_git * pack ;
7483 int err ;
7584
@@ -105,32 +114,40 @@ static int verify_one_pack(const char *path, int verbose)
105114 return error ("packfile %s not found." , arg );
106115
107116 install_packed_git (pack );
108- err = verify_pack (pack );
109117
110- if (verbose ) {
118+ if (!stat_only )
119+ err = verify_pack (pack );
120+ else
121+ err = open_pack_index (pack );
122+
123+ if (verbose || stat_only ) {
111124 if (err )
112125 printf ("%s: bad\n" , pack -> pack_name );
113126 else {
114- show_pack_info (pack );
115- printf ("%s: ok\n" , pack -> pack_name );
127+ show_pack_info (pack , flags );
128+ if (!stat_only )
129+ printf ("%s: ok\n" , pack -> pack_name );
116130 }
117131 }
118132
119133 return err ;
120134}
121135
122136static const char * const verify_pack_usage [] = {
123- "git verify-pack [-v|--verbose] <pack>..." ,
137+ "git verify-pack [-v|--verbose] [-s|--stat-only] <pack>..." ,
124138 NULL
125139};
126140
127141int cmd_verify_pack (int argc , const char * * argv , const char * prefix )
128142{
129143 int err = 0 ;
130- int verbose = 0 ;
144+ unsigned int flags = 0 ;
131145 int i ;
132146 const struct option verify_pack_options [] = {
133- OPT__VERBOSE (& verbose ),
147+ OPT_BIT ('v' , "verbose" , & flags , "verbose" ,
148+ VERIFY_PACK_VERBOSE ),
149+ OPT_BIT ('s' , "stat-only" , & flags , "show statistics only" ,
150+ VERIFY_PACK_STAT_ONLY ),
134151 OPT_END ()
135152 };
136153
@@ -140,7 +157,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
140157 if (argc < 1 )
141158 usage_with_options (verify_pack_usage , verify_pack_options );
142159 for (i = 0 ; i < argc ; i ++ ) {
143- if (verify_one_pack (argv [i ], verbose ))
160+ if (verify_one_pack (argv [i ], flags ))
144161 err = 1 ;
145162 discard_revindex ();
146163 }
0 commit comments