Skip to content

Commit 7199c09

Browse files
morotengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bc0a474 commit 7199c09

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

fetch-pack.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ static int marked;
4343
#define MAX_IN_VAIN 256
4444

4545
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;
4750

4851
static void rev_list_push(struct commit *commit, int mark)
4952
{
@@ -542,7 +545,7 @@ static void filter_refs(struct fetch_pack_args *args,
542545
}
543546

544547
/* Append unmatched requests to the list */
545-
if (allow_tip_sha1_in_want) {
548+
if ((allow_unadvertised_object_request & ALLOW_TIP_SHA1)) {
546549
for (i = 0; i < nr_sought; i++) {
547550
unsigned char sha1[20];
548551

@@ -821,7 +824,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
821824
if (server_supports("allow-tip-sha1-in-want")) {
822825
if (args->verbose)
823826
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;
825828
}
826829
if (!server_supports("thin-pack"))
827830
args->use_thin_pack = 0;

upload-pack.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ static int multi_ack;
3535
static int no_done;
3636
static int use_thin_pack, use_ofs_delta, use_include_tag;
3737
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;
3941
static int shallow_nr;
4042
static struct object_array have_obj;
4143
static struct object_array want_obj;
@@ -442,8 +444,8 @@ static int get_common_commits(void)
442444

443445
static int is_our_ref(struct object *o)
444446
{
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);
447449
}
448450

449451
static void check_non_tip(void)
@@ -727,7 +729,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
727729
packet_write(1, "%s %s%c%s%s%s%s agent=%s\n",
728730
sha1_to_hex(sha1), refname_nons,
729731
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" : "",
731734
stateless_rpc ? " no-done" : "",
732735
symref_info.buf,
733736
git_user_agent_sanitized());
@@ -787,9 +790,12 @@ static void upload_pack(void)
787790

788791
static int upload_pack_config(const char *var, const char *value, void *unused)
789792
{
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)) {
793799
keepalive = git_config_int(var, value);
794800
if (!keepalive)
795801
keepalive = -1;

0 commit comments

Comments
 (0)