Code

completion: fix issue with process substitution not working on Git for Windows
[git.git] / bundle.c
index 3aa715c40af149f26e68b1bc1ebd9c80cdc49246..08020bc3a258e055a8f5f6974217cf482edc3ee3 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -40,19 +40,18 @@ static int strbuf_readline_fd(struct strbuf *sb, int fd)
        return 0;
 }
 
-int read_bundle_header(const char *path, struct bundle_header *header)
+static int parse_bundle_header(int fd, struct bundle_header *header,
+                              const char *report_path)
 {
        struct strbuf buf = STRBUF_INIT;
-       int fd = open(path, O_RDONLY);
        int status = 0;
 
-       if (fd < 0)
-               return error("could not open '%s'", path);
-
        /* The bundle header begins with the signature */
        if (strbuf_readline_fd(&buf, fd) ||
            strcmp(buf.buf, bundle_signature)) {
-               error("'%s' does not look like a v2 bundle file", path);
+               if (report_path)
+                       error("'%s' does not look like a v2 bundle file",
+                             report_path);
                status = -1;
                goto abort;
        }
@@ -77,8 +76,9 @@ int read_bundle_header(const char *path, struct bundle_header *header)
                if (get_sha1_hex(buf.buf, sha1) ||
                    (40 <= buf.len && !isspace(buf.buf[40])) ||
                    (!is_prereq && buf.len <= 40)) {
-                       error("unrecognized header: %s%s (%d)",
-                             (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
+                       if (report_path)
+                               error("unrecognized header: %s%s (%d)",
+                                     (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
                        status = -1;
                        break;
                } else {
@@ -98,6 +98,29 @@ int read_bundle_header(const char *path, struct bundle_header *header)
        return fd;
 }
 
+int read_bundle_header(const char *path, struct bundle_header *header)
+{
+       int fd = open(path, O_RDONLY);
+
+       if (fd < 0)
+               return error("could not open '%s'", path);
+       return parse_bundle_header(fd, header, path);
+}
+
+int is_bundle(const char *path, int quiet)
+{
+       struct bundle_header header;
+       int fd = open(path, O_RDONLY);
+
+       if (fd < 0)
+               return 0;
+       memset(&header, 0, sizeof(header));
+       fd = parse_bundle_header(fd, &header, quiet ? NULL : path);
+       if (fd >= 0)
+               close(fd);
+       return (fd >= 0);
+}
+
 static int list_refs(struct ref_list *r, int argc, const char **argv)
 {
        int i;
@@ -151,11 +174,8 @@ int verify_bundle(struct bundle_header *header, int verbose)
        req_nr = revs.pending.nr;
        setup_revisions(2, argv, &revs, NULL);
 
-       memset(&refs, 0, sizeof(struct object_array));
-       for (i = 0; i < revs.pending.nr; i++) {
-               struct object_array_entry *e = revs.pending.objects + i;
-               add_object_array(e->item, e->name, &refs);
-       }
+       refs = revs.pending;
+       revs.leak_pending = 1;
 
        if (prepare_revision_walk(&revs))
                die("revision walk setup failed");
@@ -173,8 +193,8 @@ int verify_bundle(struct bundle_header *header, int verbose)
                                refs.objects[i].name);
                }
 
-       for (i = 0; i < refs.nr; i++)
-               clear_commit_marks((struct commit *)refs.objects[i].item, -1);
+       clear_commit_marks_for_object_array(&refs, ALL_REV_FLAGS);
+       free(refs.objects);
 
        if (verbose) {
                struct ref_list *r;
@@ -409,12 +429,15 @@ int create_bundle(struct bundle_header *header, const char *path,
        return 0;
 }
 
-int unbundle(struct bundle_header *header, int bundle_fd)
+int unbundle(struct bundle_header *header, int bundle_fd, int flags)
 {
        const char *argv_index_pack[] = {"index-pack",
-               "--fix-thin", "--stdin", NULL};
+                                        "--fix-thin", "--stdin", NULL, NULL};
        struct child_process ip;
 
+       if (flags & BUNDLE_VERBOSE)
+               argv_index_pack[3] = "-v";
+
        if (verify_bundle(header, 0))
                return -1;
        memset(&ip, 0, sizeof(ip));