Merge branch 'ps/bundle-verify-arg'
[gitweb.git] / transport.c
index 0694a7cf3e4a8bd7bec9fefcd440d65423021a1b..f080e93dcd50e5f2329b180bae93c59a461810f8 100644 (file)
@@ -117,7 +117,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
                        return;
                }
 
-               if (hexval(buffer[0]) > 0xf)
+               if (!isxdigit(buffer[0]))
                        continue;
                len = strlen(buffer);
                if (len && buffer[len - 1] == '\n')
@@ -283,7 +283,6 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 {
        struct strbuf *buf = data;
        int len = buf->len;
-       FILE *f;
 
        /* when called via for_each_ref(), flags is non-zero */
        if (flags && !starts_with(name, "refs/heads/") &&
@@ -292,10 +291,9 @@ static int write_one_ref(const char *name, const unsigned char *sha1,
 
        strbuf_addstr(buf, name);
        if (safe_create_leading_directories(buf->buf) ||
-                       !(f = fopen(buf->buf, "w")) ||
-                       fprintf(f, "%s\n", sha1_to_hex(sha1)) < 0 ||
-                       fclose(f))
-               return error("problems writing temporary file %s", buf->buf);
+           write_file(buf->buf, 0, "%s\n", sha1_to_hex(sha1)))
+               return error("problems writing temporary file %s: %s",
+                            buf->buf, strerror(errno));
        strbuf_setlen(buf, len);
        return 0;
 }
@@ -519,7 +517,7 @@ static int fetch_refs_via_pack(struct transport *transport,
                               int nr_heads, struct ref **to_fetch)
 {
        struct git_transport_data *data = transport->data;
-       const struct ref *refs;
+       struct ref *refs;
        char *dest = xstrdup(transport->url);
        struct fetch_pack_args args;
        struct ref *refs_tmp = NULL;
@@ -552,15 +550,17 @@ static int fetch_refs_via_pack(struct transport *transport,
                          &transport->pack_lockfile);
        close(data->fd[0]);
        close(data->fd[1]);
-       if (finish_connect(data->conn))
+       if (finish_connect(data->conn)) {
+               free_refs(refs);
                refs = NULL;
+       }
        data->conn = NULL;
        data->got_remote_heads = 0;
        data->options.self_contained_and_connected =
                args.self_contained_and_connected;
 
        free_refs(refs_tmp);
-
+       free_refs(refs);
        free(dest);
        return (refs ? 0 : -1);
 }