Skip to content

Commit 10643d4

Browse files
crorvickgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0b00a3 commit 10643d4

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

builtin/push.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void advise_checkout_pull_push(void)
244244
static int push_with_options(struct transport *transport, int flags)
245245
{
246246
int err;
247-
int nonfastforward;
247+
unsigned int reject_reasons;
248248

249249
transport_set_verbosity(transport, verbosity, progress);
250250

@@ -257,26 +257,21 @@ static int push_with_options(struct transport *transport, int flags)
257257
if (verbosity > 0)
258258
fprintf(stderr, _("Pushing to %s\n"), transport->url);
259259
err = transport_push(transport, refspec_nr, refspec, flags,
260-
&nonfastforward);
260+
&reject_reasons);
261261
if (err != 0)
262262
error(_("failed to push some refs to '%s'"), transport->url);
263263

264264
err |= transport_disconnect(transport);
265265
if (!err)
266266
return 0;
267267

268-
switch (nonfastforward) {
269-
default:
270-
break;
271-
case NON_FF_HEAD:
268+
if (reject_reasons & REJECT_NON_FF_HEAD) {
272269
advise_pull_before_push();
273-
break;
274-
case NON_FF_OTHER:
270+
} else if (reject_reasons & REJECT_NON_FF_OTHER) {
275271
if (default_matching_used)
276272
advise_use_upstream();
277273
else
278274
advise_checkout_pull_push();
279-
break;
280275
}
281276

282277
return 1;

builtin/send-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
8585
int send_all = 0;
8686
const char *receivepack = "git-receive-pack";
8787
int flags;
88-
int nonfastforward = 0;
88+
unsigned int reject_reasons;
8989
int progress = -1;
9090

9191
argv++;
@@ -223,7 +223,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
223223
ret |= finish_connect(conn);
224224

225225
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);
227227

228228
if (!args.dry_run && remote) {
229229
struct ref *ref;

transport.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count, i
714714
}
715715

716716
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)
718718
{
719719
struct ref *ref;
720720
int n = 0;
@@ -733,18 +733,17 @@ void transport_print_push_status(const char *dest, struct ref *refs,
733733
if (ref->status == REF_STATUS_OK)
734734
n += print_one_push_status(ref, dest, n, porcelain);
735735

736-
*nonfastforward = 0;
736+
*reject_reasons = 0;
737737
for (ref = refs; ref; ref = ref->next) {
738738
if (ref->status != REF_STATUS_NONE &&
739739
ref->status != REF_STATUS_UPTODATE &&
740740
ref->status != REF_STATUS_OK)
741741
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) {
744743
if (!strcmp(head, ref->name))
745-
*nonfastforward = NON_FF_HEAD;
744+
*reject_reasons |= REJECT_NON_FF_HEAD;
746745
else
747-
*nonfastforward = NON_FF_OTHER;
746+
*reject_reasons |= REJECT_NON_FF_OTHER;
748747
}
749748
}
750749
}
@@ -1031,9 +1030,9 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
10311030

10321031
int transport_push(struct transport *transport,
10331032
int refspec_nr, const char **refspec, int flags,
1034-
int *nonfastforward)
1033+
unsigned int *reject_reasons)
10351034
{
1036-
*nonfastforward = 0;
1035+
*reject_reasons = 0;
10371036
transport_verify_remote_names(refspec_nr, refspec);
10381037

10391038
if (transport->push) {
@@ -1099,7 +1098,7 @@ int transport_push(struct transport *transport,
10991098
if (!quiet || err)
11001099
transport_print_push_status(transport->url, remote_refs,
11011100
verbose | porcelain, porcelain,
1102-
nonfastforward);
1101+
reject_reasons);
11031102

11041103
if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
11051104
set_upstreams(transport, remote_refs, pretend);

transport.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ int transport_set_option(struct transport *transport, const char *name,
140140
void transport_set_verbosity(struct transport *transport, int verbosity,
141141
int force_progress);
142142

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+
145146
int transport_push(struct transport *connection,
146147
int refspec_nr, const char **refspec, int flags,
147-
int * nonfastforward);
148+
unsigned int * reject_reasons);
148149

149150
const struct ref *transport_get_remote_refs(struct transport *transport);
150151

@@ -170,7 +171,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v
170171
int transport_refs_pushed(struct ref *ref);
171172

172173
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);
174175

175176
typedef void alternate_ref_fn(const struct ref *, void *);
176177
extern void for_each_alternate_ref(alternate_ref_fn, void *);

0 commit comments

Comments
 (0)