@@ -310,43 +310,22 @@ static int compute_and_write_prerequisites(int bundle_fd,
310
310
return 0 ;
311
311
}
312
312
313
- int create_bundle (struct bundle_header * header , const char * path ,
314
- int argc , const char * * argv )
313
+ /*
314
+ * Write out bundle refs based on the tips already
315
+ * parsed into revs.pending. As a side effect, may
316
+ * manipulate revs.pending to include additional
317
+ * necessary objects (like tags).
318
+ *
319
+ * Returns the number of refs written, or negative
320
+ * on error.
321
+ */
322
+ static int write_bundle_refs (int bundle_fd , struct rev_info * revs )
315
323
{
316
- static struct lock_file lock ;
317
- int bundle_fd = -1 ;
318
- int bundle_to_stdout ;
319
- int i , ref_count = 0 ;
320
- struct rev_info revs ;
321
-
322
- bundle_to_stdout = !strcmp (path , "-" );
323
- if (bundle_to_stdout )
324
- bundle_fd = 1 ;
325
- else
326
- bundle_fd = hold_lock_file_for_update (& lock , path ,
327
- LOCK_DIE_ON_ERROR );
328
-
329
- /* write signature */
330
- write_or_die (bundle_fd , bundle_signature , strlen (bundle_signature ));
331
-
332
- /* init revs to list objects for pack-objects later */
333
- save_commit_buffer = 0 ;
334
- init_revisions (& revs , NULL );
335
-
336
- /* write prerequisites */
337
- if (compute_and_write_prerequisites (bundle_fd , & revs , argc , argv ))
338
- return -1 ;
339
-
340
- /* write references */
341
- argc = setup_revisions (argc , argv , & revs , NULL );
342
-
343
- if (argc > 1 )
344
- return error (_ ("unrecognized argument: %s" ), argv [1 ]);
345
-
346
- object_array_remove_duplicates (& revs .pending );
324
+ int i ;
325
+ int ref_count = 0 ;
347
326
348
- for (i = 0 ; i < revs . pending .nr ; i ++ ) {
349
- struct object_array_entry * e = revs . pending .objects + i ;
327
+ for (i = 0 ; i < revs -> pending .nr ; i ++ ) {
328
+ struct object_array_entry * e = revs -> pending .objects + i ;
350
329
unsigned char sha1 [20 ];
351
330
char * ref ;
352
331
const char * display_ref ;
@@ -361,7 +340,7 @@ int create_bundle(struct bundle_header *header, const char *path,
361
340
display_ref = (flag & REF_ISSYMREF ) ? e -> name : ref ;
362
341
363
342
if (e -> item -> type == OBJ_TAG &&
364
- !is_tag_in_date_range (e -> item , & revs )) {
343
+ !is_tag_in_date_range (e -> item , revs )) {
365
344
e -> item -> flags |= UNINTERESTING ;
366
345
continue ;
367
346
}
@@ -407,7 +386,7 @@ int create_bundle(struct bundle_header *header, const char *path,
407
386
*/
408
387
obj = parse_object_or_die (sha1 , e -> name );
409
388
obj -> flags |= SHOWN ;
410
- add_pending_object (& revs , obj , e -> name );
389
+ add_pending_object (revs , obj , e -> name );
411
390
}
412
391
free (ref );
413
392
continue ;
@@ -420,11 +399,51 @@ int create_bundle(struct bundle_header *header, const char *path,
420
399
write_or_die (bundle_fd , "\n" , 1 );
421
400
free (ref );
422
401
}
423
- if (!ref_count )
424
- die (_ ("Refusing to create empty bundle." ));
425
402
426
403
/* end header */
427
404
write_or_die (bundle_fd , "\n" , 1 );
405
+ return ref_count ;
406
+ }
407
+
408
+ int create_bundle (struct bundle_header * header , const char * path ,
409
+ int argc , const char * * argv )
410
+ {
411
+ static struct lock_file lock ;
412
+ int bundle_fd = -1 ;
413
+ int bundle_to_stdout ;
414
+ int ref_count = 0 ;
415
+ struct rev_info revs ;
416
+
417
+ bundle_to_stdout = !strcmp (path , "-" );
418
+ if (bundle_to_stdout )
419
+ bundle_fd = 1 ;
420
+ else
421
+ bundle_fd = hold_lock_file_for_update (& lock , path ,
422
+ LOCK_DIE_ON_ERROR );
423
+
424
+ /* write signature */
425
+ write_or_die (bundle_fd , bundle_signature , strlen (bundle_signature ));
426
+
427
+ /* init revs to list objects for pack-objects later */
428
+ save_commit_buffer = 0 ;
429
+ init_revisions (& revs , NULL );
430
+
431
+ /* write prerequisites */
432
+ if (compute_and_write_prerequisites (bundle_fd , & revs , argc , argv ))
433
+ return -1 ;
434
+
435
+ argc = setup_revisions (argc , argv , & revs , NULL );
436
+
437
+ if (argc > 1 )
438
+ return error (_ ("unrecognized argument: %s" ), argv [1 ]);
439
+
440
+ object_array_remove_duplicates (& revs .pending );
441
+
442
+ ref_count = write_bundle_refs (bundle_fd , & revs );
443
+ if (!ref_count )
444
+ die (_ ("Refusing to create empty bundle." ));
445
+ else if (ref_count < 0 )
446
+ return -1 ;
428
447
429
448
/* write pack */
430
449
if (write_pack_data (bundle_fd , & lock , & revs ))
0 commit comments