diff options
-rw-r--r-- | builtin/fetch.c | 1 | ||||
-rw-r--r-- | builtin/pack-objects.c | 1 | ||||
-rw-r--r-- | builtin/prune.c | 1 | ||||
-rw-r--r-- | builtin/receive-pack.c | 3 | ||||
-rw-r--r-- | builtin/repack.c | 1 | ||||
-rw-r--r-- | builtin/rev-parse.c | 1 | ||||
-rw-r--r-- | commit-graph.c | 1 | ||||
-rw-r--r-- | commit.c | 16 | ||||
-rw-r--r-- | commit.h | 50 | ||||
-rw-r--r-- | environment.c | 1 | ||||
-rw-r--r-- | fetch-pack.c | 3 | ||||
-rw-r--r-- | git.c | 1 | ||||
-rw-r--r-- | send-pack.c | 1 | ||||
-rw-r--r-- | shallow.c | 36 | ||||
-rw-r--r-- | shallow.h | 81 | ||||
-rw-r--r-- | upload-pack.c | 1 |
16 files changed, 124 insertions, 75 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 3ae52c015d..95beed57fa 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 03b85f5166..c5b433a23f 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -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) diff --git a/builtin/prune.c b/builtin/prune.c index fd9acc7222..02c6ab7cba 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -8,6 +8,7 @@ #include "progress.h" #include "prune-packed.h" #include "object-store.h" +#include "shallow.h" static const char * const prune_usage[] = { N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"), diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d37ab776b3..ea3d0f01af 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -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>"), @@ -876,7 +877,7 @@ static void refuse_unconfigured_deny_delete_current(void) static int command_singleton_iterator(void *cb_data, struct object_id *oid); static int update_shallow_ref(struct command *cmd, struct shallow_info *si) { - struct lock_file shallow_lock = LOCK_INIT; + struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT; struct oid_array extra = OID_ARRAY_INIT; struct check_connected_options opt = CHECK_CONNECTED_INIT; uint32_t mask = 1 << (cmd->index % 32); diff --git a/builtin/repack.c b/builtin/repack.c index 1b686ee9ce..df287739d9 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -13,6 +13,7 @@ #include "prune-packed.h" #include "object-store.h" #include "promisor-remote.h" +#include "shallow.h" static int delta_base_offset = 1; static int pack_kept_objects = -1; diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 06056434ed..669dd2fd6f 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -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 diff --git a/commit-graph.c b/commit-graph.c index 5ea0c8e15c..e3420ddcbf 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -18,6 +18,7 @@ #include "progress.h" #include "bloom.h" #include "commit-slab.h" +#include "shallow.h" void git_test_write_commit_graph_or_die(void) { @@ -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 **); @@ -110,7 +111,7 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table) return commit_graft_table[index]->oid.hash; } -static int commit_graft_pos(struct repository *r, const unsigned char *sha1) +int commit_graft_pos(struct repository *r, const unsigned char *sha1) { return sha1_pos(sha1, r->parsed_objects->grafts, r->parsed_objects->grafts_nr, @@ -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; @@ -236,6 +236,8 @@ struct commit_graft { typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *); struct commit_graft *read_graft_line(struct strbuf *line); +/* commit_graft_pos returns an index into r->parsed_objects->grafts. */ +int commit_graft_pos(struct repository *r, const unsigned char *sha1); int register_commit_graft(struct repository *r, struct commit_graft *, int); void prepare_commit_graft(struct repository *r); struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid); @@ -247,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, diff --git a/environment.c b/environment.c index 10c9061c43..aaca0e91ac 100644 --- a/environment.c +++ b/environment.c @@ -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; diff --git a/fetch-pack.c b/fetch-pack.c index f73a2ce6cb..7eaa19d7c1 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -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; @@ -34,7 +35,7 @@ static int fetch_fsck_objects = -1; static int transfer_fsck_objects = -1; static int agent_supported; static int server_supports_filtering; -static struct lock_file shallow_lock; +static struct shallow_lock shallow_lock; static const char *alternate_shallow_file; static struct strbuf fsck_msg_types = STRBUF_INIT; @@ -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) diff --git a/send-pack.c b/send-pack.c index d1b7edc995..0abee22283 100644 --- a/send-pack.c +++ b/send-pack.c @@ -15,6 +15,7 @@ #include "oid-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) @@ -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; @@ -78,16 +92,16 @@ static void reset_repository_shallow(struct repository *r) stat_validity_clear(r->parsed_objects->shallow_stat); } -int commit_shallow_file(struct repository *r, struct lock_file *lk) +int commit_shallow_file(struct repository *r, struct shallow_lock *lk) { - int res = commit_lock_file(lk); + int res = commit_lock_file(&lk->lock); reset_repository_shallow(r); return res; } -void rollback_shallow_file(struct repository *r, struct lock_file *lk) +void rollback_shallow_file(struct repository *r, struct shallow_lock *lk) { - rollback_lock_file(lk); + rollback_lock_file(&lk->lock); reset_repository_shallow(r); } @@ -352,22 +366,22 @@ const char *setup_temporary_shallow(const struct oid_array *extra) return ""; } -void setup_alternate_shallow(struct lock_file *shallow_lock, +void setup_alternate_shallow(struct shallow_lock *shallow_lock, const char **alternate_shallow_file, const struct oid_array *extra) { struct strbuf sb = STRBUF_INIT; int fd; - fd = hold_lock_file_for_update(shallow_lock, + fd = hold_lock_file_for_update(&shallow_lock->lock, git_path_shallow(the_repository), LOCK_DIE_ON_ERROR); check_shallow_file_for_update(the_repository); if (write_shallow_commits(&sb, 0, extra)) { if (write_in_full(fd, sb.buf, sb.len) < 0) die_errno("failed to write to %s", - get_lock_file_path(shallow_lock)); - *alternate_shallow_file = get_lock_file_path(shallow_lock); + get_lock_file_path(&shallow_lock->lock)); + *alternate_shallow_file = get_lock_file_path(&shallow_lock->lock); } else /* * is_repository_shallow() sees empty string as "no @@ -400,7 +414,7 @@ void advertise_shallow_grafts(int fd) */ void prune_shallow(unsigned options) { - struct lock_file shallow_lock = LOCK_INIT; + struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT; struct strbuf sb = STRBUF_INIT; unsigned flags = SEEN_ONLY; int fd; @@ -414,14 +428,14 @@ void prune_shallow(unsigned options) strbuf_release(&sb); return; } - fd = hold_lock_file_for_update(&shallow_lock, + fd = hold_lock_file_for_update(&shallow_lock.lock, git_path_shallow(the_repository), LOCK_DIE_ON_ERROR); check_shallow_file_for_update(the_repository); if (write_shallow_commits_1(&sb, 0, NULL, flags)) { if (write_in_full(fd, sb.buf, sb.len) < 0) die_errno("failed to write to %s", - get_lock_file_path(&shallow_lock)); + get_lock_file_path(&shallow_lock.lock)); commit_shallow_file(the_repository, &shallow_lock); } else { unlink(git_path_shallow(the_repository)); diff --git a/shallow.h b/shallow.h new file mode 100644 index 0000000000..5b4a96dcd6 --- /dev/null +++ b/shallow.h @@ -0,0 +1,81 @@ +#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); + +/* + * Lock for updating the $GIT_DIR/shallow file. + * + * Use `commit_shallow_file()` to commit an update, or + * `rollback_shallow_file()` to roll it back. In either case, any + * in-memory cached information about which commits are shallow will be + * appropriately invalidated so that future operations reflect the new + * state. + */ +struct shallow_lock { + struct lock_file lock; +}; +#define SHALLOW_LOCK_INIT { LOCK_INIT } + +/* commit $GIT_DIR/shallow and reset stat-validity checks */ +int commit_shallow_file(struct repository *r, struct shallow_lock *lk); +/* rollback $GIT_DIR/shallow and reset stat-validity checks */ +void rollback_shallow_file(struct repository *r, struct shallow_lock *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 shallow_lock *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 */ diff --git a/upload-pack.c b/upload-pack.c index 902d0ad5e1..613a960624 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -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) |