receive-pack: parse feature request a bit earlier
Ideally, we should have also allowed the first "shallow" to carry the feature request trailer, but that is water under the bridge now. This makes the next step to factor out the queuing of commands easier to review. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 15, 2014 at 14:11 UTC
0e3c339bb69670b39161838de17f440480e1358a
1 file changed
+14
-12
builtin/receive-pack.c
+14
-12
@@ -840,7 +840,7 @@ static struct command *read_head_info(struct sha1_array *shallow)
840
unsigned char old_sha1[20], new_sha1[20];
841
struct command *cmd;
842
char *refname;
843
- int len, reflen;
843
+ int len, reflen, linelen;
844
845
line = packet_read_line(0, &len);
846
if (!line)
@@ -853,7 +853,18 @@ static struct command *read_head_info(struct sha1_array *shallow)
853
continue;
854
}
855
856
- if (len < 83 ||
856
+ linelen = strlen(line);
857
+ if (linelen < len) {
858
+ const char *feature_list = line + linelen + 1;
859
+ if (parse_feature_request(feature_list, "report-status"))
860
+ report_status = 1;
861
+ if (parse_feature_request(feature_list, "side-band-64k"))
862
+ use_sideband = LARGE_PACKET_MAX;
863
+ if (parse_feature_request(feature_list, "quiet"))
864
+ quiet = 1;
865
+ }
866
+
867
+ if (linelen < 83 ||
868
line[40] != ' ' ||
869
line[81] != ' ' ||
870
get_sha1_hex(line, old_sha1) ||
@@ -862,16 +873,7 @@ static struct command *read_head_info(struct sha1_array *shallow)
873
line);
874
875
refname = line + 82;
865
- reflen = strlen(refname);
866
- if (reflen + 82 < len) {
867
- const char *feature_list = refname + reflen + 1;
868
- if (parse_feature_request(feature_list, "report-status"))
869
- report_status = 1;
870
- if (parse_feature_request(feature_list, "side-band-64k"))
871
- use_sideband = LARGE_PACKET_MAX;
872
- if (parse_feature_request(feature_list, "quiet"))
873
- quiet = 1;
874
- }
876
+ reflen = linelen - 82;
877
cmd = xcalloc(1, sizeof(struct command) + reflen + 1);
878
hashcpy(cmd->old_sha1, old_sha1);
879
hashcpy(cmd->new_sha1, new_sha1);