@@ -100,16 +100,6 @@ static struct pack_info *find_pack_by_old_num(int old_num)
100100 return NULL ;
101101}
102102
103- static int add_head_def (struct pack_info * this , unsigned char * sha1 )
104- {
105- if (this -> nr_alloc <= this -> nr_heads ) {
106- this -> nr_alloc = alloc_nr (this -> nr_alloc );
107- this -> head = xrealloc (this -> head , this -> nr_alloc * 20 );
108- }
109- memcpy (this -> head [this -> nr_heads ++ ], sha1 , 20 );
110- return 0 ;
111- }
112-
113103/* Returns non-zero when we detect that the info in the
114104 * old file is useless.
115105 */
@@ -126,30 +116,6 @@ static int parse_pack_def(const char *line, int old_cnt)
126116 }
127117}
128118
129- /* Returns non-zero when we detect that the info in the old file is useless.
130- */
131- static int parse_head_def (char * line )
132- {
133- unsigned char sha1 [20 ];
134- unsigned long num ;
135- char * cp , * ep ;
136- struct pack_info * this ;
137- struct object * o ;
138-
139- cp = line + 2 ;
140- num = strtoul (cp , & ep , 10 );
141- if (ep == cp || * ep ++ != ' ' )
142- return error ("invalid input ix %s" , line );
143- this = find_pack_by_old_num (num );
144- if (!this )
145- return 1 ; /* You know the drill. */
146- if (get_sha1_hex (ep , sha1 ) || ep [40 ] != ' ' )
147- return error ("invalid input sha1 %s (%s)" , line , ep );
148- if ((o = parse_object_cheap (sha1 )) == NULL )
149- return error ("no such object: %s" , line );
150- return add_head_def (this , sha1 );
151- }
152-
153119/* Returns non-zero when we detect that the info in the
154120 * old file is useless.
155121 */
@@ -176,9 +142,8 @@ static int read_pack_info_file(const char *infofile)
176142 case 'D' : /* we used to emit D but that was misguided. */
177143 goto out_stale ;
178144 break ;
179- case 'T' : /* T ix sha1 type */
180- if (parse_head_def (line ))
181- goto out_stale ;
145+ case 'T' : /* we used to emit T but nobody uses it. */
146+ goto out_stale ;
182147 break ;
183148 default :
184149 error ("unrecognized: %s" , line );
@@ -262,100 +227,9 @@ static void init_pack_info(const char *infofile, int force)
262227
263228static void write_pack_info_file (FILE * fp )
264229{
265- int i , j ;
230+ int i ;
266231 for (i = 0 ; i < num_pack ; i ++ )
267232 fprintf (fp , "P %s\n" , info [i ]-> p -> pack_name + objdirlen + 6 );
268- for (i = 0 ; i < num_pack ; i ++ ) {
269- struct pack_info * this = info [i ];
270- for (j = 0 ; j < this -> nr_heads ; j ++ ) {
271- struct object * o = lookup_object (this -> head [j ]);
272- fprintf (fp , "T %1d %s %s\n" ,
273- i , sha1_to_hex (this -> head [j ]), o -> type );
274- }
275- }
276-
277- }
278-
279- #define REFERENCED 01
280- #define EMITTED 04
281-
282- static void show (struct object * o , int pack_ix )
283- {
284- /*
285- * We are interested in objects that are not referenced,
286- */
287- if (o -> flags & EMITTED )
288- return ;
289-
290- if (!(o -> flags & REFERENCED ))
291- add_head_def (info [pack_ix ], o -> sha1 );
292- o -> flags |= EMITTED ;
293- }
294-
295- static void find_pack_info_one (int pack_ix )
296- {
297- unsigned char sha1 [20 ];
298- struct object * o ;
299- int i ;
300- struct packed_git * p = info [pack_ix ]-> p ;
301- int num = num_packed_objects (p );
302-
303- /* Scan objects, clear flags from all the edge ones and
304- * internal ones, possibly marked in the previous round.
305- */
306- for (i = 0 ; i < num ; i ++ ) {
307- if (nth_packed_object_sha1 (p , i , sha1 ))
308- die ("corrupt pack file %s?" , p -> pack_name );
309- if ((o = parse_object_cheap (sha1 )) == NULL )
310- die ("cannot parse %s" , sha1_to_hex (sha1 ));
311- if (o -> refs ) {
312- struct object_refs * refs = o -> refs ;
313- int j ;
314- for (j = 0 ; j < refs -> count ; j ++ )
315- refs -> ref [j ]-> flags = 0 ;
316- }
317- o -> flags = 0 ;
318- }
319-
320- /* Mark all the referenced ones */
321- for (i = 0 ; i < num ; i ++ ) {
322- if (nth_packed_object_sha1 (p , i , sha1 ))
323- die ("corrupt pack file %s?" , p -> pack_name );
324- if ((o = lookup_object (sha1 )) == NULL )
325- die ("cannot find %s" , sha1_to_hex (sha1 ));
326- if (o -> refs ) {
327- struct object_refs * refs = o -> refs ;
328- int j ;
329- for (j = 0 ; j < refs -> count ; j ++ )
330- refs -> ref [j ]-> flags |= REFERENCED ;
331- }
332- }
333-
334- for (i = 0 ; i < num ; i ++ ) {
335- if (nth_packed_object_sha1 (p , i , sha1 ))
336- die ("corrupt pack file %s?" , p -> pack_name );
337- if ((o = lookup_object (sha1 )) == NULL )
338- die ("cannot find %s" , sha1_to_hex (sha1 ));
339- show (o , pack_ix );
340- }
341-
342- }
343-
344- static void find_pack_info (void )
345- {
346- int i ;
347- for (i = 0 ; i < num_pack ; i ++ ) {
348- /* The packed objects are cast in stone, and a head
349- * in a pack will stay as head, so is the set of missing
350- * objects. If the repo has been reorganized and we
351- * are missing some packs available back then, we have
352- * already discarded the info read from the file, so
353- * we will find (old_num < 0) in that case.
354- */
355- if (0 <= info [i ]-> old_num )
356- continue ;
357- find_pack_info_one (i );
358- }
359233}
360234
361235static int update_info_packs (int force )
@@ -370,7 +244,6 @@ static int update_info_packs(int force)
370244 strcpy (name + namelen , "+" );
371245
372246 init_pack_info (infofile , force );
373- find_pack_info ();
374247
375248 safe_create_leading_directories (name );
376249 fp = fopen (name , "w" );
0 commit comments