Raw
1 #include "git-compat-util.h"
2 #include "repack.h"
3 #include "repository.h"
4 #include "run-command.h"
5 #include "string-list.h"
6
7 int write_filtered_pack(const struct write_pack_opts *opts,
8 struct existing_packs *existing,
9 struct string_list *names)
10 {
11 struct child_process cmd = CHILD_PROCESS_INIT;
12 struct string_list_item *item;
13 FILE *in;
14 int ret;
15 const char *caret;
16 const char *pack_prefix = write_pack_opts_pack_prefix(opts);
17
18 prepare_pack_objects(&cmd, opts->po_args, opts->destination);
19
20 strvec_push(&cmd.args, "--stdin-packs");
21
22 for_each_string_list_item(item, &existing->kept_packs)
23 strvec_pushf(&cmd.args, "--keep-pack=%s", item->string);
24
25 cmd.in = -1;
26
27 ret = start_command(&cmd);
28 if (ret)
29 return ret;
30
31 /*
32 * Here 'names' contains only the pack(s) that were just
33 * written, which is exactly the packs we want to keep. Also
34 * 'existing_kept_packs' already contains the packs in
35 * 'keep_pack_list'.
36 */
37 in = xfdopen(cmd.in, "w");
38 for_each_string_list_item(item, names)
39 fprintf(in, "^%s-%s.pack\n", pack_prefix, item->string);
40 for_each_string_list_item(item, &existing->non_kept_packs)
41 fprintf(in, "%s.pack\n", item->string);
42 for_each_string_list_item(item, &existing->cruft_packs)
43 fprintf(in, "%s.pack\n", item->string);
44 caret = opts->po_args->pack_kept_objects ? "" : "^";
45 for_each_string_list_item(item, &existing->kept_packs)
46 fprintf(in, "%s%s.pack\n", caret, item->string);
47 fclose(in);
48
49 return finish_pack_objects_cmd(existing->repo->hash_algo, opts, &cmd,
50 names);
51 }