1717#include "utf8.h"
1818#include "parse-options.h"
1919#include "quote.h"
20+ #include "remote.h"
2021
2122static const char * fast_export_usage [] = {
2223 N_ ("git fast-export [rev-list-opts]" ),
@@ -31,6 +32,8 @@ static int use_done_feature;
3132static int no_data ;
3233static int full_tree ;
3334static struct string_list extra_refs = STRING_LIST_INIT_NODUP ;
35+ static struct refspec * refspecs ;
36+ static int refspecs_nr ;
3437
3538static int parse_opt_signed_tag_mode (const struct option * opt ,
3639 const char * arg , int unset )
@@ -525,6 +528,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
525528 if (dwim_ref (e -> name , strlen (e -> name ), sha1 , & full_name ) != 1 )
526529 continue ;
527530
531+ if (refspecs ) {
532+ char * private ;
533+ private = apply_refspecs (refspecs , refspecs_nr , full_name );
534+ if (private ) {
535+ free (full_name );
536+ full_name = private ;
537+ }
538+ }
539+
528540 commit = get_commit (e , full_name );
529541 if (!commit ) {
530542 warning ("%s: Unexpected object of type %s, skipping." ,
@@ -668,6 +680,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
668680 struct commit * commit ;
669681 char * export_filename = NULL , * import_filename = NULL ;
670682 uint32_t lastimportid ;
683+ struct string_list refspecs_list = STRING_LIST_INIT_NODUP ;
671684 struct option options [] = {
672685 OPT_INTEGER (0 , "progress" , & progress ,
673686 N_ ("show progress after <n> objects" )),
@@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
688701 OPT_BOOL (0 , "use-done-feature" , & use_done_feature ,
689702 N_ ("Use the done feature to terminate the stream" )),
690703 OPT_BOOL (0 , "no-data" , & no_data , N_ ("Skip output of blob data" )),
704+ OPT_STRING_LIST (0 , "refspec" , & refspecs_list , N_ ("refspec" ),
705+ N_ ("Apply refspec to exported refs" )),
691706 OPT_END ()
692707 };
693708
@@ -707,6 +722,21 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
707722 if (argc > 1 )
708723 usage_with_options (fast_export_usage , options );
709724
725+ if (refspecs_list .nr ) {
726+ const char * * refspecs_str ;
727+ int i ;
728+
729+ refspecs_str = xmalloc (sizeof (* refspecs_str ) * refspecs_list .nr );
730+ for (i = 0 ; i < refspecs_list .nr ; i ++ )
731+ refspecs_str [i ] = refspecs_list .items [i ].string ;
732+
733+ refspecs_nr = refspecs_list .nr ;
734+ refspecs = parse_fetch_refspec (refspecs_nr , refspecs_str );
735+
736+ string_list_clear (& refspecs_list , 1 );
737+ free (refspecs_str );
738+ }
739+
710740 if (use_done_feature )
711741 printf ("feature done\n" );
712742
@@ -741,5 +771,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
741771 if (use_done_feature )
742772 printf ("done\n" );
743773
774+ free_refspec (refspecs_nr , refspecs );
775+
744776 return 0 ;
745777}
0 commit comments