@matheusbsbs / matheus-bagliano / commits / b92c5f228a
Fork 0

builtin-remote.c: Split out prune_remote as a separate function.

prune_remote will be used in update(), so this function was split out to avoid code duplication. Signed-off-by: Finn Arne Gangstad <finnag@pvv.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Finn Arne Gangstad committed Apr 3, 2009 at 11:02 UTC b92c5f228a9c07fe339c8fd5406069602b6452f6
1 file changed +30 -26
builtin-remote.c
+30 -26
@@ -26,6 +26,7 @@ static const char * const builtin_remote_usage[] = {
26 static int verbose;
27
28 static int show_all(void);
29 +static int prune_remote(const char *remote, int dry_run);
30
31 static inline int postfixcmp(const char *string, const char *postfix)
32 {
@@ -1128,46 +1129,49 @@ static int prune(int argc, const char **argv)
1129 OPT__DRY_RUN(&dry_run),
1130 OPT_END()
1131 };
1131 - struct ref_states states;
1132 - const char *dangling_msg;
1132
1133 argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
1134
1135 if (argc < 1)
1136 usage_with_options(builtin_remote_usage, options);
1137
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);
1140
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 +}
1143
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";
1151
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 + }
1162
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;
1165
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);
1168
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);
1172 }
1173
1174 + free_remote_ref_states(&states);
1175 return result;
1176 }
1177