@@ -30,6 +30,7 @@ static int fake_missing_tagger;
30
30
static int use_done_feature ;
31
31
static int no_data ;
32
32
static int full_tree ;
33
+ static struct string_list extra_refs = STRING_LIST_INIT_NODUP ;
33
34
34
35
static int parse_opt_signed_tag_mode (const struct option * opt ,
35
36
const char * arg , int unset )
@@ -484,10 +485,32 @@ static void handle_tag(const char *name, struct tag *tag)
484
485
(int )message_size , (int )message_size , message ? message : "" );
485
486
}
486
487
487
- static void get_tags_and_duplicates (struct rev_cmdline_info * info ,
488
- struct string_list * extra_refs )
488
+ static struct commit * get_commit (struct rev_cmdline_entry * e , char * full_name )
489
+ {
490
+ switch (e -> item -> type ) {
491
+ case OBJ_COMMIT :
492
+ return (struct commit * )e -> item ;
493
+ case OBJ_TAG : {
494
+ struct tag * tag = (struct tag * )e -> item ;
495
+
496
+ /* handle nested tags */
497
+ while (tag && tag -> object .type == OBJ_TAG ) {
498
+ parse_object (tag -> object .sha1 );
499
+ string_list_append (& extra_refs , full_name )-> util = tag ;
500
+ tag = (struct tag * )tag -> tagged ;
501
+ }
502
+ if (!tag )
503
+ die ("Tag %s points nowhere?" , e -> name );
504
+ return (struct commit * )tag ;
505
+ break ;
506
+ }
507
+ default :
508
+ return NULL ;
509
+ }
510
+ }
511
+
512
+ static void get_tags_and_duplicates (struct rev_cmdline_info * info )
489
513
{
490
- struct tag * tag ;
491
514
int i ;
492
515
493
516
for (i = 0 ; i < info -> nr ; i ++ ) {
@@ -502,60 +525,45 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info,
502
525
if (dwim_ref (e -> name , strlen (e -> name ), sha1 , & full_name ) != 1 )
503
526
continue ;
504
527
505
- switch (e -> item -> type ) {
506
- case OBJ_COMMIT :
507
- commit = (struct commit * )e -> item ;
508
- break ;
509
- case OBJ_TAG :
510
- tag = (struct tag * )e -> item ;
511
-
512
- /* handle nested tags */
513
- while (tag && tag -> object .type == OBJ_TAG ) {
514
- parse_object (tag -> object .sha1 );
515
- string_list_append (extra_refs , full_name )-> util = tag ;
516
- tag = (struct tag * )tag -> tagged ;
517
- }
518
- if (!tag )
519
- die ("Tag %s points nowhere?" , e -> name );
520
- switch (tag -> object .type ) {
521
- case OBJ_COMMIT :
522
- commit = (struct commit * )tag ;
523
- break ;
524
- case OBJ_BLOB :
525
- export_blob (tag -> object .sha1 );
526
- continue ;
527
- default : /* OBJ_TAG (nested tags) is already handled */
528
- warning ("Tag points to object of unexpected type %s, skipping." ,
529
- typename (tag -> object .type ));
530
- continue ;
531
- }
532
- break ;
533
- default :
528
+ commit = get_commit (e , full_name );
529
+ if (!commit ) {
534
530
warning ("%s: Unexpected object of type %s, skipping." ,
535
531
e -> name ,
536
532
typename (e -> item -> type ));
537
533
continue ;
538
534
}
539
535
536
+ switch (commit -> object .type ) {
537
+ case OBJ_COMMIT :
538
+ break ;
539
+ case OBJ_BLOB :
540
+ export_blob (commit -> object .sha1 );
541
+ continue ;
542
+ default : /* OBJ_TAG (nested tags) is already handled */
543
+ warning ("Tag points to object of unexpected type %s, skipping." ,
544
+ typename (commit -> object .type ));
545
+ continue ;
546
+ }
547
+
540
548
/*
541
549
* This ref will not be updated through a commit, lets make
542
550
* sure it gets properly updated eventually.
543
551
*/
544
552
if (commit -> util || commit -> object .flags & SHOWN )
545
- string_list_append (extra_refs , full_name )-> util = commit ;
553
+ string_list_append (& extra_refs , full_name )-> util = commit ;
546
554
if (!commit -> util )
547
555
commit -> util = full_name ;
548
556
}
549
557
}
550
558
551
- static void handle_tags_and_duplicates (struct string_list * extra_refs )
559
+ static void handle_tags_and_duplicates (void )
552
560
{
553
561
struct commit * commit ;
554
562
int i ;
555
563
556
- for (i = extra_refs -> nr - 1 ; i >= 0 ; i -- ) {
557
- const char * name = extra_refs -> items [i ].string ;
558
- struct object * object = extra_refs -> items [i ].util ;
564
+ for (i = extra_refs . nr - 1 ; i >= 0 ; i -- ) {
565
+ const char * name = extra_refs . items [i ].string ;
566
+ struct object * object = extra_refs . items [i ].util ;
559
567
switch (object -> type ) {
560
568
case OBJ_TAG :
561
569
handle_tag (name , (struct tag * )object );
@@ -657,7 +665,6 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
657
665
{
658
666
struct rev_info revs ;
659
667
struct object_array commits = OBJECT_ARRAY_INIT ;
660
- struct string_list extra_refs = STRING_LIST_INIT_NODUP ;
661
668
struct commit * commit ;
662
669
char * export_filename = NULL , * import_filename = NULL ;
663
670
uint32_t lastimportid ;
@@ -709,7 +716,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
709
716
if (import_filename && revs .prune_data .nr )
710
717
full_tree = 1 ;
711
718
712
- get_tags_and_duplicates (& revs .cmdline , & extra_refs );
719
+ get_tags_and_duplicates (& revs .cmdline );
713
720
714
721
if (prepare_revision_walk (& revs ))
715
722
die ("revision walk setup failed" );
@@ -725,7 +732,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
725
732
}
726
733
}
727
734
728
- handle_tags_and_duplicates (& extra_refs );
735
+ handle_tags_and_duplicates ();
729
736
730
737
if (export_filename && lastimportid != last_idnum )
731
738
export_marks (export_filename );
0 commit comments