{"thread":{"id":"37339","subject":"[PATCH] send-pack: move REF_STATUS_REJECT_NODELETE logic a bit higher","startedAt":"2014-08-12T22:13:27Z","lastAt":"2014-08-12T22:13:27Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"247630","messageId":"xmqqr40l4arc.fsf@gitster.dls.corp.google.com","threadId":"37339","inReplyTo":null,"subject":"[PATCH] send-pack: move REF_STATUS_REJECT_NODELETE logic a bit higher","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-08-12T22:13:27Z","receivedAt":"2014-08-12T22:13:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is more of an RFH than a PATCH.  I think we would want to\nencapsulate the logic to set STATUS_REJECT_NODELETE in\nset_ref_status_for_push() function, but I do not see a good code\nstructure to do so, given the constraints of the dataflow (i.e. the\nprotocol capability is only inspected here with server_supports()).\n\nThe motivation behind this patch is that I want to move the \"Among\nrefs on remote_refs list, these are not going to be updated on the\nremote end\" logic into a separate helper function in the next step\nand call that before we enter in this per-ref main loop.\n\n-- >8 --\n20e8b465 (refactor ref status logic for pushing, 2010-01-08)\nrestructured the code to set status for each ref to be pushed, but\ndid not quite go far enough.  We inspect the status set earlier by\nset_refs_status_for_push() and then perform yet another update to\nthe status of a ref with an otherwise OK status to be deleted to\nmark it with REF_STATUS_REJECT_NODELETE when the protocol tells us\nnever to delete.\n\nSplit the latter into a separate loop that comes before we enter the\nper-ref loop.  This way we would have one less condition to check in\nthe main loop.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n send-pack.c | 14 +++++++++-----\n 1 file changed, 9 insertions(+), 5 deletions(-)\n\ndiff --git a/send-pack.c b/send-pack.c\nindex 6129b0f..51497c3 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -231,6 +231,14 @@ int send_pack(struct send_pack_args *args,\n \t\treturn 0;\n \t}\n \n+\t/*\n+\t * Why is delete-refs so specific to send-pack machinery\n+\t * that set_ref_status_for_push() cannot set this bit for us???\n+\t */\n+\tfor (ref = remote_refs; ref; ref = ref->next)\n+\t\tif (ref->deletion && !allow_deleting_refs)\n+\t\t\tref->status = REF_STATUS_REJECT_NODELETE;\n+\n \tif (!args->dry_run)\n \t\tadvertise_shallow_grafts_buf(&req_buf);\n \n@@ -249,17 +257,13 @@ int send_pack(struct send_pack_args *args,\n \t\tcase REF_STATUS_REJECT_FETCH_FIRST:\n \t\tcase REF_STATUS_REJECT_NEEDS_FORCE:\n \t\tcase REF_STATUS_REJECT_STALE:\n+\t\tcase REF_STATUS_REJECT_NODELETE:\n \t\tcase REF_STATUS_UPTODATE:\n \t\t\tcontinue;\n \t\tdefault:\n \t\t\t; /* do nothing */\n \t\t}\n \n-\t\tif (ref->deletion && !allow_deleting_refs) {\n-\t\t\tref->status = REF_STATUS_REJECT_NODELETE;\n-\t\t\tcontinue;\n-\t\t}\n-\n \t\tif (!ref->deletion)\n \t\t\tnew_refs++;\n \n-- \n2.1.0-rc2-243-g9c8a734\n"}]}