push: return reject reasons as a bitset
Pass all rejection reasons back from transport_push(). The logic is simpler and more flexible with regard to providing useful feedback. Signed-off-by: Chris Rorvick <chris@rorvick.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chris Rorvick committed
Nov 29, 2012 at 19:41 UTC
10643d4ec3b9c5898d93d1c20e98b2ff1906bf79
4 files changed
+19
-24
builtin/push.c
+4
-9
@@ -244,7 +244,7 @@ static void advise_checkout_pull_push(void)
244
static int push_with_options(struct transport *transport, int flags)
245
{
246
int err;
247
- int nonfastforward;
247
+ unsigned int reject_reasons;
248
249
transport_set_verbosity(transport, verbosity, progress);
250
@@ -257,7 +257,7 @@ static int push_with_options(struct transport *transport, int flags)
257
if (verbosity > 0)
258
fprintf(stderr, _("Pushing to %s\n"), transport->url);
259
err = transport_push(transport, refspec_nr, refspec, flags,
260
- &nonfastforward);
260
+ &reject_reasons);
261
if (err != 0)
262
error(_("failed to push some refs to '%s'"), transport->url);
263
@@ -265,18 +265,13 @@ static int push_with_options(struct transport *transport, int flags)
265
if (!err)
266
return 0;
267
268
- switch (nonfastforward) {
269
- default:
270
- break;
271
- case NON_FF_HEAD:
268
+ if (reject_reasons & REJECT_NON_FF_HEAD) {
269
advise_pull_before_push();
273
- break;
274
- case NON_FF_OTHER:
270
+ } else if (reject_reasons & REJECT_NON_FF_OTHER) {
271
if (default_matching_used)
272
advise_use_upstream();
273
else
274
advise_checkout_pull_push();
279
- break;
275
}
276
277
return 1;
builtin/send-pack.c
+2
-2
@@ -85,7 +85,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
85
int send_all = 0;
86
const char *receivepack = "git-receive-pack";
87
int flags;
88
- int nonfastforward = 0;
88
+ unsigned int reject_reasons;
89
int progress = -1;
90
91
argv++;
@@ -223,7 +223,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
223
ret |= finish_connect(conn);
224
225
if (!helper_status)
226
- transport_print_push_status(dest, remote_refs, args.verbose, 0, &nonfastforward);
226
+ transport_print_push_status(dest, remote_refs, args.verbose, 0, &reject_reasons);
227
228
if (!args.dry_run && remote) {
229
struct ref *ref;
transport.c
+8
-9
@@ -714,7 +714,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
714
}
715
716
void transport_print_push_status(const char *dest, struct ref *refs,
717
- int verbose, int porcelain, int *nonfastforward)
717
+ int verbose, int porcelain, unsigned int *reject_reasons)
718
{
719
struct ref *ref;
720
int n = 0;
@@ -733,18 +733,17 @@ void transport_print_push_status(const char *dest, struct ref *refs,
733
if (ref->status == REF_STATUS_OK)
734
n += print_one_push_status(ref, dest, n, porcelain);
735
736
- *nonfastforward = 0;
736
+ *reject_reasons = 0;
737
for (ref = refs; ref; ref = ref->next) {
738
if (ref->status != REF_STATUS_NONE &&
739
ref->status != REF_STATUS_UPTODATE &&
740
ref->status != REF_STATUS_OK)
741
n += print_one_push_status(ref, dest, n, porcelain);
742
- if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD &&
743
- *nonfastforward != NON_FF_HEAD) {
742
+ if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
743
if (!strcmp(head, ref->name))
745
- *nonfastforward = NON_FF_HEAD;
744
+ *reject_reasons |= REJECT_NON_FF_HEAD;
745
else
747
- *nonfastforward = NON_FF_OTHER;
746
+ *reject_reasons |= REJECT_NON_FF_OTHER;
747
}
748
}
749
}
@@ -1031,9 +1030,9 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
1030
1031
int transport_push(struct transport *transport,
1032
int refspec_nr, const char **refspec, int flags,
1034
- int *nonfastforward)
1033
+ unsigned int *reject_reasons)
1034
{
1036
- *nonfastforward = 0;
1035
+ *reject_reasons = 0;
1036
transport_verify_remote_names(refspec_nr, refspec);
1037
1038
if (transport->push) {
@@ -1099,7 +1098,7 @@ int transport_push(struct transport *transport,
1098
if (!quiet || err)
1099
transport_print_push_status(transport->url, remote_refs,
1100
verbose | porcelain, porcelain,
1102
- nonfastforward);
1101
+ reject_reasons);
1102
1103
if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
1104
set_upstreams(transport, remote_refs, pretend);
transport.h
+5
-4
@@ -140,11 +140,12 @@ int transport_set_option(struct transport *transport, const char *name,
140
void transport_set_verbosity(struct transport *transport, int verbosity,
141
int force_progress);
142
143
-#define NON_FF_HEAD 1
144
-#define NON_FF_OTHER 2
143
+#define REJECT_NON_FF_HEAD 0x01
144
+#define REJECT_NON_FF_OTHER 0x02
145
+
146
int transport_push(struct transport *connection,
147
int refspec_nr, const char **refspec, int flags,
147
- int * nonfastforward);
148
+ unsigned int * reject_reasons);
149
150
const struct ref *transport_get_remote_refs(struct transport *transport);
151
@@ -170,7 +171,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
171
int transport_refs_pushed(struct ref *ref);
172
173
void transport_print_push_status(const char *dest, struct ref *refs,
173
- int verbose, int porcelain, int *nonfastforward);
174
+ int verbose, int porcelain, unsigned int *reject_reasons);
175
176
typedef void alternate_ref_fn(const struct ref *, void *);
177
extern void for_each_alternate_ref(alternate_ref_fn, void *);