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>
This commit is contained in:
Stefan Beller 2018-05-17 15:51:52 -07:00 committed by Junio C Hamano
parent 102de880d2
commit eee4502baa
4 changed files with 33 additions and 33 deletions

View File

@ -190,18 +190,15 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
struct oid_array; struct oid_array;
struct ref; struct ref;
#define register_shallow(r, o) register_shallow_##r(o); extern int register_shallow(struct repository *r, const struct object_id *oid);
extern int register_shallow_the_repository(const struct object_id *oid);
extern int unregister_shallow(const struct object_id *oid); extern int unregister_shallow(const struct object_id *oid);
extern int for_each_commit_graft(each_commit_graft_fn, void *); extern int for_each_commit_graft(each_commit_graft_fn, void *);
#define is_repository_shallow(r) is_repository_shallow_##r() extern int is_repository_shallow(struct repository *r);
extern int is_repository_shallow_the_repository(void);
extern struct commit_list *get_shallow_commits(struct object_array *heads, extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag); int depth, int shallow_flag, int not_shallow_flag);
extern struct commit_list *get_shallow_commits_by_rev_list( extern struct commit_list *get_shallow_commits_by_rev_list(
int ac, const char **av, int shallow_flag, int not_shallow_flag); int ac, const char **av, int shallow_flag, int not_shallow_flag);
#define set_alternate_shallow_file(r, p, o) set_alternate_shallow_file_##r(p, o) extern void set_alternate_shallow_file(struct repository *r, const char *path, int override);
extern void set_alternate_shallow_file_the_repository(const char *path, int override);
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol, extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
const struct oid_array *extra); const struct oid_array *extra);
extern void setup_alternate_shallow(struct lock_file *shallow_lock, extern void setup_alternate_shallow(struct lock_file *shallow_lock,

View File

@ -464,6 +464,9 @@ struct parsed_object_pool *parsed_object_pool_new(void)
o->tag_state = allocate_alloc_state(); o->tag_state = allocate_alloc_state();
o->object_state = allocate_alloc_state(); o->object_state = allocate_alloc_state();
o->is_shallow = -1;
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
return o; return o;
} }

View File

@ -16,6 +16,10 @@ struct parsed_object_pool {
/* parent substitutions from .git/info/grafts and .git/shallow */ /* parent substitutions from .git/info/grafts and .git/shallow */
struct commit_graft **grafts; struct commit_graft **grafts;
int grafts_alloc, grafts_nr; int grafts_alloc, grafts_nr;
int is_shallow;
struct stat_validity *shallow_stat;
char *alternate_shallow_file;
}; };
struct parsed_object_pool *parsed_object_pool_new(void); struct parsed_object_pool *parsed_object_pool_new(void);

View File

@ -14,22 +14,19 @@
#include "commit-slab.h" #include "commit-slab.h"
#include "revision.h" #include "revision.h"
#include "list-objects.h" #include "list-objects.h"
#include "repository.h"
static int is_shallow = -1; void set_alternate_shallow_file(struct repository *r, const char *path, int override)
static struct stat_validity shallow_stat;
static char *alternate_shallow_file;
void set_alternate_shallow_file_the_repository(const char *path, int override)
{ {
if (is_shallow != -1) if (r->parsed_objects->is_shallow != -1)
die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file"); die("BUG: is_repository_shallow must not be called before set_alternate_shallow_file");
if (alternate_shallow_file && !override) if (r->parsed_objects->alternate_shallow_file && !override)
return; return;
free(alternate_shallow_file); free(r->parsed_objects->alternate_shallow_file);
alternate_shallow_file = xstrdup_or_null(path); r->parsed_objects->alternate_shallow_file = xstrdup_or_null(path);
} }
int register_shallow_the_repository(const struct object_id *oid) int register_shallow(struct repository *r, const struct object_id *oid)
{ {
struct commit_graft *graft = struct commit_graft *graft =
xmalloc(sizeof(struct commit_graft)); xmalloc(sizeof(struct commit_graft));
@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid)
graft->nr_parent = -1; graft->nr_parent = -1;
if (commit && commit->object.parsed) if (commit && commit->object.parsed)
commit->parents = NULL; commit->parents = NULL;
return register_commit_graft(the_repository, graft, 0); return register_commit_graft(r, graft, 0);
} }
int is_repository_shallow_the_repository(void) int is_repository_shallow(struct repository *r)
{ {
FILE *fp; FILE *fp;
char buf[1024]; char buf[1024];
const char *path = alternate_shallow_file; const char *path = r->parsed_objects->alternate_shallow_file;
if (is_shallow >= 0) if (r->parsed_objects->is_shallow >= 0)
return is_shallow; return r->parsed_objects->is_shallow;
if (!path) if (!path)
path = git_path_shallow(the_repository); path = git_path_shallow(r);
/* /*
* fetch-pack sets '--shallow-file ""' as an indicator that no * fetch-pack sets '--shallow-file ""' as an indicator that no
* shallow file should be used. We could just open it and it * shallow file should be used. We could just open it and it
* will likely fail. But let's do an explicit check instead. * will likely fail. But let's do an explicit check instead.
*/ */
if (!*path || (fp = fopen(path, "r")) == NULL) { if (!*path || (fp = fopen(path, "r")) == NULL) {
stat_validity_clear(&shallow_stat); stat_validity_clear(r->parsed_objects->shallow_stat);
is_shallow = 0; r->parsed_objects->is_shallow = 0;
return is_shallow; return r->parsed_objects->is_shallow;
} }
stat_validity_update(&shallow_stat, fileno(fp)); stat_validity_update(r->parsed_objects->shallow_stat, fileno(fp));
is_shallow = 1; r->parsed_objects->is_shallow = 1;
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
struct object_id oid; struct object_id oid;
if (get_oid_hex(buf, &oid)) if (get_oid_hex(buf, &oid))
die("bad shallow line: %s", buf); die("bad shallow line: %s", buf);
register_shallow(the_repository, &oid); register_shallow(r, &oid);
} }
fclose(fp); fclose(fp);
return is_shallow; return r->parsed_objects->is_shallow;
} }
struct commit_list *get_shallow_commits(struct object_array *heads, int depth, 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,
return result; return result;
} }
#define check_shallow_file_for_update(r) check_shallow_file_for_update_##r() static void check_shallow_file_for_update(struct repository *r)
static void check_shallow_file_for_update_the_repository(void)
{ {
if (is_shallow == -1) if (r->parsed_objects->is_shallow == -1)
die("BUG: shallow must be initialized by now"); die("BUG: shallow must be initialized by now");
if (!stat_validity_check(&shallow_stat, git_path_shallow(the_repository))) if (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))
die("shallow file has changed since we read it"); die("shallow file has changed since we read it");
} }