]> git.ipfire.org Git - thirdparty/git.git/blobdiff - bundle.c
bundle API: change "flags" to be "extra_index_pack_args"
[thirdparty/git.git] / bundle.c
index 693d61955140093d049ec64816379cf5b69796b3..a0bb687b0f4ea30d44883dcb9d4de5bf1e5963ea 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -23,13 +23,16 @@ static struct {
        { 3, v3_bundle_signature },
 };
 
-static void add_to_ref_list(const struct object_id *oid, const char *name,
-               struct ref_list *list)
+void bundle_header_init(struct bundle_header *header)
 {
-       ALLOC_GROW(list->list, list->nr + 1, list->alloc);
-       oidcpy(&list->list[list->nr].oid, oid);
-       list->list[list->nr].name = xstrdup(name);
-       list->nr++;
+       struct bundle_header blank = BUNDLE_HEADER_INIT;
+       memcpy(header, &blank, sizeof(*header));
+}
+
+void bundle_header_release(struct bundle_header *header)
+{
+       string_list_clear(&header->prerequisites, 1);
+       string_list_clear(&header->references, 1);
 }
 
 static int parse_capability(struct bundle_header *header, const char *capability)
@@ -112,10 +115,11 @@ static int parse_bundle_header(int fd, struct bundle_header *header,
                        status = -1;
                        break;
                } else {
+                       struct object_id *dup = oiddup(&oid);
                        if (is_prereq)
-                               add_to_ref_list(&oid, "", &header->prerequisites);
+                               string_list_append(&header->prerequisites, "")->util = dup;
                        else
-                               add_to_ref_list(&oid, p + 1, &header->references);
+                               string_list_append(&header->references, p + 1)->util = dup;
                }
        }
 
@@ -139,33 +143,38 @@ int read_bundle_header(const char *path, struct bundle_header *header)
 
 int is_bundle(const char *path, int quiet)
 {
-       struct bundle_header header;
+       struct bundle_header header = BUNDLE_HEADER_INIT;
        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);
+       bundle_header_release(&header);
        return (fd >= 0);
 }
 
-static int list_refs(struct ref_list *r, int argc, const char **argv)
+static int list_refs(struct string_list *r, int argc, const char **argv)
 {
        int i;
 
        for (i = 0; i < r->nr; i++) {
+               struct object_id *oid;
+               const char *name;
+
                if (argc > 1) {
                        int j;
                        for (j = 1; j < argc; j++)
-                               if (!strcmp(r->list[i].name, argv[j]))
+                               if (!strcmp(r->items[i].string, argv[j]))
                                        break;
                        if (j == argc)
                                continue;
                }
-               printf("%s %s\n", oid_to_hex(&r->list[i].oid),
-                               r->list[i].name);
+
+               oid = r->items[i].util;
+               name = r->items[i].string;
+               printf("%s %s\n", oid_to_hex(oid), name);
        }
        return 0;
 }
@@ -181,7 +190,7 @@ int verify_bundle(struct repository *r,
         * Do fast check, then if any prereqs are missing then go line by line
         * to be verbose about the errors
         */
-       struct ref_list *p = &header->prerequisites;
+       struct string_list *p = &header->prerequisites;
        struct rev_info revs;
        const char *argv[] = {NULL, "--all", NULL};
        struct commit *commit;
@@ -193,16 +202,18 @@ int verify_bundle(struct repository *r,
 
        repo_init_revisions(r, &revs, NULL);
        for (i = 0; i < p->nr; i++) {
-               struct ref_list_entry *e = p->list + i;
-               struct object *o = parse_object(r, &e->oid);
+               struct string_list_item *e = p->items + i;
+               const char *name = e->string;
+               struct object_id *oid = e->util;
+               struct object *o = parse_object(r, oid);
                if (o) {
                        o->flags |= PREREQ_MARK;
-                       add_pending_object(&revs, o, e->name);
+                       add_pending_object(&revs, o, name);
                        continue;
                }
                if (++ret == 1)
                        error("%s", message);
-               error("%s %s", oid_to_hex(&e->oid), e->name);
+               error("%s %s", oid_to_hex(oid), name);
        }
        if (revs.pending.nr != p->nr)
                return ret;
@@ -218,26 +229,29 @@ int verify_bundle(struct repository *r,
                        i--;
 
        for (i = 0; i < p->nr; i++) {
-               struct ref_list_entry *e = p->list + i;
-               struct object *o = parse_object(r, &e->oid);
+               struct string_list_item *e = p->items + i;
+               const char *name = e->string;
+               const struct object_id *oid = e->util;
+               struct object *o = parse_object(r, oid);
                assert(o); /* otherwise we'd have returned early */
                if (o->flags & SHOWN)
                        continue;
                if (++ret == 1)
                        error("%s", message);
-               error("%s %s", oid_to_hex(&e->oid), e->name);
+               error("%s %s", oid_to_hex(oid), name);
        }
 
        /* Clean up objects used, as they will be reused. */
        for (i = 0; i < p->nr; i++) {
-               struct ref_list_entry *e = p->list + i;
-               commit = lookup_commit_reference_gently(r, &e->oid, 1);
+               struct string_list_item *e = p->items + i;
+               struct object_id *oid = e->util;
+               commit = lookup_commit_reference_gently(r, oid, 1);
                if (commit)
                        clear_commit_marks(commit, ALL_REV_FLAGS);
        }
 
        if (verbose) {
-               struct ref_list *r;
+               struct string_list *r;
 
                r = &header->references;
                printf_ln(Q_("The bundle contains this ref:",
@@ -555,18 +569,18 @@ err:
 }
 
 int unbundle(struct repository *r, struct bundle_header *header,
-            int bundle_fd, int flags)
+            int bundle_fd, struct strvec *extra_index_pack_args)
 {
-       const char *argv_index_pack[] = {"index-pack",
-                                        "--fix-thin", "--stdin", NULL, NULL};
        struct child_process ip = CHILD_PROCESS_INIT;
+       strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
 
-       if (flags & BUNDLE_VERBOSE)
-               argv_index_pack[3] = "-v";
+       if (extra_index_pack_args) {
+               strvec_pushv(&ip.args, extra_index_pack_args->v);
+               strvec_clear(extra_index_pack_args);
+       }
 
        if (verify_bundle(r, header, 0))
                return -1;
-       ip.argv = argv_index_pack;
        ip.in = bundle_fd;
        ip.no_stdout = 1;
        ip.git_cmd = 1;