@matheusbsbs / matheus-bagliano / commits / 120ad2b0f1
Fork 0

shallow: extract a header file for shallow-related functions

There are many functions in commit.h that are more related to shallow repositories than they are to any sort of generic commit machinery. Likely this began when there were only a few shallow-related functions, and commit.h seemed a reasonable enough place to put them. But, now there are a good number of shallow-related functions, and placing them all in 'commit.h' doesn't make sense. This patch extracts a 'shallow.h', which takes all of the declarations from 'commit.h' for functions which already exist in 'shallow.c'. We will bring the remaining shallow-related functions defined in 'commit.c' in a subsequent patch. For now, move only the ones that already are implemented in 'shallow.c', and update the necessary includes. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 30, 2020 at 13:48 UTC 120ad2b0f13b60266fec9760bba3b5abfcd6fb78
16 files changed +91 -61
builtin/fetch.c
+1
@@ -27,6 +27,7 @@
27 #include "branch.h"
28 #include "promisor-remote.h"
29 #include "commit-graph.h"
30 +#include "shallow.h"
31
32 #define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
33
builtin/pack-objects.c
+1
@@ -34,6 +34,7 @@
34 #include "dir.h"
35 #include "midx.h"
36 #include "trace2.h"
37 +#include "shallow.h"
38
39 #define IN_PACK(obj) oe_in_pack(&to_pack, obj)
40 #define SIZE(obj) oe_size(&to_pack, obj)
builtin/prune.c
+1
@@ -7,6 +7,7 @@
7 #include "parse-options.h"
8 #include "progress.h"
9 #include "object-store.h"
10 +#include "shallow.h"
11
12 static const char * const prune_usage[] = {
13 N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"),
builtin/receive-pack.c
+1
@@ -28,6 +28,7 @@
28 #include "protocol.h"
29 #include "commit-reach.h"
30 #include "worktree.h"
31 +#include "shallow.h"
32
33 static const char * const receive_pack_usage[] = {
34 N_("git receive-pack <git-dir>"),
builtin/repack.c
+1
@@ -12,6 +12,7 @@
12 #include "packfile.h"
13 #include "object-store.h"
14 #include "promisor-remote.h"
15 +#include "shallow.h"
16
17 static int delta_base_offset = 1;
18 static int pack_kept_objects = -1;
builtin/rev-parse.c
+1
@@ -16,6 +16,7 @@
16 #include "split-index.h"
17 #include "submodule.h"
18 #include "commit-reach.h"
19 +#include "shallow.h"
20
21 #define DO_REVS 1
22 #define DO_NOREV 2
commit-graph.c
+1
@@ -16,6 +16,7 @@
16 #include "hashmap.h"
17 #include "replace-object.h"
18 #include "progress.h"
19 +#include "shallow.h"
20
21 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
22 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
commit.c
+1 -13
@@ -20,6 +20,7 @@
20 #include "refs.h"
21 #include "commit-reach.h"
22 #include "run-command.h"
23 +#include "shallow.h"
24
25 static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
26
@@ -245,19 +246,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
246 return ret;
247 }
248
248 -int unregister_shallow(const struct object_id *oid)
249 -{
250 - int pos = commit_graft_pos(the_repository, oid->hash);
251 - if (pos < 0)
252 - return -1;
253 - if (pos + 1 < the_repository->parsed_objects->grafts_nr)
254 - MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
255 - the_repository->parsed_objects->grafts + pos + 1,
256 - the_repository->parsed_objects->grafts_nr - pos - 1);
257 - the_repository->parsed_objects->grafts_nr--;
258 - return 0;
259 -}
260 -
249 struct commit_buffer {
250 void *buffer;
251 unsigned long size;
commit.h
-48
@@ -249,55 +249,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit);
249
250 struct oid_array;
251 struct ref;
252 -int register_shallow(struct repository *r, const struct object_id *oid);
253 -int unregister_shallow(const struct object_id *oid);
254 -int commit_shallow_file(struct repository *r, struct lock_file *lk);
255 -void rollback_shallow_file(struct repository *r, struct lock_file *lk);
252 int for_each_commit_graft(each_commit_graft_fn, void *);
257 -int is_repository_shallow(struct repository *r);
258 -struct commit_list *get_shallow_commits(struct object_array *heads,
259 - int depth, int shallow_flag, int not_shallow_flag);
260 -struct commit_list *get_shallow_commits_by_rev_list(
261 - int ac, const char **av, int shallow_flag, int not_shallow_flag);
262 -void set_alternate_shallow_file(struct repository *r, const char *path, int override);
263 -int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
264 - const struct oid_array *extra);
265 -void setup_alternate_shallow(struct lock_file *shallow_lock,
266 - const char **alternate_shallow_file,
267 - const struct oid_array *extra);
268 -const char *setup_temporary_shallow(const struct oid_array *extra);
269 -void advertise_shallow_grafts(int);
270 -
271 -/*
272 - * Initialize with prepare_shallow_info() or zero-initialize (equivalent to
273 - * prepare_shallow_info with a NULL oid_array).
274 - */
275 -struct shallow_info {
276 - struct oid_array *shallow;
277 - int *ours, nr_ours;
278 - int *theirs, nr_theirs;
279 - struct oid_array *ref;
280 -
281 - /* for receive-pack */
282 - uint32_t **used_shallow;
283 - int *need_reachability_test;
284 - int *reachable;
285 - int *shallow_ref;
286 - struct commit **commits;
287 - int nr_commits;
288 -};
289 -
290 -void prepare_shallow_info(struct shallow_info *, struct oid_array *);
291 -void clear_shallow_info(struct shallow_info *);
292 -void remove_nonexistent_theirs_shallow(struct shallow_info *);
293 -void assign_shallow_commits_to_refs(struct shallow_info *info,
294 - uint32_t **used,
295 - int *ref_status);
296 -int delayed_reachability_test(struct shallow_info *si, int c);
297 -#define PRUNE_SHOW_ONLY 1
298 -#define PRUNE_QUICK 2
299 -void prune_shallow(unsigned options);
300 -extern struct trace_key trace_shallow;
253
254 int interactive_add(int argc, const char **argv, const char *prefix, int patch);
255 int run_add_interactive(const char *revision, const char *patch_mode,
environment.c
+1
@@ -17,6 +17,7 @@
17 #include "argv-array.h"
18 #include "object-store.h"
19 #include "chdir-notify.h"
20 +#include "shallow.h"
21
22 int trust_executable_bit = 1;
23 int trust_ctime = 1;
fetch-pack.c
+1
@@ -22,6 +22,7 @@
22 #include "connected.h"
23 #include "fetch-negotiator.h"
24 #include "fsck.h"
25 +#include "shallow.h"
26
27 static int transfer_unpack_limit = -1;
28 static int fetch_unpack_limit = -1;
git.c
+1
@@ -4,6 +4,7 @@
4 #include "help.h"
5 #include "run-command.h"
6 #include "alias.h"
7 +#include "shallow.h"
8
9 #define RUN_SETUP (1<<0)
10 #define RUN_SETUP_GENTLY (1<<1)
send-pack.c
+1
@@ -15,6 +15,7 @@
15 #include "sha1-array.h"
16 #include "gpg-interface.h"
17 #include "cache.h"
18 +#include "shallow.h"
19
20 int option_parse_push_signed(const struct option *opt,
21 const char *arg, int unset)
shallow.c
+14
@@ -14,6 +14,7 @@
14 #include "commit-slab.h"
15 #include "list-objects.h"
16 #include "commit-reach.h"
17 +#include "shallow.h"
18
19 void set_alternate_shallow_file(struct repository *r, const char *path, int override)
20 {
@@ -38,6 +39,19 @@ int register_shallow(struct repository *r, const struct object_id *oid)
39 return register_commit_graft(r, graft, 0);
40 }
41
42 +int unregister_shallow(const struct object_id *oid)
43 +{
44 + int pos = commit_graft_pos(the_repository, oid->hash);
45 + if (pos < 0)
46 + return -1;
47 + if (pos + 1 < the_repository->parsed_objects->grafts_nr)
48 + MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
49 + the_repository->parsed_objects->grafts + pos + 1,
50 + the_repository->parsed_objects->grafts_nr - pos - 1);
51 + the_repository->parsed_objects->grafts_nr--;
52 + return 0;
53 +}
54 +
55 int is_repository_shallow(struct repository *r)
56 {
57 FILE *fp;
shallow.h new
+64
@@ -0,0 +1,64 @@
1 +#ifndef SHALLOW_H
2 +#define SHALLOW_H
3 +
4 +#include "lockfile.h"
5 +#include "object.h"
6 +#include "repository.h"
7 +#include "strbuf.h"
8 +
9 +void set_alternate_shallow_file(struct repository *r, const char *path, int override);
10 +int register_shallow(struct repository *r, const struct object_id *oid);
11 +int unregister_shallow(const struct object_id *oid);
12 +int is_repository_shallow(struct repository *r);
13 +int commit_shallow_file(struct repository *r, struct lock_file *lk);
14 +void rollback_shallow_file(struct repository *r, struct lock_file *lk);
15 +
16 +struct commit_list *get_shallow_commits(struct object_array *heads,
17 + int depth, int shallow_flag, int not_shallow_flag);
18 +struct commit_list *get_shallow_commits_by_rev_list(
19 + int ac, const char **av, int shallow_flag, int not_shallow_flag);
20 +int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
21 + const struct oid_array *extra);
22 +
23 +void setup_alternate_shallow(struct lock_file *shallow_lock,
24 + const char **alternate_shallow_file,
25 + const struct oid_array *extra);
26 +
27 +const char *setup_temporary_shallow(const struct oid_array *extra);
28 +
29 +void advertise_shallow_grafts(int);
30 +
31 +#define PRUNE_SHOW_ONLY 1
32 +#define PRUNE_QUICK 2
33 +void prune_shallow(unsigned options);
34 +
35 +/*
36 + * Initialize with prepare_shallow_info() or zero-initialize (equivalent to
37 + * prepare_shallow_info with a NULL oid_array).
38 + */
39 +struct shallow_info {
40 + struct oid_array *shallow;
41 + int *ours, nr_ours;
42 + int *theirs, nr_theirs;
43 + struct oid_array *ref;
44 +
45 + /* for receive-pack */
46 + uint32_t **used_shallow;
47 + int *need_reachability_test;
48 + int *reachable;
49 + int *shallow_ref;
50 + struct commit **commits;
51 + int nr_commits;
52 +};
53 +
54 +void prepare_shallow_info(struct shallow_info *, struct oid_array *);
55 +void clear_shallow_info(struct shallow_info *);
56 +void remove_nonexistent_theirs_shallow(struct shallow_info *);
57 +void assign_shallow_commits_to_refs(struct shallow_info *info,
58 + uint32_t **used,
59 + int *ref_status);
60 +int delayed_reachability_test(struct shallow_info *si, int c);
61 +
62 +extern struct trace_key trace_shallow;
63 +
64 +#endif /* SHALLOW_H */
upload-pack.c
+1
@@ -26,6 +26,7 @@
26 #include "serve.h"
27 #include "commit-graph.h"
28 #include "commit-reach.h"
29 +#include "shallow.h"
30
31 /* Remember to update object flag allocation in object.h */
32 #define THEY_HAVE (1u << 11)