@@ -26,6 +26,7 @@ static const char * const builtin_remote_usage[] = {
2626static int verbose ;
2727
2828static int show_all (void );
29+ static int prune_remote (const char * remote , int dry_run );
2930
3031static inline int postfixcmp (const char * string , const char * postfix )
3132{
@@ -1128,46 +1129,49 @@ static int prune(int argc, const char **argv)
11281129 OPT__DRY_RUN (& dry_run ),
11291130 OPT_END ()
11301131 };
1131- struct ref_states states ;
1132- const char * dangling_msg ;
11331132
11341133 argc = parse_options (argc , argv , options , builtin_remote_usage , 0 );
11351134
11361135 if (argc < 1 )
11371136 usage_with_options (builtin_remote_usage , options );
11381137
1139- dangling_msg = (dry_run
1140- ? " %s will become dangling!\n"
1141- : " %s has become dangling!\n" );
1138+ for (; argc ; argc -- , argv ++ )
1139+ result |= prune_remote (* argv , dry_run );
11421140
1143- memset (& states , 0 , sizeof (states ));
1144- for (; argc ; argc -- , argv ++ ) {
1145- int i ;
1146-
1147- get_remote_ref_states (* argv , & states , GET_REF_STATES );
1141+ return result ;
1142+ }
11481143
1149- if ( states . stale . nr ) {
1150- printf ( "Pruning %s\n" , * argv );
1151- printf ( "URL: %s\n" ,
1152- states . remote -> url_nr
1153- ? states . remote -> url [ 0 ]
1154- : "(no URL)" );
1155- }
1144+ static int prune_remote ( const char * remote , int dry_run )
1145+ {
1146+ int result = 0 , i ;
1147+ struct ref_states states ;
1148+ const char * dangling_msg = dry_run
1149+ ? " %s will become dangling!\n"
1150+ : " %s has become dangling!\n" ;
11561151
1157- for (i = 0 ; i < states .stale .nr ; i ++ ) {
1158- const char * refname = states .stale .items [i ].util ;
1152+ memset (& states , 0 , sizeof (states ));
1153+ get_remote_ref_states (remote , & states , GET_REF_STATES );
1154+
1155+ if (states .stale .nr ) {
1156+ printf ("Pruning %s\n" , remote );
1157+ printf ("URL: %s\n" ,
1158+ states .remote -> url_nr
1159+ ? states .remote -> url [0 ]
1160+ : "(no URL)" );
1161+ }
11591162
1160- if (! dry_run )
1161- result |= delete_ref ( refname , NULL , 0 ) ;
1163+ for ( i = 0 ; i < states . stale . nr ; i ++ ) {
1164+ const char * refname = states . stale . items [ i ]. util ;
11621165
1163- printf (" * [%s] %s\n" , dry_run ? "would prune" : "pruned" ,
1164- abbrev_ref (refname , "refs/remotes/" ));
1165- warn_dangling_symref (dangling_msg , refname );
1166- }
1166+ if (!dry_run )
1167+ result |= delete_ref (refname , NULL , 0 );
11671168
1168- free_remote_ref_states (& states );
1169+ printf (" * [%s] %s\n" , dry_run ? "would prune" : "pruned" ,
1170+ abbrev_ref (refname , "refs/remotes/" ));
1171+ warn_dangling_symref (dangling_msg , refname );
11691172 }
11701173
1174+ free_remote_ref_states (& states );
11711175 return result ;
11721176}
11731177
0 commit comments