23
23
#include "lockfile.h"
24
24
#include "parse-options.h"
25
25
#include "run-command.h"
26
+ #include "remote.h"
26
27
#include "sigchain.h"
27
28
#include "strvec.h"
28
29
#include "commit.h"
@@ -916,6 +917,63 @@ static int maintenance_opt_schedule(const struct option *opt, const char *arg,
916
917
return 0 ;
917
918
}
918
919
920
+ struct remote_cb_data {
921
+ struct maintenance_run_opts * maintenance_opts ;
922
+ struct string_list failed_remotes ;
923
+ };
924
+
925
+ static void report_failed_remotes (struct string_list * failed_remotes ,
926
+ const char * action_name )
927
+ {
928
+ if (failed_remotes -> nr ) {
929
+ int i ;
930
+ struct strbuf msg = STRBUF_INIT ;
931
+ strbuf_addf (& msg , _ ("failed to %s the following remotes: " ),
932
+ action_name );
933
+ for (i = 0 ; i < failed_remotes -> nr ; i ++ ) {
934
+ if (i )
935
+ strbuf_addstr (& msg , ", " );
936
+ strbuf_addstr (& msg , failed_remotes -> items [i ].string );
937
+ }
938
+ error ("%s" , msg .buf );
939
+ strbuf_release (& msg );
940
+ }
941
+ }
942
+
943
+ static int prune_remote (struct remote * remote , void * cb_data )
944
+ {
945
+ struct child_process child = CHILD_PROCESS_INIT ;
946
+ struct remote_cb_data * data = cb_data ;
947
+
948
+ if (!remote -> url .nr )
949
+ return 0 ;
950
+
951
+ child .git_cmd = 1 ;
952
+ strvec_pushl (& child .args , "remote" , "prune" , remote -> name , NULL );
953
+
954
+ if (run_command (& child ))
955
+ string_list_append (& data -> failed_remotes , remote -> name );
956
+
957
+ return 0 ;
958
+ }
959
+
960
+ static int maintenance_task_prune_remote (struct maintenance_run_opts * opts ,
961
+ struct gc_config * cfg UNUSED )
962
+ {
963
+ struct remote_cb_data cbdata = { .maintenance_opts = opts ,
964
+ .failed_remotes = STRING_LIST_INIT_DUP };
965
+
966
+ int result ;
967
+ result = for_each_remote (prune_remote , & cbdata );
968
+
969
+ report_failed_remotes (& cbdata .failed_remotes , "prune" );
970
+ if (cbdata .failed_remotes .nr )
971
+ result = 1 ;
972
+
973
+ string_list_clear (& cbdata .failed_remotes , 0 );
974
+ return result ;
975
+ }
976
+
919
977
/* Remember to update object flag allocation in object.h */
920
978
#define SEEN (1u<<0)
921
979
@@ -1036,8 +1094,8 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts,
1036
1094
1037
1095
static int fetch_remote (struct remote * remote , void * cbdata )
1038
1096
{
1039
- struct maintenance_run_opts * opts = cbdata ;
1040
1097
struct child_process child = CHILD_PROCESS_INIT ;
1098
+ struct remote_cb_data * data = cbdata ;
1041
1099
1042
1100
if (remote -> skip_default_update )
1043
1101
return 0 ;
@@ -1048,21 +1106,34 @@ static int fetch_remote(struct remote *remote, void *cbdata)
1048
1106
"--no-write-fetch-head" , "--recurse-submodules=no" ,
1049
1107
NULL );
1050
1108
1051
- if (opts -> quiet )
1109
+ if (data -> maintenance_opts -> quiet )
1052
1110
strvec_push (& child .args , "--quiet" );
1053
1111
1054
- return !!run_command (& child );
1112
+ if (run_command (& child ))
1113
+ string_list_append (& data -> failed_remotes , remote -> name );
1114
+
1115
+ return 0 ;
1055
1116
}
1056
1117
1057
1118
static int maintenance_task_prefetch (struct maintenance_run_opts * opts ,
1058
1119
struct gc_config * cfg UNUSED )
1059
1120
{
1060
- if (for_each_remote (fetch_remote , opts )) {
1061
- error (_ ("failed to prefetch remotes" ));
1062
- return 1 ;
1121
+ struct remote_cb_data cbdata = { .maintenance_opts = opts ,
1122
+ .failed_remotes = STRING_LIST_INIT_DUP };
1123
+
1124
+ int result = 0 ;
1125
+
1126
+ if (for_each_remote (fetch_remote , & cbdata )) {
1127
+ error (_ ("failed to prefetch some remotes" ));
1128
+ result = 1 ;
1063
1129
}
1064
1130
1065
- return 0 ;
1131
+ report_failed_remotes (& cbdata .failed_remotes , "prefetch" );
1132
+ if (cbdata .failed_remotes .nr )
1133
+ result = 1 ;
1134
+
1135
+ string_list_clear (& cbdata .failed_remotes , 0 );
1136
+ return result ;
1066
1137
}
1067
1138
1068
1139
static int maintenance_task_gc (struct maintenance_run_opts * opts ,
@@ -1378,6 +1449,7 @@ enum maintenance_task_label {
1378
1449
TASK_GC ,
1379
1450
TASK_COMMIT_GRAPH ,
1380
1451
TASK_PACK_REFS ,
1452
+ TASK_PRUNE_REMOTE_REFS ,
1381
1453
1382
1454
/* Leave as final value */
1383
1455
TASK__COUNT
@@ -1414,6 +1486,10 @@ static struct maintenance_task tasks[] = {
1414
1486
maintenance_task_pack_refs ,
1415
1487
pack_refs_condition ,
1416
1488
},
1489
+ [TASK_PRUNE_REMOTE_REFS ] = {
1490
+ "prune-remote-refs" ,
1491
+ maintenance_task_prune_remote ,
1492
+ },
1417
1493
};
1418
1494
1419
1495
static int compare_tasks_by_selection (const void * a_ , const void * b_ )
@@ -1508,6 +1584,8 @@ static void initialize_maintenance_strategy(void)
1508
1584
tasks [TASK_LOOSE_OBJECTS ].schedule = SCHEDULE_DAILY ;
1509
1585
tasks [TASK_PACK_REFS ].enabled = 1 ;
1510
1586
tasks [TASK_PACK_REFS ].schedule = SCHEDULE_WEEKLY ;
1587
+ tasks [TASK_PRUNE_REMOTE_REFS ].enabled = 0 ;
1588
+ tasks [TASK_PRUNE_REMOTE_REFS ].schedule = SCHEDULE_DAILY ;
1511
1589
}
1512
1590
}
1513
1591
0 commit comments