Raw
1 #ifndef REPACK_H
2 #define REPACK_H
3
4 #include "list-objects-filter-options.h"
5 #include "string-list.h"
6
7 struct pack_objects_args {
8 char *window;
9 char *window_memory;
10 char *depth;
11 char *threads;
12 unsigned long max_pack_size;
13 int no_reuse_delta;
14 int no_reuse_object;
15 int quiet;
16 int local;
17 int name_hash_version;
18 int path_walk;
19 int delta_base_offset;
20 int pack_kept_objects;
21 struct list_objects_filter_options filter_options;
22 };
23
24 #define PACK_OBJECTS_ARGS_INIT { \
25 .delta_base_offset = 1, \
26 .pack_kept_objects = -1, \
27 }
28
29 struct child_process;
30
31 void prepare_pack_objects(struct child_process *cmd,
32 const struct pack_objects_args *args,
33 const char *out);
34 void pack_objects_args_release(struct pack_objects_args *args);
35
36 void repack_remove_redundant_pack(struct repository *repo, const char *dir_name,
37 const char *base_name,
38 bool wrote_incremental_midx);
39
40 struct write_pack_opts {
41 struct pack_objects_args *po_args;
42 const char *destination;
43 const char *packdir;
44 const char *packtmp;
45 };
46
47 const char *write_pack_opts_pack_prefix(const struct write_pack_opts *opts);
48 bool write_pack_opts_is_local(const struct write_pack_opts *opts);
49
50 int finish_pack_objects_cmd(const struct git_hash_algo *algop,
51 const struct write_pack_opts *opts,
52 struct child_process *cmd,
53 struct string_list *names);
54
55 struct repository;
56 struct packed_git;
57
58 struct existing_packs {
59 struct repository *repo;
60 struct odb_source *source;
61 struct string_list kept_packs;
62 struct string_list non_kept_packs;
63 struct string_list cruft_packs;
64 struct string_list midx_packs;
65 };
66
67 #define EXISTING_PACKS_INIT { \
68 .kept_packs = STRING_LIST_INIT_DUP, \
69 .non_kept_packs = STRING_LIST_INIT_DUP, \
70 .cruft_packs = STRING_LIST_INIT_DUP, \
71 }
72
73 /*
74 * Adds all packs hex strings (pack-$HASH) to either packs->non_kept
75 * or packs->kept based on whether each pack has a corresponding
76 * .keep file or not. Packs without a .keep file are not to be kept
77 * if we are going to pack everything into one file.
78 */
79 void existing_packs_collect(struct existing_packs *existing,
80 const struct string_list *extra_keep);
81 int existing_packs_has_non_kept(const struct existing_packs *existing);
82 int existing_pack_is_marked_for_deletion(struct string_list_item *item);
83 void existing_packs_retain_cruft(struct existing_packs *existing,
84 struct packed_git *cruft);
85 void existing_packs_mark_for_deletion(struct existing_packs *existing,
86 struct string_list *names);
87 void existing_packs_retain_midx_packs(struct existing_packs *existing);
88 void existing_packs_remove_redundant(struct existing_packs *existing,
89 const char *packdir,
90 bool wrote_incremental_midx);
91 void existing_packs_release(struct existing_packs *existing);
92
93 struct generated_pack;
94
95 struct generated_pack *generated_pack_populate(const char *name,
96 const char *packtmp);
97 int generated_pack_has_ext(const struct generated_pack *pack, const char *ext);
98 void generated_pack_install(struct generated_pack *pack, const char *name,
99 const char *packdir, const char *packtmp);
100
101 void repack_promisor_objects(struct repository *repo,
102 const struct pack_objects_args *args,
103 struct string_list *names, const char *packtmp);
104
105 struct pack_geometry {
106 struct packed_git **pack;
107 uint32_t pack_nr, pack_alloc;
108 uint32_t split;
109
110 struct packed_git **promisor_pack;
111 uint32_t promisor_pack_nr, promisor_pack_alloc;
112 uint32_t promisor_split;
113
114 uint32_t midx_layer_threshold;
115 bool midx_layer_threshold_set;
116 bool midx_tip_rewritten;
117
118 int split_factor;
119 };
120
121 void pack_geometry_repack_promisors(struct repository *repo,
122 const struct pack_objects_args *args,
123 const struct pack_geometry *geometry,
124 struct string_list *names,
125 const char *packtmp);
126
127 void pack_geometry_init(struct pack_geometry *geometry,
128 struct existing_packs *existing,
129 const struct pack_objects_args *args);
130 void pack_geometry_split(struct pack_geometry *geometry);
131 struct packed_git *pack_geometry_preferred_pack(struct pack_geometry *geometry);
132 void pack_geometry_remove_redundant(struct pack_geometry *geometry,
133 struct string_list *names,
134 struct existing_packs *existing,
135 const char *packdir,
136 bool wrote_incremental_midx);
137 void pack_geometry_release(struct pack_geometry *geometry);
138
139 struct tempfile;
140
141 enum repack_write_midx_mode {
142 REPACK_WRITE_MIDX_NONE,
143 REPACK_WRITE_MIDX_DEFAULT,
144 REPACK_WRITE_MIDX_INCREMENTAL,
145 };
146
147 struct repack_write_midx_opts {
148 struct existing_packs *existing;
149 struct pack_geometry *geometry;
150 struct string_list *names;
151 const char *refs_snapshot;
152 const char *packdir;
153 int show_progress;
154 int write_bitmaps;
155 int midx_must_contain_cruft;
156 int midx_split_factor;
157 int midx_new_layer_threshold;
158 enum repack_write_midx_mode mode;
159 };
160
161 void midx_snapshot_refs(struct repository *repo, struct tempfile *f);
162 int repack_write_midx(struct repack_write_midx_opts *opts);
163
164 int write_filtered_pack(const struct write_pack_opts *opts,
165 struct existing_packs *existing,
166 struct string_list *names);
167
168 int write_cruft_pack(const struct write_pack_opts *opts,
169 const char *cruft_expiration,
170 unsigned long combine_cruft_below_size,
171 struct string_list *names,
172 struct existing_packs *existing);
173
174 #endif /* REPACK_H */