Skip to content

Commit 896833b

Browse files
committed
Merge branch 'tb/shallow-cleanup'
Code cleanup. * tb/shallow-cleanup: shallow: use struct 'shallow_lock' for additional safety shallow.h: document '{commit,rollback}_shallow_file' shallow: extract a header file for shallow-related functions commit: make 'commit_graft_pos' non-static
2 parents b994622 + cac4b8e commit 896833b

16 files changed

+124
-75
lines changed

builtin/fetch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "branch.h"
2828
#include "promisor-remote.h"
2929
#include "commit-graph.h"
30+
#include "shallow.h"
3031

3132
#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
3233

builtin/pack-objects.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "dir.h"
3535
#include "midx.h"
3636
#include "trace2.h"
37+
#include "shallow.h"
3738

3839
#define IN_PACK(obj) oe_in_pack(&to_pack, obj)
3940
#define SIZE(obj) oe_size(&to_pack, obj)

builtin/prune.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "progress.h"
99
#include "prune-packed.h"
1010
#include "object-store.h"
11+
#include "shallow.h"
1112

1213
static const char * const prune_usage[] = {
1314
N_("git prune [-n] [-v] [--progress] [--expire <time>] [--] [<head>...]"),

builtin/receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "protocol.h"
2929
#include "commit-reach.h"
3030
#include "worktree.h"
31+
#include "shallow.h"
3132

3233
static const char * const receive_pack_usage[] = {
3334
N_("git receive-pack <git-dir>"),
@@ -876,7 +877,7 @@ static void refuse_unconfigured_deny_delete_current(void)
876877
static int command_singleton_iterator(void *cb_data, struct object_id *oid);
877878
static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
878879
{
879-
struct lock_file shallow_lock = LOCK_INIT;
880+
struct shallow_lock shallow_lock = SHALLOW_LOCK_INIT;
880881
struct oid_array extra = OID_ARRAY_INIT;
881882
struct check_connected_options opt = CHECK_CONNECTED_INIT;
882883
uint32_t mask = 1 << (cmd->index % 32);

builtin/repack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "prune-packed.h"
1414
#include "object-store.h"
1515
#include "promisor-remote.h"
16+
#include "shallow.h"
1617

1718
static int delta_base_offset = 1;
1819
static int pack_kept_objects = -1;

builtin/rev-parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "split-index.h"
1717
#include "submodule.h"
1818
#include "commit-reach.h"
19+
#include "shallow.h"
1920

2021
#define DO_REVS 1
2122
#define DO_NOREV 2

commit-graph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "progress.h"
1919
#include "bloom.h"
2020
#include "commit-slab.h"
21+
#include "shallow.h"
2122

2223
void git_test_write_commit_graph_or_die(void)
2324
{

commit.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "refs.h"
2121
#include "commit-reach.h"
2222
#include "run-command.h"
23+
#include "shallow.h"
2324

2425
static struct commit_extra_header *read_commit_extra_header_lines(const char *buf, size_t len, const char **);
2526

@@ -110,7 +111,7 @@ static const unsigned char *commit_graft_sha1_access(size_t index, void *table)
110111
return commit_graft_table[index]->oid.hash;
111112
}
112113

113-
static int commit_graft_pos(struct repository *r, const unsigned char *sha1)
114+
int commit_graft_pos(struct repository *r, const unsigned char *sha1)
114115
{
115116
return sha1_pos(sha1, r->parsed_objects->grafts,
116117
r->parsed_objects->grafts_nr,
@@ -245,19 +246,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
245246
return ret;
246247
}
247248

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-
261249
struct commit_buffer {
262250
void *buffer;
263251
unsigned long size;

commit.h

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ struct commit_graft {
236236
typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
237237

238238
struct commit_graft *read_graft_line(struct strbuf *line);
239+
/* commit_graft_pos returns an index into r->parsed_objects->grafts. */
240+
int commit_graft_pos(struct repository *r, const unsigned char *sha1);
239241
int register_commit_graft(struct repository *r, struct commit_graft *, int);
240242
void prepare_commit_graft(struct repository *r);
241243
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);
247249

248250
struct oid_array;
249251
struct ref;
250-
int register_shallow(struct repository *r, const struct object_id *oid);
251-
int unregister_shallow(const struct object_id *oid);
252-
int commit_shallow_file(struct repository *r, struct lock_file *lk);
253-
void rollback_shallow_file(struct repository *r, struct lock_file *lk);
254252
int for_each_commit_graft(each_commit_graft_fn, void *);
255-
int is_repository_shallow(struct repository *r);
256-
struct commit_list *get_shallow_commits(struct object_array *heads,
257-
int depth, int shallow_flag, int not_shallow_flag);
258-
struct commit_list *get_shallow_commits_by_rev_list(
259-
int ac, const char **av, int shallow_flag, int not_shallow_flag);
260-
void set_alternate_shallow_file(struct repository *r, const char *path, int override);
261-
int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
262-
const struct oid_array *extra);
263-
void setup_alternate_shallow(struct lock_file *shallow_lock,
264-
const char **alternate_shallow_file,
265-
const struct oid_array *extra);
266-
const char *setup_temporary_shallow(const struct oid_array *extra);
267-
void advertise_shallow_grafts(int);
268-
269-
/*
270-
* Initialize with prepare_shallow_info() or zero-initialize (equivalent to
271-
* prepare_shallow_info with a NULL oid_array).
272-
*/
273-
struct shallow_info {
274-
struct oid_array *shallow;
275-
int *ours, nr_ours;
276-
int *theirs, nr_theirs;
277-
struct oid_array *ref;
278-
279-
/* for receive-pack */
280-
uint32_t **used_shallow;
281-
int *need_reachability_test;
282-
int *reachable;
283-
int *shallow_ref;
284-
struct commit **commits;
285-
int nr_commits;
286-
};
287-
288-
void prepare_shallow_info(struct shallow_info *, struct oid_array *);
289-
void clear_shallow_info(struct shallow_info *);
290-
void remove_nonexistent_theirs_shallow(struct shallow_info *);
291-
void assign_shallow_commits_to_refs(struct shallow_info *info,
292-
uint32_t **used,
293-
int *ref_status);
294-
int delayed_reachability_test(struct shallow_info *si, int c);
295-
#define PRUNE_SHOW_ONLY 1
296-
#define PRUNE_QUICK 2
297-
void prune_shallow(unsigned options);
298-
extern struct trace_key trace_shallow;
299253

300254
int interactive_add(int argc, const char **argv, const char *prefix, int patch);
301255
int run_add_interactive(const char *revision, const char *patch_mode,

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "argv-array.h"
1818
#include "object-store.h"
1919
#include "chdir-notify.h"
20+
#include "shallow.h"
2021

2122
int trust_executable_bit = 1;
2223
int trust_ctime = 1;

0 commit comments

Comments
 (0)