Skip to content

Commit eee4502

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 102de88 commit eee4502

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

commit.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
190190

191191
struct oid_array;
192192
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);
195194
extern int unregister_shallow(const struct object_id *oid);
196195
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);
199197
extern struct commit_list *get_shallow_commits(struct object_array *heads,
200198
int depth, int shallow_flag, int not_shallow_flag);
201199
extern struct commit_list *get_shallow_commits_by_rev_list(
202200
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);
205202
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
206203
const struct oid_array *extra);
207204
extern void setup_alternate_shallow(struct lock_file *shallow_lock,

object.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void)
464464
o->tag_state = allocate_alloc_state();
465465
o->object_state = allocate_alloc_state();
466466

467+
o->is_shallow = -1;
468+
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
469+
467470
return o;
468471
}
469472

object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct parsed_object_pool {
1616
/* parent substitutions from .git/info/grafts and .git/shallow */
1717
struct commit_graft **grafts;
1818
int grafts_alloc, grafts_nr;
19+
20+
int is_shallow;
21+
struct stat_validity *shallow_stat;
22+
char *alternate_shallow_file;
1923
};
2024

2125
struct parsed_object_pool *parsed_object_pool_new(void);

shallow.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,19 @@
1414
#include "commit-slab.h"
1515
#include "revision.h"
1616
#include "list-objects.h"
17+
#include "repository.h"
1718

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)
2320
{
24-
if (is_shallow != -1)
21+
if (r->parsed_objects->is_shallow != -1)
2522
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)
2724
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);
3027
}
3128

32-
int register_shallow_the_repository(const struct object_id *oid)
29+
int register_shallow(struct repository *r, const struct object_id *oid)
3330
{
3431
struct commit_graft *graft =
3532
xmalloc(sizeof(struct commit_graft));
@@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid)
3936
graft->nr_parent = -1;
4037
if (commit && commit->object.parsed)
4138
commit->parents = NULL;
42-
return register_commit_graft(the_repository, graft, 0);
39+
return register_commit_graft(r, graft, 0);
4340
}
4441

45-
int is_repository_shallow_the_repository(void)
42+
int is_repository_shallow(struct repository *r)
4643
{
4744
FILE *fp;
4845
char buf[1024];
49-
const char *path = alternate_shallow_file;
46+
const char *path = r->parsed_objects->alternate_shallow_file;
5047

51-
if (is_shallow >= 0)
52-
return is_shallow;
48+
if (r->parsed_objects->is_shallow >= 0)
49+
return r->parsed_objects->is_shallow;
5350

5451
if (!path)
55-
path = git_path_shallow(the_repository);
52+
path = git_path_shallow(r);
5653
/*
5754
* fetch-pack sets '--shallow-file ""' as an indicator that no
5855
* shallow file should be used. We could just open it and it
5956
* will likely fail. But let's do an explicit check instead.
6057
*/
6158
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;
6562
}
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;
6865

6966
while (fgets(buf, sizeof(buf), fp)) {
7067
struct object_id oid;
7168
if (get_oid_hex(buf, &oid))
7269
die("bad shallow line: %s", buf);
73-
register_shallow(the_repository, &oid);
70+
register_shallow(r, &oid);
7471
}
7572
fclose(fp);
76-
return is_shallow;
73+
return r->parsed_objects->is_shallow;
7774
}
7875

7976
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,
217214
return result;
218215
}
219216

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)
222218
{
223-
if (is_shallow == -1)
219+
if (r->parsed_objects->is_shallow == -1)
224220
die("BUG: shallow must be initialized by now");
225221

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)))
227223
die("shallow file has changed since we read it");
228224
}
229225

0 commit comments

Comments
 (0)