t1007: add hash-object --literally tests
[gitweb.git] / connect.c
index 94a66502464400d5dfc47a4151cc2fd01780a0a4..87b52026326e8c0f0296e80d64c784888f719a8e 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -64,9 +64,7 @@ static void parse_one_symref_info(struct string_list *symref, const char *val, i
        if (!len)
                return; /* just "symref" */
        /* e.g. "symref=HEAD:refs/heads/master" */
-       sym = xmalloc(len + 1);
-       memcpy(sym, val, len);
-       sym[len] = '\0';
+       sym = xmemdupz(val, len);
        target = strchr(sym, ':');
        if (!target)
                /* just "symref=something" */
@@ -129,6 +127,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                char *name;
                int len, name_len;
                char *buffer = packet_buffer;
+               const char *arg;
 
                len = packet_read(in, &src_buf, &src_len,
                                  packet_buffer, sizeof(packet_buffer),
@@ -140,12 +139,12 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
                if (!len)
                        break;
 
-               if (len > 4 && starts_with(buffer, "ERR "))
-                       die("remote error: %s", buffer + 4);
+               if (len > 4 && skip_prefix(buffer, "ERR ", &arg))
+                       die("remote error: %s", arg);
 
-               if (len == 48 && starts_with(buffer, "shallow ")) {
-                       if (get_sha1_hex(buffer + 8, old_sha1))
-                               die("protocol error: expected shallow sha-1, got '%s'", buffer + 8);
+               if (len == 48 && skip_prefix(buffer, "shallow ", &arg)) {
+                       if (get_sha1_hex(arg, old_sha1))
+                               die("protocol error: expected shallow sha-1, got '%s'", arg);
                        if (!shallow_points)
                                die("repository on the other end cannot be shallow");
                        sha1_array_append(shallow_points, old_sha1);
@@ -538,7 +537,8 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
 
        get_host_and_port(&host, &port);
 
-       proxy = xcalloc(1, sizeof(*proxy));
+       proxy = xmalloc(sizeof(*proxy));
+       child_process_init(proxy);
        argv_array_push(&proxy->args, git_proxy_command);
        argv_array_push(&proxy->args, host);
        argv_array_push(&proxy->args, port);
@@ -640,7 +640,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
        return protocol;
 }
 
-static struct child_process no_fork;
+static struct child_process no_fork = CHILD_PROCESS_INIT;
 
 /*
  * This returns a dummy child_process if the transport protocol does not
@@ -695,7 +695,8 @@ struct child_process *git_connect(int fd[2], const char *url,
                             target_host, 0);
                free(target_host);
        } else {
-               conn = xcalloc(1, sizeof(*conn));
+               conn = xmalloc(sizeof(*conn));
+               child_process_init(conn);
 
                strbuf_addstr(&cmd, prog);
                strbuf_addch(&cmd, ' ');