shallow: migrate shallow information into the object parser

We need to convert the shallow functions all at the same time as we move the data structures they operate on into the repository. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 17, 2018 at 15:51 UTC eee4502baaf8f82c20bcda70625df56ce68dd9b1
4 files changed +33 -33
commit.h
+3 -6
@@ -190,18 +190,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
190
191 struct oid_array;
192 struct ref;
193 -#define register_shallow(r, o) register_shallow_##r(o);
194 -extern int register_shallow_the_repository(const struct object_id *oid);
193 +extern int register_shallow(struct repository *r, const struct object_id *oid);
194 extern int unregister_shallow(const struct object_id *oid);
195 extern int for_each_commit_graft(each_commit_graft_fn, void *);
197 -#define is_repository_shallow(r) is_repository_shallow_##r()
198 -extern int is_repository_shallow_the_repository(void);
196 +extern int is_repository_shallow(struct repository *r);
197 extern struct commit_list *get_shallow_commits(struct object_array *heads,
198 int depth, int shallow_flag, int not_shallow_flag);
199 extern struct commit_list *get_shallow_commits_by_rev_list(
200 int ac, const char **av, int shallow_flag, int not_shallow_flag);
203 -#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o)
204 -extern void set_alternate_shallow_file_the_repository(const char *path, int override);
201 +extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
202 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
203 const struct oid_array *extra);
204 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
object.c
+3
@@ -464,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void)
464 o->tag_state = allocate_alloc_state();
465 o->object_state = allocate_alloc_state();
466
467 + o->is_shallow = -1;
468 + o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
469 +
470 return o;
471 }
472
object.h
+4
@@ -16,6 +16,10 @@ struct parsed_object_pool {
16 /* parent substitutions from .git/info/grafts and .git/shallow */
17 struct commit_graft **grafts;
18 int grafts_alloc, grafts_nr;
19 +
20 + int is_shallow;
21 + struct stat_validity *shallow_stat;
22 + char *alternate_shallow_file;
23 };
24
25 struct parsed_object_pool *parsed_object_pool_new(void);
shallow.c
+23 -27
@@ -14,22 +14,19 @@
14 #include "commit-slab.h"
15 #include "revision.h"
16 #include "list-objects.h"
17 +#include "repository.h"
18
18 -static int is_shallow = -1;
19 -static struct stat_validity shallow_stat;
20 -static char *alternate_shallow_file;
21 -
22 -void set_alternate_shallow_file_the_repository(const char *path, int override)
19 +void set_alternate_shallow_file(struct repository *r, const char *path, int override)
20 {
24 - if (is_shallow != -1)
21 + if (r->parsed_objects->is_shallow != -1)
22 die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
26 - if (alternate_shallow_file && !override)
23 + if (r->parsed_objects->alternate_shallow_file && !override)
24 return;
28 - free(alternate_shallow_file);
29 - alternate_shallow_file = xstrdup_or_null(path);
25 + free(r->parsed_objects->alternate_shallow_file);
26 + r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path);
27 }
28
32 -int register_shallow_the_repository(const struct object_id *oid)
29 +int register_shallow(struct repository *r, const struct object_id *oid)
30 {
31 struct commit_graft *graft =
32 xmalloc(sizeof(struct commit_graft));
@@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid)
36 graft->nr_parent = -1;
37 if (commit && commit->object.parsed)
38 commit->parents = NULL;
42 - return register_commit_graft(the_repository, graft, 0);
39 + return register_commit_graft(r, graft, 0);
40 }
41
45 -int is_repository_shallow_the_repository(void)
42 +int is_repository_shallow(struct repository *r)
43 {
44 FILE *fp;
45 char buf[1024];
49 - const char *path = alternate_shallow_file;
46 + const char *path = r->parsed_objects->alternate_shallow_file;
47
51 - if (is_shallow >= 0)
52 - return is_shallow;
48 + if (r->parsed_objects->is_shallow >= 0)
49 + return r->parsed_objects->is_shallow;
50
51 if (!path)
55 - path = git_path_shallow(the_repository);
52 + path = git_path_shallow(r);
53 /*
54 * fetch-pack sets '--shallow-file ""' as an indicator that no
55 * shallow file should be used. We could just open it and it
56 * will likely fail. But let's do an explicit check instead.
57 */
58 if (!*path || (fp = fopen(path, "r")) == NULL) {
62 - stat_validity_clear(&shallow_stat);
63 - is_shallow = 0;
64 - return is_shallow;
59 + stat_validity_clear(r->parsed_objects->shallow_stat);
60 + r->parsed_objects->is_shallow = 0;
61 + return r->parsed_objects->is_shallow;
62 }
66 - stat_validity_update(&shallow_stat, fileno(fp));
67 - is_shallow = 1;
63 + stat_validity_update(r->parsed_objects->shallow_stat, fileno(fp));
64 + r->parsed_objects->is_shallow = 1;
65
66 while (fgets(buf, sizeof(buf), fp)) {
67 struct object_id oid;
68 if (get_oid_hex(buf, &oid))
69 die("bad shallow line: %s", buf);
73 - register_shallow(the_repository, &oid);
70 + register_shallow(r, &oid);
71 }
72 fclose(fp);
76 - return is_shallow;
73 + return r->parsed_objects->is_shallow;
74 }
75
76 struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
@@ -217,13 +214,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
214 return result;
215 }
216
220 -#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r()
221 -static void check_shallow_file_for_update_the_repository(void)
217 +static void check_shallow_file_for_update(struct repository *r)
218 {
223 - if (is_shallow == -1)
219 + if (r->parsed_objects->is_shallow == -1)
220 die("BUG: shallow must be initialized by now");
221
226 - if (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository)))
222 + if (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))
223 die("shallow file has changed since we read it");
224 }
225