| 216 | } |
| 217 | |
| 218 | int verify_bundle(struct repository *r, |
| 219 | struct bundle_header *header, |
| 220 | enum verify_bundle_flags flags) |
| 221 | { |
| 222 | /* |
| 223 | * Do fast check, then if any prereqs are missing then go line by line |
| 224 | * to be verbose about the errors |
| 225 | */ |
| 226 | struct string_list *p = &header->prerequisites; |
| 227 | int i, ret = 0; |
| 228 | const char *message = _("Repository lacks these prerequisite commits:"); |
| 229 | struct string_list_iterator iter = { |
| 230 | .list = p, |
| 231 | }; |
| 232 | struct check_connected_options opts = { |
| 233 | .quiet = 1, |
| 234 | }; |
| 235 | |
| 236 | if (!r || !r->objects || !r->objects->sources) |
| 237 | return error(_("need a repository to verify a bundle")); |
| 238 | |
| 239 | for (i = 0; i < p->nr; i++) { |
| 240 | struct string_list_item *e = p->items + i; |
| 241 | const char *name = e->string; |
| 242 | struct object_id *oid = e->util; |
| 243 | struct object *o = parse_object(r, oid); |
| 244 | if (o) |
| 245 | continue; |
| 246 | ret++; |
| 247 | if (flags & VERIFY_BUNDLE_QUIET) |
| 248 | continue; |
| 249 | if (ret == 1) |
| 250 | error("%s", message); |
| 251 | error("%s %s", oid_to_hex(oid), name); |
| 252 | } |
| 253 | if (ret) |
| 254 | goto cleanup; |
| 255 | |
| 256 | if ((ret = check_connected(iterate_ref_map, &iter, &opts))) |
| 257 | error(_("some prerequisite commits exist in the object store, " |
| 258 | "but are not connected to the repository's history")); |
| 259 | |
| 260 | /* TODO: preserve this verbose language. */ |
| 261 | if (flags & VERIFY_BUNDLE_VERBOSE) { |
| 262 | struct string_list *r; |
| 263 | |
| 264 | r = &header->references; |
| 265 | printf_ln(Q_("The bundle contains this ref:", |
| 266 | "The bundle contains these %"PRIuMAX" refs:", |
| 267 | r->nr), |
| 268 | (uintmax_t)r->nr); |
| 269 | list_refs(r, 0, NULL); |
| 270 | |
| 271 | r = &header->prerequisites; |
| 272 | if (!r->nr) { |
| 273 | printf_ln(_("The bundle records a complete history.")); |
| 274 | } else { |
| 275 | printf_ln(Q_("The bundle requires this ref:", |
no test coverage detected