| 38 | } |
| 39 | |
| 40 | int write_cruft_pack(const struct write_pack_opts *opts, |
| 41 | const char *cruft_expiration, |
| 42 | unsigned long combine_cruft_below_size, |
| 43 | struct string_list *names, |
| 44 | struct existing_packs *existing) |
| 45 | { |
| 46 | struct child_process cmd = CHILD_PROCESS_INIT; |
| 47 | struct string_list_item *item; |
| 48 | FILE *in; |
| 49 | int ret; |
| 50 | const char *pack_prefix = write_pack_opts_pack_prefix(opts); |
| 51 | |
| 52 | prepare_pack_objects(&cmd, opts->po_args, opts->destination); |
| 53 | |
| 54 | strvec_push(&cmd.args, "--cruft"); |
| 55 | if (cruft_expiration) |
| 56 | strvec_pushf(&cmd.args, "--cruft-expiration=%s", |
| 57 | cruft_expiration); |
| 58 | |
| 59 | strvec_push(&cmd.args, "--non-empty"); |
| 60 | |
| 61 | cmd.in = -1; |
| 62 | |
| 63 | ret = start_command(&cmd); |
| 64 | if (ret) |
| 65 | return ret; |
| 66 | |
| 67 | /* |
| 68 | * names has a confusing double use: it both provides the list |
| 69 | * of just-written new packs, and accepts the name of the cruft |
| 70 | * pack we are writing. |
| 71 | * |
| 72 | * By the time it is read here, it contains only the pack(s) |
| 73 | * that were just written, which is exactly the set of packs we |
| 74 | * want to consider kept. |
| 75 | * |
| 76 | * If `--expire-to` is given, the double-use served by `names` |
| 77 | * ensures that the pack written to `--expire-to` excludes any |
| 78 | * objects contained in the cruft pack. |
| 79 | */ |
| 80 | in = xfdopen(cmd.in, "w"); |
| 81 | for_each_string_list_item(item, names) |
| 82 | fprintf(in, "%s-%s.pack\n", pack_prefix, item->string); |
| 83 | if (combine_cruft_below_size && !cruft_expiration) { |
| 84 | combine_small_cruft_packs(in, combine_cruft_below_size, |
| 85 | existing); |
| 86 | } else { |
| 87 | for_each_string_list_item(item, &existing->non_kept_packs) |
| 88 | fprintf(in, "-%s.pack\n", item->string); |
| 89 | for_each_string_list_item(item, &existing->cruft_packs) |
| 90 | fprintf(in, "-%s.pack\n", item->string); |
| 91 | } |
| 92 | for_each_string_list_item(item, &existing->kept_packs) |
| 93 | fprintf(in, "%s.pack\n", item->string); |
| 94 | fclose(in); |
| 95 | |
| 96 | return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd, |
| 97 | names); |
no test coverage detected