6
6
7
7
#define MAX_CHAIN 50
8
8
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 )
10
13
{
11
14
uint32_t nr_objects , i ;
12
15
int cnt ;
16
+ int stat_only = flags & VERIFY_PACK_STAT_ONLY ;
13
17
unsigned long chain_histogram [MAX_CHAIN + 1 ], baseobjects ;
14
18
15
19
nr_objects = p -> num_objects ;
@@ -32,16 +36,19 @@ static void show_pack_info(struct packed_git *p)
32
36
type = packed_object_info_detail (p , offset , & size , & store_size ,
33
37
& delta_chain_length ,
34
38
base_sha1 );
35
- printf ("%s " , sha1_to_hex (sha1 ));
39
+ if (!stat_only )
40
+ printf ("%s " , sha1_to_hex (sha1 ));
36
41
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 );
39
45
baseobjects ++ ;
40
46
}
41
47
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 ));
45
52
if (delta_chain_length <= MAX_CHAIN )
46
53
chain_histogram [delta_chain_length ]++ ;
47
54
else
@@ -66,10 +73,12 @@ static void show_pack_info(struct packed_git *p)
66
73
chain_histogram [0 ] > 1 ? "s" : "" );
67
74
}
68
75
69
- static int verify_one_pack (const char * path , int verbose )
76
+ static int verify_one_pack (const char * path , unsigned int flags )
70
77
{
71
78
char arg [PATH_MAX ];
72
79
int len ;
80
+ int verbose = flags & VERIFY_PACK_VERBOSE ;
81
+ int stat_only = flags & VERIFY_PACK_STAT_ONLY ;
73
82
struct packed_git * pack ;
74
83
int err ;
75
84
@@ -105,32 +114,40 @@ static int verify_one_pack(const char *path, int verbose)
105
114
return error ("packfile %s not found." , arg );
106
115
107
116
install_packed_git (pack );
108
- err = verify_pack (pack );
109
117
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 ) {
111
124
if (err )
112
125
printf ("%s: bad\n" , pack -> pack_name );
113
126
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 );
116
130
}
117
131
}
118
132
119
133
return err ;
120
134
}
121
135
122
136
static const char * const verify_pack_usage [] = {
123
- "git verify-pack [-v|--verbose] <pack>..." ,
137
+ "git verify-pack [-v|--verbose] [-s|--stat-only] <pack>..." ,
124
138
NULL
125
139
};
126
140
127
141
int cmd_verify_pack (int argc , const char * * argv , const char * prefix )
128
142
{
129
143
int err = 0 ;
130
- int verbose = 0 ;
144
+ unsigned int flags = 0 ;
131
145
int i ;
132
146
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 ),
134
151
OPT_END ()
135
152
};
136
153
@@ -140,7 +157,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
140
157
if (argc < 1 )
141
158
usage_with_options (verify_pack_usage , verify_pack_options );
142
159
for (i = 0 ; i < argc ; i ++ ) {
143
- if (verify_one_pack (argv [i ], verbose ))
160
+ if (verify_one_pack (argv [i ], flags ))
144
161
err = 1 ;
145
162
discard_revindex ();
146
163
}
0 commit comments