builtin/commit.c: extract ignore_non_trailer() helper function
[gitweb.git] / fetch-pack.c
index 094267fd80cdb09feec75c89aa2f4931f11e583d..fab5e801755a9152aa19baf72b609052e1b32035 100644 (file)
@@ -185,36 +185,6 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
        }
 }
 
-struct write_shallow_data {
-       struct strbuf *out;
-       int use_pack_protocol;
-       int count;
-};
-
-static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
-{
-       struct write_shallow_data *data = cb_data;
-       const char *hex = sha1_to_hex(graft->sha1);
-       data->count++;
-       if (data->use_pack_protocol)
-               packet_buf_write(data->out, "shallow %s", hex);
-       else {
-               strbuf_addstr(data->out, hex);
-               strbuf_addch(data->out, '\n');
-       }
-       return 0;
-}
-
-static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
-{
-       struct write_shallow_data data;
-       data.out = out;
-       data.use_pack_protocol = use_pack_protocol;
-       data.count = 0;
-       for_each_commit_graft(write_one_shallow, &data);
-       return data.count;
-}
-
 static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 {
        int len;
@@ -537,7 +507,7 @@ static void filter_refs(struct fetch_pack_args *args,
                next = ref->next;
 
                if (!memcmp(ref->name, "refs/", 5) &&
-                   check_refname_format(ref->name + 5, 0))
+                   check_refname_format(ref->name, 0))
                        ; /* trash */
                else {
                        while (i < nr_sought) {
@@ -689,7 +659,7 @@ static int get_pack(struct fetch_pack_args *args,
        const char *argv[22];
        char keep_arg[256];
        char hdr_arg[256];
-       const char **av;
+       const char **av, *cmd_name;
        int do_keep = args->keep_pack;
        struct child_process cmd;
        int ret;
@@ -736,7 +706,7 @@ static int get_pack(struct fetch_pack_args *args,
        if (do_keep) {
                if (pack_lockfile)
                        cmd.out = -1;
-               *av++ = "index-pack";
+               *av++ = cmd_name = "index-pack";
                *av++ = "--stdin";
                if (!args->quiet && !args->no_progress)
                        *av++ = "-v";
@@ -753,7 +723,7 @@ static int get_pack(struct fetch_pack_args *args,
                        *av++ = "--check-self-contained-and-connected";
        }
        else {
-               *av++ = "unpack-objects";
+               *av++ = cmd_name = "unpack-objects";
                if (args->quiet || args->no_progress)
                        *av++ = "-q";
                args->check_self_contained_and_connected = 0;
@@ -771,19 +741,23 @@ static int get_pack(struct fetch_pack_args *args,
        cmd.in = demux.out;
        cmd.git_cmd = 1;
        if (start_command(&cmd))
-               die("fetch-pack: unable to fork off %s", argv[0]);
+               die("fetch-pack: unable to fork off %s", cmd_name);
        if (do_keep && pack_lockfile) {
                *pack_lockfile = index_pack_lockfile(cmd.out);
                close(cmd.out);
        }
 
+       if (!use_sideband)
+               /* Closed by start_command() */
+               xd[0] = -1;
+
        ret = finish_command(&cmd);
        if (!ret || (args->check_self_contained_and_connected && ret == 1))
                args->self_contained_and_connected =
                        args->check_self_contained_and_connected &&
                        ret == 0;
        else
-               die("%s failed", argv[0]);
+               die("%s failed", cmd_name);
        if (use_sideband && finish_async(&demux))
                die("error in sideband demultiplexer");
        return 0;
@@ -796,27 +770,6 @@ static int cmp_ref_by_name(const void *a_, const void *b_)
        return strcmp(a->name, b->name);
 }
 
-static void setup_alternate_shallow(void)
-{
-       struct strbuf sb = STRBUF_INIT;
-       int fd;
-
-       check_shallow_file_for_update();
-       fd = hold_lock_file_for_update(&shallow_lock, git_path("shallow"),
-                                      LOCK_DIE_ON_ERROR);
-       if (write_shallow_commits(&sb, 0)) {
-               if (write_in_full(fd, sb.buf, sb.len) != sb.len)
-                       die_errno("failed to write to %s", shallow_lock.filename);
-               alternate_shallow_file = shallow_lock.filename;
-       } else
-               /*
-                * is_repository_shallow() sees empty string as "no
-                * shallow file".
-                */
-               alternate_shallow_file = "";
-       strbuf_release(&sb);
-}
-
 static struct ref *do_fetch_pack(struct fetch_pack_args *args,
                                 int fd[2],
                                 const struct ref *orig_ref,
@@ -897,7 +850,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
        if (args->stateless_rpc)
                packet_flush(fd[1]);
        if (args->depth > 0)
-               setup_alternate_shallow();
+               setup_alternate_shallow(&shallow_lock, &alternate_shallow_file);
        else
                alternate_shallow_file = NULL;
        if (get_pack(args, fd, pack_lockfile))