upload-pack: prepare to extend allow-tip-sha1-in-want

To allow future extensions, e.g. allowing non-tip sha1, replace the boolean allow_tip_sha1_in_want variable with the flag-style allow_request_with_bare_object_name variable. Signed-off-by: Fredrik Medley <fredrik.medley@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Fredrik Medley committed May 21, 2015 at 22:23 UTC 7199c093ad4a90bd0d9012681b6a148ab8c945e3
2 files changed +19 -10
fetch-pack.c
+6 -3
@@ -43,7 +43,10 @@ static int marked;
43 #define MAX_IN_VAIN 256
44
45 static struct prio_queue rev_list = { compare_commits_by_commit_date };
46 -static int non_common_revs, multi_ack, use_sideband, allow_tip_sha1_in_want;
46 +static int non_common_revs, multi_ack, use_sideband;
47 +/* Allow specifying sha1 if it is a ref tip. */
48 +#define ALLOW_TIP_SHA1 01
49 +static unsigned int allow_unadvertised_object_request;
50
51 static void rev_list_push(struct commit *commit, int mark)
52 {
@@ -542,7 +545,7 @@ static void filter_refs(struct fetch_pack_args *args,
545 }
546
547 /* Append unmatched requests to the list */
545 - if (allow_tip_sha1_in_want) {
548 + if ((allow_unadvertised_object_request & ALLOW_TIP_SHA1)) {
549 for (i = 0; i < nr_sought; i++) {
550 unsigned char sha1[20];
551
@@ -821,7 +824,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
824 if (server_supports("allow-tip-sha1-in-want")) {
825 if (args->verbose)
826 fprintf(stderr, "Server supports allow-tip-sha1-in-want\n");
824 - allow_tip_sha1_in_want = 1;
827 + allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
828 }
829 if (!server_supports("thin-pack"))
830 args->use_thin_pack = 0;
upload-pack.c
+13 -7
@@ -35,7 +35,9 @@ static int multi_ack;
35 static int no_done;
36 static int use_thin_pack, use_ofs_delta, use_include_tag;
37 static int no_progress, daemon_mode;
38 -static int allow_tip_sha1_in_want;
38 +/* Allow specifying sha1 if it is a ref tip. */
39 +#define ALLOW_TIP_SHA1 01
40 +static unsigned int allow_unadvertised_object_request;
41 static int shallow_nr;
42 static struct object_array have_obj;
43 static struct object_array want_obj;
@@ -442,8 +444,8 @@ static int get_common_commits(void)
444
445 static int is_our_ref(struct object *o)
446 {
445 - return o->flags &
446 - ((allow_tip_sha1_in_want ? HIDDEN_REF : 0) | OUR_REF);
447 + int allow_hidden_ref = (allow_unadvertised_object_request & ALLOW_TIP_SHA1);
448 + return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
449 }
450
451 static void check_non_tip(void)
@@ -727,7 +729,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
729 packet_write(1, "%s %s%c%s%s%s%s agent=%s\n",
730 sha1_to_hex(sha1), refname_nons,
731 0, capabilities,
730 - allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "",
732 + (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
733 + " allow-tip-sha1-in-want" : "",
734 stateless_rpc ? " no-done" : "",
735 symref_info.buf,
736 git_user_agent_sanitized());
@@ -787,9 +790,12 @@ static void upload_pack(void)
790
791 static int upload_pack_config(const char *var, const char *value, void *unused)
792 {
790 - if (!strcmp("uploadpack.allowtipsha1inwant", var))
791 - allow_tip_sha1_in_want = git_config_bool(var, value);
792 - else if (!strcmp("uploadpack.keepalive", var)) {
793 + if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
794 + if (git_config_bool(var, value))
795 + allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
796 + else
797 + allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
798 + } else if (!strcmp("uploadpack.keepalive", var)) {
799 keepalive = git_config_int(var, value);
800 if (!keepalive)
801 keepalive = -1;