Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 1 | #include "cache.h" |
Michael Haggerty | 697cc8e | 2014-10-01 12:28:42 +0200 | [diff] [blame] | 2 | #include "lockfile.h" |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 3 | #include "bundle.h" |
Stefan Beller | cbd53a2 | 2018-05-15 16:42:15 -0700 | [diff] [blame] | 4 | #include "object-store.h" |
Stefan Beller | 109cd76 | 2018-06-28 18:21:51 -0700 | [diff] [blame] | 5 | #include "repository.h" |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 6 | #include "object.h" |
| 7 | #include "commit.h" |
| 8 | #include "diff.h" |
| 9 | #include "revision.h" |
| 10 | #include "list-objects.h" |
| 11 | #include "run-command.h" |
Junio C Hamano | fa30383 | 2007-11-22 16:51:18 -0800 | [diff] [blame] | 12 | #include "refs.h" |
Jeff King | dbbcd44 | 2020-07-28 16:23:39 -0400 | [diff] [blame] | 13 | #include "strvec.h" |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 14 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 15 | |
| 16 | static const char v2_bundle_signature[] = "# v2 git bundle\n"; |
| 17 | static const char v3_bundle_signature[] = "# v3 git bundle\n"; |
| 18 | static struct { |
| 19 | int version; |
| 20 | const char *signature; |
| 21 | } bundle_sigs[] = { |
| 22 | { 2, v2_bundle_signature }, |
| 23 | { 3, v3_bundle_signature }, |
| 24 | }; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 25 | |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 26 | void bundle_header_init(struct bundle_header *header) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 27 | { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 28 | struct bundle_header blank = BUNDLE_HEADER_INIT; |
| 29 | memcpy(header, &blank, sizeof(*header)); |
| 30 | } |
| 31 | |
| 32 | void bundle_header_release(struct bundle_header *header) |
| 33 | { |
| 34 | string_list_clear(&header->prerequisites, 1); |
| 35 | string_list_clear(&header->references, 1); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 36 | } |
| 37 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 38 | static int parse_capability(struct bundle_header *header, const char *capability) |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 39 | { |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 40 | const char *arg; |
| 41 | if (skip_prefix(capability, "object-format=", &arg)) { |
| 42 | int algo = hash_algo_by_name(arg); |
| 43 | if (algo == GIT_HASH_UNKNOWN) |
| 44 | return error(_("unrecognized bundle hash algorithm: %s"), arg); |
| 45 | header->hash_algo = &hash_algos[algo]; |
| 46 | return 0; |
| 47 | } |
| 48 | return error(_("unknown capability '%s'"), capability); |
| 49 | } |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 50 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 51 | static int parse_bundle_signature(struct bundle_header *header, const char *line) |
| 52 | { |
| 53 | int i; |
| 54 | |
| 55 | for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) { |
| 56 | if (!strcmp(line, bundle_sigs[i].signature)) { |
| 57 | header->version = bundle_sigs[i].version; |
| 58 | return 0; |
| 59 | } |
| 60 | } |
| 61 | return -1; |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 64 | static int parse_bundle_header(int fd, struct bundle_header *header, |
| 65 | const char *report_path) |
Junio C Hamano | f3fa183 | 2007-11-08 15:35:32 -0800 | [diff] [blame] | 66 | { |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 67 | struct strbuf buf = STRBUF_INIT; |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 68 | int status = 0; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 69 | |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 70 | /* The bundle header begins with the signature */ |
Thomas Rast | 5e8617f | 2012-02-22 20:34:22 +0100 | [diff] [blame] | 71 | if (strbuf_getwholeline_fd(&buf, fd, '\n') || |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 72 | parse_bundle_signature(header, buf.buf)) { |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 73 | if (report_path) |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 74 | error(_("'%s' does not look like a v2 or v3 bundle file"), |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 75 | report_path); |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 76 | status = -1; |
| 77 | goto abort; |
| 78 | } |
| 79 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 80 | header->hash_algo = the_hash_algo; |
| 81 | |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 82 | /* The bundle header ends with an empty line */ |
Thomas Rast | 5e8617f | 2012-02-22 20:34:22 +0100 | [diff] [blame] | 83 | while (!strbuf_getwholeline_fd(&buf, fd, '\n') && |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 84 | buf.len && buf.buf[0] != '\n') { |
brian m. carlson | b8607f3 | 2017-05-01 02:28:59 +0000 | [diff] [blame] | 85 | struct object_id oid; |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 86 | int is_prereq = 0; |
brian m. carlson | b8607f3 | 2017-05-01 02:28:59 +0000 | [diff] [blame] | 87 | const char *p; |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 88 | |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 89 | strbuf_rtrim(&buf); |
| 90 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 91 | if (header->version == 3 && *buf.buf == '@') { |
| 92 | if (parse_capability(header, buf.buf + 1)) { |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 93 | status = -1; |
| 94 | break; |
| 95 | } |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 96 | continue; |
| 97 | } |
| 98 | |
| 99 | if (*buf.buf == '-') { |
| 100 | is_prereq = 1; |
| 101 | strbuf_remove(&buf, 0, 1); |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Tip lines have object name, SP, and refname. |
| 106 | * Prerequisites have object name that is optionally |
| 107 | * followed by SP and subject line. |
| 108 | */ |
brian m. carlson | 6161ce7 | 2020-06-19 17:56:00 +0000 | [diff] [blame] | 109 | if (parse_oid_hex_algop(buf.buf, &oid, &p, header->hash_algo) || |
brian m. carlson | b8607f3 | 2017-05-01 02:28:59 +0000 | [diff] [blame] | 110 | (*p && !isspace(*p)) || |
| 111 | (!is_prereq && !*p)) { |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 112 | if (report_path) |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 113 | error(_("unrecognized header: %s%s (%d)"), |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 114 | (is_prereq ? "-" : ""), buf.buf, (int)buf.len); |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 115 | status = -1; |
| 116 | break; |
| 117 | } else { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 118 | struct object_id *dup = oiddup(&oid); |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 119 | if (is_prereq) |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 120 | string_list_append(&header->prerequisites, "")->util = dup; |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 121 | else |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 122 | string_list_append(&header->references, p + 1)->util = dup; |
Junio C Hamano | e9ee84c | 2011-10-13 15:12:02 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
| 126 | abort: |
| 127 | if (status) { |
| 128 | close(fd); |
| 129 | fd = -1; |
| 130 | } |
| 131 | strbuf_release(&buf); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 132 | return fd; |
| 133 | } |
| 134 | |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 135 | int read_bundle_header(const char *path, struct bundle_header *header) |
| 136 | { |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 137 | int fd = open(path, O_RDONLY); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 138 | |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 139 | if (fd < 0) |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 140 | return error(_("could not open '%s'"), path); |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 141 | return parse_bundle_header(fd, header, path); |
| 142 | } |
| 143 | |
| 144 | int is_bundle(const char *path, int quiet) |
| 145 | { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 146 | struct bundle_header header = BUNDLE_HEADER_INIT; |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 147 | int fd = open(path, O_RDONLY); |
| 148 | |
| 149 | if (fd < 0) |
| 150 | return 0; |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 151 | fd = parse_bundle_header(fd, &header, quiet ? NULL : path); |
| 152 | if (fd >= 0) |
| 153 | close(fd); |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 154 | bundle_header_release(&header); |
Junio C Hamano | 2727b71 | 2011-10-13 15:19:31 -0700 | [diff] [blame] | 155 | return (fd >= 0); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 156 | } |
| 157 | |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 158 | static int list_refs(struct string_list *r, int argc, const char **argv) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 159 | { |
| 160 | int i; |
| 161 | |
| 162 | for (i = 0; i < r->nr; i++) { |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 163 | struct object_id *oid; |
| 164 | const char *name; |
| 165 | |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 166 | if (argc > 1) { |
| 167 | int j; |
| 168 | for (j = 1; j < argc; j++) |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 169 | if (!strcmp(r->items[i].string, argv[j])) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 170 | break; |
| 171 | if (j == argc) |
| 172 | continue; |
| 173 | } |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 174 | |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 175 | oid = r->items[i].util; |
| 176 | name = r->items[i].string; |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 177 | printf("%s %s\n", oid_to_hex(oid), name); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 178 | } |
| 179 | return 0; |
| 180 | } |
| 181 | |
Nguyễn Thái Ngọc Duy | 208acbf | 2014-03-25 20:23:26 +0700 | [diff] [blame] | 182 | /* Remember to update object flag allocation in object.h */ |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 183 | #define PREREQ_MARK (1u<<16) |
| 184 | |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 185 | int verify_bundle(struct repository *r, |
| 186 | struct bundle_header *header, |
| 187 | int verbose) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 188 | { |
| 189 | /* |
| 190 | * Do fast check, then if any prereqs are missing then go line by line |
| 191 | * to be verbose about the errors |
| 192 | */ |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 193 | struct string_list *p = &header->prerequisites; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 194 | struct rev_info revs; |
Nguyễn Thái Ngọc Duy | a80aad7 | 2009-05-21 19:32:44 +1000 | [diff] [blame] | 195 | const char *argv[] = {NULL, "--all", NULL}; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 196 | struct commit *commit; |
| 197 | int i, ret = 0, req_nr; |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 198 | const char *message = _("Repository lacks these prerequisite commits:"); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 199 | |
Johannes Schindelin | 3bbbe46 | 2019-05-27 12:59:14 -0700 | [diff] [blame] | 200 | if (!r || !r->objects || !r->objects->odb) |
| 201 | return error(_("need a repository to verify a bundle")); |
| 202 | |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 203 | repo_init_revisions(r, &revs, NULL); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 204 | for (i = 0; i < p->nr; i++) { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 205 | struct string_list_item *e = p->items + i; |
| 206 | const char *name = e->string; |
| 207 | struct object_id *oid = e->util; |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 208 | struct object *o = parse_object(r, oid); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 209 | if (o) { |
| 210 | o->flags |= PREREQ_MARK; |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 211 | add_pending_object(&revs, o, name); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 212 | continue; |
| 213 | } |
| 214 | if (++ret == 1) |
Daniel Lowe | 9db56f7 | 2008-11-10 16:07:52 -0500 | [diff] [blame] | 215 | error("%s", message); |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 216 | error("%s %s", oid_to_hex(oid), name); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 217 | } |
| 218 | if (revs.pending.nr != p->nr) |
| 219 | return ret; |
| 220 | req_nr = revs.pending.nr; |
| 221 | setup_revisions(2, argv, &revs, NULL); |
| 222 | |
Martin Koegler | 3d51e1b | 2008-02-18 08:31:56 +0100 | [diff] [blame] | 223 | if (prepare_revision_walk(&revs)) |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 224 | die(_("revision walk setup failed")); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 225 | |
| 226 | i = req_nr; |
| 227 | while (i && (commit = get_revision(&revs))) |
| 228 | if (commit->object.flags & PREREQ_MARK) |
| 229 | i--; |
| 230 | |
René Scharfe | 6364739 | 2017-12-25 18:46:14 +0100 | [diff] [blame] | 231 | for (i = 0; i < p->nr; i++) { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 232 | struct string_list_item *e = p->items + i; |
| 233 | const char *name = e->string; |
| 234 | const struct object_id *oid = e->util; |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 235 | struct object *o = parse_object(r, oid); |
René Scharfe | 6364739 | 2017-12-25 18:46:14 +0100 | [diff] [blame] | 236 | assert(o); /* otherwise we'd have returned early */ |
| 237 | if (o->flags & SHOWN) |
| 238 | continue; |
| 239 | if (++ret == 1) |
| 240 | error("%s", message); |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 241 | error("%s %s", oid_to_hex(oid), name); |
René Scharfe | 6364739 | 2017-12-25 18:46:14 +0100 | [diff] [blame] | 242 | } |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 243 | |
Martin Ågren | b2ccdf7 | 2017-09-23 01:34:51 +0200 | [diff] [blame] | 244 | /* Clean up objects used, as they will be reused. */ |
René Scharfe | 6364739 | 2017-12-25 18:46:14 +0100 | [diff] [blame] | 245 | for (i = 0; i < p->nr; i++) { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 246 | struct string_list_item *e = p->items + i; |
| 247 | struct object_id *oid = e->util; |
Ævar Arnfjörð Bjarmason | 15e7c7d | 2021-07-02 11:57:31 +0200 | [diff] [blame] | 248 | commit = lookup_commit_reference_gently(r, oid, 1); |
René Scharfe | 6364739 | 2017-12-25 18:46:14 +0100 | [diff] [blame] | 249 | if (commit) |
| 250 | clear_commit_marks(commit, ALL_REV_FLAGS); |
| 251 | } |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 252 | |
| 253 | if (verbose) { |
Ævar Arnfjörð Bjarmason | 10b635b | 2021-07-02 11:57:32 +0200 | [diff] [blame] | 254 | struct string_list *r; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 255 | |
| 256 | r = &header->references; |
Lukas Fleischer | a02ffe0 | 2013-03-08 19:01:26 +0100 | [diff] [blame] | 257 | printf_ln(Q_("The bundle contains this ref:", |
| 258 | "The bundle contains these %d refs:", |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 259 | r->nr), |
| 260 | r->nr); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 261 | list_refs(r, 0, NULL); |
Lukas Fleischer | 71ba6b1 | 2013-03-07 01:56:35 +0100 | [diff] [blame] | 262 | r = &header->prerequisites; |
Junio C Hamano | 8c3710f | 2012-06-04 11:51:13 -0700 | [diff] [blame] | 263 | if (!r->nr) { |
| 264 | printf_ln(_("The bundle records a complete history.")); |
| 265 | } else { |
Lukas Fleischer | a02ffe0 | 2013-03-08 19:01:26 +0100 | [diff] [blame] | 266 | printf_ln(Q_("The bundle requires this ref:", |
| 267 | "The bundle requires these %d refs:", |
Junio C Hamano | 8c3710f | 2012-06-04 11:51:13 -0700 | [diff] [blame] | 268 | r->nr), |
| 269 | r->nr); |
| 270 | list_refs(r, 0, NULL); |
| 271 | } |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 272 | } |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | int list_bundle_refs(struct bundle_header *header, int argc, const char **argv) |
| 277 | { |
| 278 | return list_refs(&header->references, argc, argv); |
| 279 | } |
| 280 | |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 281 | static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) |
| 282 | { |
| 283 | unsigned long size; |
| 284 | enum object_type type; |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 285 | char *buf = NULL, *line, *lineend; |
Johannes Schindelin | dddbad7 | 2017-04-26 21:29:31 +0200 | [diff] [blame] | 286 | timestamp_t date; |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 287 | int result = 1; |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 288 | |
| 289 | if (revs->max_age == -1 && revs->min_age == -1) |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 290 | goto out; |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 291 | |
brian m. carlson | b4f5aca | 2018-03-12 02:27:53 +0000 | [diff] [blame] | 292 | buf = read_object_file(&tag->oid, &type, &size); |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 293 | if (!buf) |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 294 | goto out; |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 295 | line = memmem(buf, size, "\ntagger ", 8); |
| 296 | if (!line++) |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 297 | goto out; |
Lukas Fleischer | 2c8544a | 2014-08-02 10:39:06 +0200 | [diff] [blame] | 298 | lineend = memchr(line, '\n', buf + size - line); |
| 299 | line = memchr(line, '>', lineend ? lineend - line : buf + size - line); |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 300 | if (!line++) |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 301 | goto out; |
Johannes Schindelin | 1aeb7e7 | 2017-04-21 12:45:44 +0200 | [diff] [blame] | 302 | date = parse_timestamp(line, NULL, 10); |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 303 | result = (revs->max_age == -1 || revs->max_age < date) && |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 304 | (revs->min_age == -1 || revs->min_age > date); |
René Scharfe | 6404594 | 2014-10-04 00:40:24 +0200 | [diff] [blame] | 305 | out: |
| 306 | free(buf); |
| 307 | return result; |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Michael Haggerty | e54c347 | 2015-08-10 11:47:37 +0200 | [diff] [blame] | 310 | |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 311 | /* Write the pack data to bundle_fd */ |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 312 | static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options) |
Junio C Hamano | 5e626b9 | 2014-10-30 10:45:41 -0700 | [diff] [blame] | 313 | { |
| 314 | struct child_process pack_objects = CHILD_PROCESS_INIT; |
| 315 | int i; |
| 316 | |
Jeff King | ef8d7ac | 2020-07-28 16:24:53 -0400 | [diff] [blame] | 317 | strvec_pushl(&pack_objects.args, |
Jeff King | f6d8942 | 2020-07-28 16:26:31 -0400 | [diff] [blame] | 318 | "pack-objects", |
| 319 | "--stdout", "--thin", "--delta-base-offset", |
| 320 | NULL); |
Jeff King | d70a9eb | 2020-07-28 20:37:20 -0400 | [diff] [blame] | 321 | strvec_pushv(&pack_objects.args, pack_options->v); |
Junio C Hamano | 5e626b9 | 2014-10-30 10:45:41 -0700 | [diff] [blame] | 322 | pack_objects.in = -1; |
| 323 | pack_objects.out = bundle_fd; |
| 324 | pack_objects.git_cmd = 1; |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | * start_command() will close our descriptor if it's >1. Duplicate it |
| 328 | * to avoid surprising the caller. |
| 329 | */ |
| 330 | if (pack_objects.out > 1) { |
| 331 | pack_objects.out = dup(pack_objects.out); |
| 332 | if (pack_objects.out < 0) { |
| 333 | error_errno(_("unable to dup bundle descriptor")); |
| 334 | child_process_clear(&pack_objects); |
| 335 | return -1; |
| 336 | } |
| 337 | } |
| 338 | |
Junio C Hamano | 5e626b9 | 2014-10-30 10:45:41 -0700 | [diff] [blame] | 339 | if (start_command(&pack_objects)) |
| 340 | return error(_("Could not spawn pack-objects")); |
| 341 | |
Junio C Hamano | 5e626b9 | 2014-10-30 10:45:41 -0700 | [diff] [blame] | 342 | for (i = 0; i < revs->pending.nr; i++) { |
| 343 | struct object *object = revs->pending.objects[i].item; |
| 344 | if (object->flags & UNINTERESTING) |
| 345 | write_or_die(pack_objects.in, "^", 1); |
brian m. carlson | 703d2d4 | 2019-08-18 20:04:11 +0000 | [diff] [blame] | 346 | write_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz); |
Junio C Hamano | 5e626b9 | 2014-10-30 10:45:41 -0700 | [diff] [blame] | 347 | write_or_die(pack_objects.in, "\n", 1); |
| 348 | } |
| 349 | close(pack_objects.in); |
| 350 | if (finish_command(&pack_objects)) |
| 351 | return error(_("pack-objects died")); |
| 352 | return 0; |
| 353 | } |
| 354 | |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 355 | /* |
| 356 | * Write out bundle refs based on the tips already |
| 357 | * parsed into revs.pending. As a side effect, may |
| 358 | * manipulate revs.pending to include additional |
| 359 | * necessary objects (like tags). |
| 360 | * |
| 361 | * Returns the number of refs written, or negative |
| 362 | * on error. |
| 363 | */ |
| 364 | static int write_bundle_refs(int bundle_fd, struct rev_info *revs) |
Junio C Hamano | e8eb251 | 2014-10-30 11:01:37 -0700 | [diff] [blame] | 365 | { |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 366 | int i; |
| 367 | int ref_count = 0; |
Junio C Hamano | e8eb251 | 2014-10-30 11:01:37 -0700 | [diff] [blame] | 368 | |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 369 | for (i = 0; i < revs->pending.nr; i++) { |
| 370 | struct object_array_entry *e = revs->pending.objects + i; |
brian m. carlson | f2fd076 | 2015-11-10 02:22:28 +0000 | [diff] [blame] | 371 | struct object_id oid; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 372 | char *ref; |
Junio C Hamano | fa30383 | 2007-11-22 16:51:18 -0800 | [diff] [blame] | 373 | const char *display_ref; |
| 374 | int flag; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 375 | |
| 376 | if (e->item->flags & UNINTERESTING) |
| 377 | continue; |
Jonathan Tan | f24c30e | 2020-09-01 15:28:09 -0700 | [diff] [blame] | 378 | if (dwim_ref(e->name, strlen(e->name), &oid, &ref, 0) != 1) |
Stefan Beller | c8a571d | 2015-03-10 16:51:48 -0700 | [diff] [blame] | 379 | goto skip_write_ref; |
brian m. carlson | 34c290a | 2017-10-15 22:06:56 +0000 | [diff] [blame] | 380 | if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag)) |
Junio C Hamano | fa30383 | 2007-11-22 16:51:18 -0800 | [diff] [blame] | 381 | flag = 0; |
| 382 | display_ref = (flag & REF_ISSYMREF) ? e->name : ref; |
| 383 | |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 384 | if (e->item->type == OBJ_TAG && |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 385 | !is_tag_in_date_range(e->item, revs)) { |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 386 | e->item->flags |= UNINTERESTING; |
Stefan Beller | c8a571d | 2015-03-10 16:51:48 -0700 | [diff] [blame] | 387 | goto skip_write_ref; |
Johannes Schindelin | c9a42c4 | 2009-01-02 19:08:46 +0100 | [diff] [blame] | 388 | } |
| 389 | |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 390 | /* |
| 391 | * Make sure the refs we wrote out is correct; --max-count and |
| 392 | * other limiting options could have prevented all the tips |
| 393 | * from getting output. |
| 394 | * |
| 395 | * Non commit objects such as tags and blobs do not have |
| 396 | * this issue as they are not affected by those extra |
| 397 | * constraints. |
| 398 | */ |
| 399 | if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) { |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 400 | warning(_("ref '%s' is excluded by the rev-list options"), |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 401 | e->name); |
Stefan Beller | c8a571d | 2015-03-10 16:51:48 -0700 | [diff] [blame] | 402 | goto skip_write_ref; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 403 | } |
| 404 | /* |
| 405 | * If you run "git bundle create bndl v1.0..v2.0", the |
| 406 | * name of the positive ref is "v2.0" but that is the |
| 407 | * commit that is referenced by the tag, and not the tag |
| 408 | * itself. |
| 409 | */ |
Jeff King | 9001dc2 | 2018-08-28 17:22:48 -0400 | [diff] [blame] | 410 | if (!oideq(&oid, &e->item->oid)) { |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 411 | /* |
| 412 | * Is this the positive end of a range expressed |
| 413 | * in terms of a tag (e.g. v2.0 from the range |
| 414 | * "v1.0..v2.0")? |
| 415 | */ |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 416 | struct commit *one = lookup_commit_reference(revs->repo, &oid); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 417 | struct object *obj; |
| 418 | |
| 419 | if (e->item == &(one->object)) { |
| 420 | /* |
| 421 | * Need to include e->name as an |
| 422 | * independent ref to the pack-objects |
| 423 | * input, so that the tag is included |
| 424 | * in the output; otherwise we would |
| 425 | * end up triggering "empty bundle" |
| 426 | * error. |
| 427 | */ |
brian m. carlson | c251c83 | 2017-05-06 22:10:38 +0000 | [diff] [blame] | 428 | obj = parse_object_or_die(&oid, e->name); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 429 | obj->flags |= SHOWN; |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 430 | add_pending_object(revs, obj, e->name); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 431 | } |
Stefan Beller | c8a571d | 2015-03-10 16:51:48 -0700 | [diff] [blame] | 432 | goto skip_write_ref; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | ref_count++; |
brian m. carlson | 703d2d4 | 2019-08-18 20:04:11 +0000 | [diff] [blame] | 436 | write_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 437 | write_or_die(bundle_fd, " ", 1); |
Junio C Hamano | fa30383 | 2007-11-22 16:51:18 -0800 | [diff] [blame] | 438 | write_or_die(bundle_fd, display_ref, strlen(display_ref)); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 439 | write_or_die(bundle_fd, "\n", 1); |
Stefan Beller | c8a571d | 2015-03-10 16:51:48 -0700 | [diff] [blame] | 440 | skip_write_ref: |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 441 | free(ref); |
| 442 | } |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 443 | |
| 444 | /* end header */ |
| 445 | write_or_die(bundle_fd, "\n", 1); |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 446 | return ref_count; |
| 447 | } |
| 448 | |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 449 | struct bundle_prerequisites_info { |
| 450 | struct object_array *pending; |
| 451 | int fd; |
| 452 | }; |
| 453 | |
| 454 | static void write_bundle_prerequisites(struct commit *commit, void *data) |
| 455 | { |
| 456 | struct bundle_prerequisites_info *bpi = data; |
| 457 | struct object *object; |
| 458 | struct pretty_print_context ctx = { 0 }; |
| 459 | struct strbuf buf = STRBUF_INIT; |
| 460 | |
| 461 | if (!(commit->object.flags & BOUNDARY)) |
| 462 | return; |
| 463 | strbuf_addf(&buf, "-%s ", oid_to_hex(&commit->object.oid)); |
| 464 | write_or_die(bpi->fd, buf.buf, buf.len); |
| 465 | |
| 466 | ctx.fmt = CMIT_FMT_ONELINE; |
| 467 | ctx.output_encoding = get_log_output_encoding(); |
| 468 | strbuf_reset(&buf); |
| 469 | pretty_print_commit(&ctx, commit, &buf); |
| 470 | strbuf_trim(&buf); |
| 471 | |
| 472 | object = (struct object *)commit; |
| 473 | object->flags |= UNINTERESTING; |
| 474 | add_object_array_with_path(object, buf.buf, bpi->pending, S_IFINVALID, |
| 475 | NULL); |
| 476 | strbuf_addch(&buf, '\n'); |
| 477 | write_or_die(bpi->fd, buf.buf, buf.len); |
| 478 | strbuf_release(&buf); |
| 479 | } |
| 480 | |
Jeff King | fcb133e | 2019-01-24 08:11:51 -0500 | [diff] [blame] | 481 | int create_bundle(struct repository *r, const char *path, |
Junio C Hamano | e0ad957 | 2020-08-11 18:04:11 -0700 | [diff] [blame] | 482 | int argc, const char **argv, struct strvec *pack_options, int version) |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 483 | { |
Martin Ågren | b227586 | 2018-05-09 22:55:38 +0200 | [diff] [blame] | 484 | struct lock_file lock = LOCK_INIT; |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 485 | int bundle_fd = -1; |
| 486 | int bundle_to_stdout; |
| 487 | int ref_count = 0; |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 488 | struct rev_info revs, revs_copy; |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 489 | int min_version = the_hash_algo == &hash_algos[GIT_HASH_SHA1] ? 2 : 3; |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 490 | struct bundle_prerequisites_info bpi; |
| 491 | int i; |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 492 | |
| 493 | bundle_to_stdout = !strcmp(path, "-"); |
| 494 | if (bundle_to_stdout) |
| 495 | bundle_fd = 1; |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 496 | else |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 497 | bundle_fd = hold_lock_file_for_update(&lock, path, |
| 498 | LOCK_DIE_ON_ERROR); |
| 499 | |
brian m. carlson | c5aecfc | 2020-07-29 23:14:20 +0000 | [diff] [blame] | 500 | if (version == -1) |
| 501 | version = min_version; |
| 502 | |
| 503 | if (version < 2 || version > 3) { |
| 504 | die(_("unsupported bundle version %d"), version); |
| 505 | } else if (version < min_version) { |
| 506 | die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name); |
| 507 | } else if (version == 2) { |
| 508 | write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature)); |
| 509 | } else { |
| 510 | const char *capability = "@object-format="; |
| 511 | write_or_die(bundle_fd, v3_bundle_signature, strlen(v3_bundle_signature)); |
| 512 | write_or_die(bundle_fd, capability, strlen(capability)); |
| 513 | write_or_die(bundle_fd, the_hash_algo->name, strlen(the_hash_algo->name)); |
| 514 | write_or_die(bundle_fd, "\n", 1); |
| 515 | } |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 516 | |
| 517 | /* init revs to list objects for pack-objects later */ |
| 518 | save_commit_buffer = 0; |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 519 | repo_init_revisions(r, &revs, NULL); |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 520 | |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 521 | argc = setup_revisions(argc, argv, &revs, NULL); |
| 522 | |
Stefan Beller | f5ff5fb | 2016-03-31 17:35:45 -0700 | [diff] [blame] | 523 | if (argc > 1) { |
| 524 | error(_("unrecognized argument: %s"), argv[1]); |
| 525 | goto err; |
| 526 | } |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 527 | |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 528 | /* save revs.pending in revs_copy for later use */ |
| 529 | memcpy(&revs_copy, &revs, sizeof(revs)); |
| 530 | revs_copy.pending.nr = 0; |
| 531 | revs_copy.pending.alloc = 0; |
| 532 | revs_copy.pending.objects = NULL; |
| 533 | for (i = 0; i < revs.pending.nr; i++) { |
| 534 | struct object_array_entry *e = revs.pending.objects + i; |
| 535 | if (e) |
| 536 | add_object_array_with_path(e->item, e->name, |
| 537 | &revs_copy.pending, |
| 538 | e->mode, e->path); |
| 539 | } |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 540 | |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 541 | /* write prerequisites */ |
| 542 | revs.boundary = 1; |
| 543 | if (prepare_revision_walk(&revs)) |
| 544 | die("revision walk setup failed"); |
| 545 | bpi.fd = bundle_fd; |
| 546 | bpi.pending = &revs_copy.pending; |
| 547 | traverse_commit_list(&revs, write_bundle_prerequisites, NULL, &bpi); |
| 548 | object_array_remove_duplicates(&revs_copy.pending); |
| 549 | |
| 550 | /* write bundle refs */ |
| 551 | ref_count = write_bundle_refs(bundle_fd, &revs_copy); |
Jeff King | d9362ef | 2014-10-30 17:35:24 -0400 | [diff] [blame] | 552 | if (!ref_count) |
| 553 | die(_("Refusing to create empty bundle.")); |
| 554 | else if (ref_count < 0) |
Stefan Beller | f5ff5fb | 2016-03-31 17:35:45 -0700 | [diff] [blame] | 555 | goto err; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 556 | |
| 557 | /* write pack */ |
Jiang Xin | 5bb0fd2 | 2021-01-11 21:27:03 -0500 | [diff] [blame] | 558 | if (write_pack_data(bundle_fd, &revs_copy, pack_options)) |
Stefan Beller | f5ff5fb | 2016-03-31 17:35:45 -0700 | [diff] [blame] | 559 | goto err; |
Brandon Casey | 4ed7cd3 | 2008-01-16 13:12:46 -0600 | [diff] [blame] | 560 | |
Csaba Henk | 0f5cdf6 | 2010-08-27 20:31:47 +0000 | [diff] [blame] | 561 | if (!bundle_to_stdout) { |
| 562 | if (commit_lock_file(&lock)) |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 563 | die_errno(_("cannot create '%s'"), path); |
Csaba Henk | 0f5cdf6 | 2010-08-27 20:31:47 +0000 | [diff] [blame] | 564 | } |
Johannes Sixt | c20181e | 2008-02-21 23:42:56 +0100 | [diff] [blame] | 565 | return 0; |
Stefan Beller | f5ff5fb | 2016-03-31 17:35:45 -0700 | [diff] [blame] | 566 | err: |
Jeff King | 2c8ee1f | 2018-11-16 04:43:59 -0500 | [diff] [blame] | 567 | rollback_lock_file(&lock); |
Stefan Beller | f5ff5fb | 2016-03-31 17:35:45 -0700 | [diff] [blame] | 568 | return -1; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 571 | int unbundle(struct repository *r, struct bundle_header *header, |
Ævar Arnfjörð Bjarmason | 7366096 | 2021-09-05 09:34:43 +0200 | [diff] [blame] | 572 | int bundle_fd, struct strvec *extra_index_pack_args) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 573 | { |
René Scharfe | d318027 | 2014-08-19 21:09:35 +0200 | [diff] [blame] | 574 | struct child_process ip = CHILD_PROCESS_INIT; |
Ævar Arnfjörð Bjarmason | 7366096 | 2021-09-05 09:34:43 +0200 | [diff] [blame] | 575 | strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 576 | |
Ævar Arnfjörð Bjarmason | 7366096 | 2021-09-05 09:34:43 +0200 | [diff] [blame] | 577 | if (extra_index_pack_args) { |
| 578 | strvec_pushv(&ip.args, extra_index_pack_args->v); |
| 579 | strvec_clear(extra_index_pack_args); |
| 580 | } |
Junio C Hamano | be042af | 2011-09-18 16:52:32 -0700 | [diff] [blame] | 581 | |
Nguyễn Thái Ngọc Duy | 74ae4b6 | 2018-11-10 06:49:01 +0100 | [diff] [blame] | 582 | if (verify_bundle(r, header, 0)) |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 583 | return -1; |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 584 | ip.in = bundle_fd; |
| 585 | ip.no_stdout = 1; |
| 586 | ip.git_cmd = 1; |
| 587 | if (run_command(&ip)) |
Nguyễn Thái Ngọc Duy | 8a1e7ea | 2012-04-23 19:30:30 +0700 | [diff] [blame] | 588 | return error(_("index-pack died")); |
Johannes Schindelin | 30415d5 | 2007-09-10 23:03:15 -0400 | [diff] [blame] | 589 | return 0; |
| 590 | } |