diff options
Diffstat (limited to 'bundle.c')
-rw-r--r-- | bundle.c | 60 |
1 files changed, 28 insertions, 32 deletions
@@ -7,18 +7,15 @@ #include "list-objects.h" #include "run-command.h" #include "refs.h" +#include "argv-array.h" static const char bundle_signature[] = "# v2 git bundle\n"; static void add_to_ref_list(const unsigned char *sha1, const char *name, struct ref_list *list) { - if (list->nr + 1 >= list->alloc) { - list->alloc = alloc_nr(list->nr + 1); - list->list = xrealloc(list->list, - list->alloc * sizeof(list->list[0])); - } - memcpy(list->list[list->nr].sha1, sha1, 20); + ALLOC_GROW(list->list, list->nr + 1, list->alloc); + hashcpy(list->list[list->nr].sha1, sha1); list->list[list->nr].name = xstrdup(name); list->nr++; } @@ -57,7 +54,7 @@ static int parse_bundle_header(int fd, struct bundle_header *header, * followed by SP and subject line. */ if (get_sha1_hex(buf.buf, sha1) || - (40 <= buf.len && !isspace(buf.buf[40])) || + (buf.len > 40 && !isspace(buf.buf[40])) || (!is_prereq && buf.len <= 40)) { if (report_path) error(_("unrecognized header: %s%s (%d)"), @@ -183,17 +180,17 @@ int verify_bundle(struct bundle_header *header, int verbose) struct ref_list *r; r = &header->references; - printf_ln(Q_("The bundle contains %d ref", - "The bundle contains %d refs", + printf_ln(Q_("The bundle contains this ref:", + "The bundle contains these %d refs:", r->nr), r->nr); list_refs(r, 0, NULL); + r = &header->prerequisites; if (!r->nr) { printf_ln(_("The bundle records a complete history.")); } else { - r = &header->prerequisites; - printf_ln(Q_("The bundle requires this ref", - "The bundle requires these %d refs", + printf_ln(Q_("The bundle requires this ref:", + "The bundle requires these %d refs:", r->nr), r->nr); list_refs(r, 0, NULL); @@ -234,13 +231,13 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) } int create_bundle(struct bundle_header *header, const char *path, - int argc, const char **argv) + int argc, const char **argv) { static struct lock_file lock; int bundle_fd = -1; int bundle_to_stdout; - const char **argv_boundary = xmalloc((argc + 4) * sizeof(const char *)); - const char **argv_pack = xmalloc(6 * sizeof(const char *)); + struct argv_array argv_boundary = ARGV_ARRAY_INIT; + struct argv_array argv_pack = ARGV_ARRAY_INIT; int i, ref_count = 0; struct strbuf buf = STRBUF_INIT; struct rev_info revs; @@ -262,13 +259,14 @@ int create_bundle(struct bundle_header *header, const char *path, init_revisions(&revs, NULL); /* write prerequisites */ - memcpy(argv_boundary + 3, argv + 1, argc * sizeof(const char *)); - argv_boundary[0] = "rev-list"; - argv_boundary[1] = "--boundary"; - argv_boundary[2] = "--pretty=oneline"; - argv_boundary[argc + 2] = NULL; + argv_array_pushl(&argv_boundary, + "rev-list", "--boundary", "--pretty=oneline", + NULL); + for (i = 1; i < argc; i++) + argv_array_push(&argv_boundary, argv[i]); + memset(&rls, 0, sizeof(rls)); - rls.argv = argv_boundary; + rls.argv = argv_boundary.argv; rls.out = -1; rls.git_cmd = 1; if (start_command(&rls)) @@ -279,12 +277,12 @@ int create_bundle(struct bundle_header *header, const char *path, if (buf.len > 0 && buf.buf[0] == '-') { write_or_die(bundle_fd, buf.buf, buf.len); if (!get_sha1_hex(buf.buf + 1, sha1)) { - struct object *object = parse_object(sha1); + struct object *object = parse_object_or_die(sha1, buf.buf); object->flags |= UNINTERESTING; - add_pending_object(&revs, object, xstrdup(buf.buf)); + add_pending_object(&revs, object, buf.buf); } } else if (!get_sha1_hex(buf.buf, sha1)) { - struct object *object = parse_object(sha1); + struct object *object = parse_object_or_die(sha1, buf.buf); object->flags |= SHOWN; } } @@ -361,7 +359,7 @@ int create_bundle(struct bundle_header *header, const char *path, * end up triggering "empty bundle" * error. */ - obj = parse_object(sha1); + obj = parse_object_or_die(sha1, e->name); obj->flags |= SHOWN; add_pending_object(&revs, obj, e->name); } @@ -383,14 +381,12 @@ int create_bundle(struct bundle_header *header, const char *path, write_or_die(bundle_fd, "\n", 1); /* write pack */ - argv_pack[0] = "pack-objects"; - argv_pack[1] = "--all-progress-implied"; - argv_pack[2] = "--stdout"; - argv_pack[3] = "--thin"; - argv_pack[4] = "--delta-base-offset"; - argv_pack[5] = NULL; + argv_array_pushl(&argv_pack, + "pack-objects", "--all-progress-implied", + "--stdout", "--thin", "--delta-base-offset", + NULL); memset(&rls, 0, sizeof(rls)); - rls.argv = argv_pack; + rls.argv = argv_pack.argv; rls.in = -1; rls.out = bundle_fd; rls.git_cmd = 1; |