]> git.ipfire.org Git - thirdparty/git.git/commitdiff
shallow: extract a header file for shallow-related functions
authorTaylor Blau <me@ttaylorr.com>
Thu, 30 Apr 2020 19:48:50 +0000 (13:48 -0600)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Apr 2020 21:19:13 +0000 (14:19 -0700)
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>
16 files changed:
builtin/fetch.c
builtin/pack-objects.c
builtin/prune.c
builtin/receive-pack.c
builtin/repack.c
builtin/rev-parse.c
commit-graph.c
commit.c
commit.h
environment.c
fetch-pack.c
git.c
send-pack.c
shallow.c
shallow.h [new file with mode: 0644]
upload-pack.c

index bf6bab80fab915242f412de7f0ced4a92d95f930..a292acd1c0a4c5dd4b01dfd13d32b364168d6f9a 100644 (file)
@@ -27,6 +27,7 @@
 #include "branch.h"
 #include "promisor-remote.h"
 #include "commit-graph.h"
+#include "shallow.h"
 
 #define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
 
index 02aa6ee4808a96f264a861bc49789341179056be..0b17d3cdd44c56714af78ea058a72e5187df48c6 100644 (file)
@@ -34,6 +34,7 @@
 #include "dir.h"
 #include "midx.h"
 #include "trace2.h"
+#include "shallow.h"
 
 #define IN_PACK(obj) oe_in_pack(&to_pack, obj)
 #define SIZE(obj) oe_size(&to_pack, obj)
index 2b76872ad2207857077f4ecf285780e94388d00d..028ff786d62e5102c75e3327ee12413595923b5f 100644 (file)
@@ -7,6 +7,7 @@
 #include "parse-options.h"
 #include "progress.h"
 #include "object-store.h"
+#include "shallow.h"
 
 static const char * const prune_usage[] = {
        N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"),
index 652661fa993c4f3fdde2d30115e5e0131cf57103..8e3f9bc35f49b97279b5165c4d8a3e16cb7f22f0 100644 (file)
@@ -28,6 +28,7 @@
 #include "protocol.h"
 #include "commit-reach.h"
 #include "worktree.h"
+#include "shallow.h"
 
 static const char * const receive_pack_usage[] = {
        N_("git receive-pack <git-dir>"),
index 0781763b06e80d0188acfe3c902061729b762809..2550603608a332062bff04310a596a2004c90b50 100644 (file)
@@ -12,6 +12,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "promisor-remote.h"
+#include "shallow.h"
 
 static int delta_base_offset = 1;
 static int pack_kept_objects = -1;
index 7a00da820355b61c548449c55381577a2232a0e8..a035b7919fa98e3c949752a08b57771827fbce3b 100644 (file)
@@ -16,6 +16,7 @@
 #include "split-index.h"
 #include "submodule.h"
 #include "commit-reach.h"
+#include "shallow.h"
 
 #define DO_REVS                1
 #define DO_NOREV       2
index f013a84e294b13b552b62257bbf2fa7e1c353a82..d316de50217c5b25d9ca6da578ea08e3d3275999 100644 (file)
@@ -16,6 +16,7 @@
 #include "hashmap.h"
 #include "replace-object.h"
 #include "progress.h"
+#include "shallow.h"
 
 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
index efa9ea7dcfa50f7b2760d3bbe2b09bd65a11bd5c..aa969b32a32456daf212967175ad63cc28c3b0a4 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -20,6 +20,7 @@
 #include "refs.h"
 #include "commit-reach.h"
 #include "run-command.h"
+#include "shallow.h"
 
 static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
 
@@ -245,19 +246,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
        return ret;
 }
 
-int unregister_shallow(const struct object_id *oid)
-{
-       int pos = commit_graft_pos(the_repository, oid->hash);
-       if (pos < 0)
-               return -1;
-       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
-               MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
-                          the_repository->parsed_objects->grafts + pos + 1,
-                          the_repository->parsed_objects->grafts_nr - pos - 1);
-       the_repository->parsed_objects->grafts_nr--;
-       return 0;
-}
-
 struct commit_buffer {
        void *buffer;
        unsigned long size;
index 0fe1e1b570d9748abb7174db0f0fd5b41f310b4a..1b2dea5d85ebe52c8e5f32f1e5e26ff33e0c566c 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -249,55 +249,7 @@ struct commit *get_fork_point(const char *refname, struct commit *commit);
 
 struct oid_array;
 struct ref;
-int register_shallow(struct repository *r, const struct object_id *oid);
-int unregister_shallow(const struct object_id *oid);
-int commit_shallow_file(struct repository *r, struct lock_file *lk);
-void rollback_shallow_file(struct repository *r, struct lock_file *lk);
 int for_each_commit_graft(each_commit_graft_fn, void *);
-int is_repository_shallow(struct repository *r);
-struct commit_list *get_shallow_commits(struct object_array *heads,
-                                       int depth, int shallow_flag, int not_shallow_flag);
-struct commit_list *get_shallow_commits_by_rev_list(
-               int ac, const char **av, int shallow_flag, int not_shallow_flag);
-void set_alternate_shallow_file(struct repository *r, const char *path, int override);
-int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
-                         const struct oid_array *extra);
-void setup_alternate_shallow(struct lock_file *shallow_lock,
-                            const char **alternate_shallow_file,
-                            const struct oid_array *extra);
-const char *setup_temporary_shallow(const struct oid_array *extra);
-void advertise_shallow_grafts(int);
-
-/*
- * Initialize with prepare_shallow_info() or zero-initialize (equivalent to
- * prepare_shallow_info with a NULL oid_array).
- */
-struct shallow_info {
-       struct oid_array *shallow;
-       int *ours, nr_ours;
-       int *theirs, nr_theirs;
-       struct oid_array *ref;
-
-       /* for receive-pack */
-       uint32_t **used_shallow;
-       int *need_reachability_test;
-       int *reachable;
-       int *shallow_ref;
-       struct commit **commits;
-       int nr_commits;
-};
-
-void prepare_shallow_info(struct shallow_info *, struct oid_array *);
-void clear_shallow_info(struct shallow_info *);
-void remove_nonexistent_theirs_shallow(struct shallow_info *);
-void assign_shallow_commits_to_refs(struct shallow_info *info,
-                                   uint32_t **used,
-                                   int *ref_status);
-int delayed_reachability_test(struct shallow_info *si, int c);
-#define PRUNE_SHOW_ONLY 1
-#define PRUNE_QUICK 2
-void prune_shallow(unsigned options);
-extern struct trace_key trace_shallow;
 
 int interactive_add(int argc, const char **argv, const char *prefix, int patch);
 int run_add_interactive(const char *revision, const char *patch_mode,
index e72a02d0d577dab4da0f559ed988899baff91fbc..76747c3ada586d0930ff6e2e8f38ebbc8d823973 100644 (file)
@@ -17,6 +17,7 @@
 #include "argv-array.h"
 #include "object-store.h"
 #include "chdir-notify.h"
+#include "shallow.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
index a618f3b0293730d063850345a282805cb08b8233..401d028e4172c6c4ace91c76b1e2edeccdfdfd0c 100644 (file)
@@ -22,6 +22,7 @@
 #include "connected.h"
 #include "fetch-negotiator.h"
 #include "fsck.h"
+#include "shallow.h"
 
 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
diff --git a/git.c b/git.c
index 7be7ad34bd053884ec48923706e70c81719a8660..24be8189e4fc58c959e5ccd864bbf66ddf1dfbfe 100644 (file)
--- a/git.c
+++ b/git.c
@@ -4,6 +4,7 @@
 #include "help.h"
 #include "run-command.h"
 #include "alias.h"
+#include "shallow.h"
 
 #define RUN_SETUP              (1<<0)
 #define RUN_SETUP_GENTLY       (1<<1)
index 0407841ae87af99254f254b65bb53815790fec9a..e0ccfef75af93a5f400659d4f18cf83078442f37 100644 (file)
@@ -15,6 +15,7 @@
 #include "sha1-array.h"
 #include "gpg-interface.h"
 #include "cache.h"
+#include "shallow.h"
 
 int option_parse_push_signed(const struct option *opt,
                             const char *arg, int unset)
index 5010a6c73202b65f16edaadd261d034c6f009005..76e00893fec302d9e801d83ea06ece11be1d1ecb 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -14,6 +14,7 @@
 #include "commit-slab.h"
 #include "list-objects.h"
 #include "commit-reach.h"
+#include "shallow.h"
 
 void set_alternate_shallow_file(struct repository *r, const char *path, int override)
 {
@@ -38,6 +39,19 @@ int register_shallow(struct repository *r, const struct object_id *oid)
        return register_commit_graft(r, graft, 0);
 }
 
+int unregister_shallow(const struct object_id *oid)
+{
+       int pos = commit_graft_pos(the_repository, oid->hash);
+       if (pos < 0)
+               return -1;
+       if (pos + 1 < the_repository->parsed_objects->grafts_nr)
+               MOVE_ARRAY(the_repository->parsed_objects->grafts + pos,
+                          the_repository->parsed_objects->grafts + pos + 1,
+                          the_repository->parsed_objects->grafts_nr - pos - 1);
+       the_repository->parsed_objects->grafts_nr--;
+       return 0;
+}
+
 int is_repository_shallow(struct repository *r)
 {
        FILE *fp;
diff --git a/shallow.h b/shallow.h
new file mode 100644 (file)
index 0000000..b50a85e
--- /dev/null
+++ b/shallow.h
@@ -0,0 +1,64 @@
+#ifndef SHALLOW_H
+#define SHALLOW_H
+
+#include "lockfile.h"
+#include "object.h"
+#include "repository.h"
+#include "strbuf.h"
+
+void set_alternate_shallow_file(struct repository *r, const char *path, int override);
+int register_shallow(struct repository *r, const struct object_id *oid);
+int unregister_shallow(const struct object_id *oid);
+int is_repository_shallow(struct repository *r);
+int commit_shallow_file(struct repository *r, struct lock_file *lk);
+void rollback_shallow_file(struct repository *r, struct lock_file *lk);
+
+struct commit_list *get_shallow_commits(struct object_array *heads,
+                                       int depth, int shallow_flag, int not_shallow_flag);
+struct commit_list *get_shallow_commits_by_rev_list(
+               int ac, const char **av, int shallow_flag, int not_shallow_flag);
+int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
+                         const struct oid_array *extra);
+
+void setup_alternate_shallow(struct lock_file *shallow_lock,
+                            const char **alternate_shallow_file,
+                            const struct oid_array *extra);
+
+const char *setup_temporary_shallow(const struct oid_array *extra);
+
+void advertise_shallow_grafts(int);
+
+#define PRUNE_SHOW_ONLY 1
+#define PRUNE_QUICK 2
+void prune_shallow(unsigned options);
+
+/*
+ * Initialize with prepare_shallow_info() or zero-initialize (equivalent to
+ * prepare_shallow_info with a NULL oid_array).
+ */
+struct shallow_info {
+       struct oid_array *shallow;
+       int *ours, nr_ours;
+       int *theirs, nr_theirs;
+       struct oid_array *ref;
+
+       /* for receive-pack */
+       uint32_t **used_shallow;
+       int *need_reachability_test;
+       int *reachable;
+       int *shallow_ref;
+       struct commit **commits;
+       int nr_commits;
+};
+
+void prepare_shallow_info(struct shallow_info *, struct oid_array *);
+void clear_shallow_info(struct shallow_info *);
+void remove_nonexistent_theirs_shallow(struct shallow_info *);
+void assign_shallow_commits_to_refs(struct shallow_info *info,
+                                   uint32_t **used,
+                                   int *ref_status);
+int delayed_reachability_test(struct shallow_info *si, int c);
+
+extern struct trace_key trace_shallow;
+
+#endif /* SHALLOW_H */
index c53249cac19a33351f4f747782b71f877fc0692f..e71b068291ff5ef3a2c67b31b7098aca82374aef 100644 (file)
@@ -26,6 +26,7 @@
 #include "serve.h"
 #include "commit-graph.h"
 #include "commit-reach.h"
+#include "shallow.h"
 
 /* Remember to update object flag allocation in object.h */
 #define THEY_HAVE      (1u << 11)