Skip to content

Commit e40671a

Browse files
committed
send-pack: refactor decision to send update per ref
A new helper function ref_update_to_be_sent() decides for each ref if the update is to be sent based on the status previously set by set_ref_status_for_push() and also if this is a mirrored push. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 621b059 commit e40671a

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

send-pack.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,26 @@ static void advertise_shallow_grafts_buf(struct strbuf *sb)
190190
for_each_commit_graft(advertise_shallow_grafts_cb, sb);
191191
}
192192

193+
static int ref_update_to_be_sent(const struct ref *ref, const struct send_pack_args *args)
194+
{
195+
if (!ref->peer_ref && !args->send_mirror)
196+
return 0;
197+
198+
/* Check for statuses set by set_ref_status_for_push() */
199+
switch (ref->status) {
200+
case REF_STATUS_REJECT_NONFASTFORWARD:
201+
case REF_STATUS_REJECT_ALREADY_EXISTS:
202+
case REF_STATUS_REJECT_FETCH_FIRST:
203+
case REF_STATUS_REJECT_NEEDS_FORCE:
204+
case REF_STATUS_REJECT_STALE:
205+
case REF_STATUS_REJECT_NODELETE:
206+
case REF_STATUS_UPTODATE:
207+
return 0;
208+
default:
209+
return 1;
210+
}
211+
}
212+
193213
int send_pack(struct send_pack_args *args,
194214
int fd[], struct child_process *conn,
195215
struct ref *remote_refs,
@@ -248,23 +268,9 @@ int send_pack(struct send_pack_args *args,
248268
*/
249269
new_refs = 0;
250270
for (ref = remote_refs; ref; ref = ref->next) {
251-
if (!ref->peer_ref && !args->send_mirror)
271+
if (!ref_update_to_be_sent(ref, args))
252272
continue;
253273

254-
/* Check for statuses set by set_ref_status_for_push() */
255-
switch (ref->status) {
256-
case REF_STATUS_REJECT_NONFASTFORWARD:
257-
case REF_STATUS_REJECT_ALREADY_EXISTS:
258-
case REF_STATUS_REJECT_FETCH_FIRST:
259-
case REF_STATUS_REJECT_NEEDS_FORCE:
260-
case REF_STATUS_REJECT_STALE:
261-
case REF_STATUS_REJECT_NODELETE:
262-
case REF_STATUS_UPTODATE:
263-
continue;
264-
default:
265-
; /* do nothing */
266-
}
267-
268274
if (!ref->deletion)
269275
new_refs++;
270276

0 commit comments

Comments
 (0)