@@ -485,9 +485,32 @@ static void handle_tag(const char *name, struct tag *tag)
485485 (int )message_size , (int )message_size , message ? message : "" );
486486}
487487
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+
488512static void get_tags_and_duplicates (struct rev_cmdline_info * info )
489513{
490- struct tag * tag ;
491514 int i ;
492515
493516 for (i = 0 ; i < info -> nr ; i ++ ) {
@@ -502,41 +525,26 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
502525 if (dwim_ref (e -> name , strlen (e -> name ), sha1 , & full_name ) != 1 )
503526 continue ;
504527
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 ) {
534530 warning ("%s: Unexpected object of type %s, skipping." ,
535531 e -> name ,
536532 typename (e -> item -> type ));
537533 continue ;
538534 }
539535
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+
540548 /*
541549 * This ref will not be updated through a commit, lets make
542550 * sure it gets properly updated eventually.
0 commit comments