receive-pack: parse feature request a bit earlier
[gitweb.git] / builtin / receive-pack.c
index c3230817db4a7676eb74335b254f30597e66edd9..a91eec8b1c3e1dfd955d370c112a7bd2010243bd 100644 (file)
@@ -438,7 +438,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
        uint32_t mask = 1 << (cmd->index % 32);
        int i;
 
-       trace_printf_key("GIT_TRACE_SHALLOW",
+       trace_printf_key(&trace_shallow,
                         "shallow: update_shallow_ref %s\n", cmd->ref_name);
        for (i = 0; i < si->shallow->nr; i++)
                if (si->used_shallow[i] &&
@@ -614,12 +614,9 @@ static void run_update_post_hook(struct command *commands)
        argv[0] = hook;
 
        for (argc = 1, cmd = commands; cmd; cmd = cmd->next) {
-               char *p;
                if (cmd->error_string || cmd->did_not_exist)
                        continue;
-               p = xmalloc(strlen(cmd->ref_name) + 1);
-               strcpy(p, cmd->ref_name);
-               argv[argc] = p;
+               argv[argc] = xstrdup(cmd->ref_name);
                argc++;
        }
        argv[argc] = NULL;
@@ -843,7 +840,7 @@ static struct command *read_head_info(struct sha1_array *shallow)
                unsigned char old_sha1[20], new_sha1[20];
                struct command *cmd;
                char *refname;
-               int len, reflen;
+               int len, reflen, linelen;
 
                line = packet_read_line(0, &len);
                if (!line)
@@ -856,7 +853,18 @@ static struct command *read_head_info(struct sha1_array *shallow)
                        continue;
                }
 
-               if (len < 83 ||
+               linelen = strlen(line);
+               if (linelen < len) {
+                       const char *feature_list = line + linelen + 1;
+                       if (parse_feature_request(feature_list, "report-status"))
+                               report_status = 1;
+                       if (parse_feature_request(feature_list, "side-band-64k"))
+                               use_sideband = LARGE_PACKET_MAX;
+                       if (parse_feature_request(feature_list, "quiet"))
+                               quiet = 1;
+               }
+
+               if (linelen < 83 ||
                    line[40] != ' ' ||
                    line[81] != ' ' ||
                    get_sha1_hex(line, old_sha1) ||
@@ -865,20 +873,12 @@ static struct command *read_head_info(struct sha1_array *shallow)
                            line);
 
                refname = line + 82;
-               reflen = strlen(refname);
-               if (reflen + 82 < len) {
-                       const char *feature_list = refname + reflen + 1;
-                       if (parse_feature_request(feature_list, "report-status"))
-                               report_status = 1;
-                       if (parse_feature_request(feature_list, "side-band-64k"))
-                               use_sideband = LARGE_PACKET_MAX;
-                       if (parse_feature_request(feature_list, "quiet"))
-                               quiet = 1;
-               }
-               cmd = xcalloc(1, sizeof(struct command) + len - 80);
+               reflen = linelen - 82;
+               cmd = xcalloc(1, sizeof(struct command) + reflen + 1);
                hashcpy(cmd->old_sha1, old_sha1);
                hashcpy(cmd->new_sha1, new_sha1);
-               memcpy(cmd->ref_name, line + 82, len - 81);
+               memcpy(cmd->ref_name, refname, reflen);
+               cmd->ref_name[reflen] = '\0';
                *p = cmd;
                p = &cmd->next;
        }
@@ -1125,7 +1125,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
        int advertise_refs = 0;
        int stateless_rpc = 0;
        int i;
-       char *dir = NULL;
+       const char *dir = NULL;
        struct command *commands;
        struct sha1_array shallow = SHA1_ARRAY_INIT;
        struct sha1_array ref = SHA1_ARRAY_INIT;
@@ -1160,7 +1160,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
                }
                if (dir)
                        usage(receive_pack_usage);
-               dir = xstrdup(arg);
+               dir = arg;
        }
        if (!dir)
                usage(receive_pack_usage);