diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-08-02 15:30:42 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-08-02 15:30:42 -0700 |
commit | 3a2a1dc17077a27ad1a89db27cb1b4b374f3b0ff (patch) | |
tree | 7cd70df6ba2e915e629a1138373a5c878cd0db45 /commit.c | |
parent | Merge branch 'is/parsing-line-range' (diff) | |
parent | commit.c: allow lookup_commit_reference to handle arbitrary repositories (diff) | |
download | tgif-3a2a1dc17077a27ad1a89db27cb1b4b374f3b0ff.tar.xz |
Merge branch 'sb/object-store-lookup'
lookup_commit_reference() and friends have been updated to find
in-core object for a specific in-core repository instance.
* sb/object-store-lookup: (32 commits)
commit.c: allow lookup_commit_reference to handle arbitrary repositories
commit.c: allow lookup_commit_reference_gently to handle arbitrary repositories
tag.c: allow deref_tag to handle arbitrary repositories
object.c: allow parse_object to handle arbitrary repositories
object.c: allow parse_object_buffer to handle arbitrary repositories
commit.c: allow get_cached_commit_buffer to handle arbitrary repositories
commit.c: allow set_commit_buffer to handle arbitrary repositories
commit.c: migrate the commit buffer to the parsed object store
commit-slabs: remove realloc counter outside of slab struct
commit.c: allow parse_commit_buffer to handle arbitrary repositories
tag: allow parse_tag_buffer to handle arbitrary repositories
tag: allow lookup_tag to handle arbitrary repositories
commit: allow lookup_commit to handle arbitrary repositories
tree: allow lookup_tree to handle arbitrary repositories
blob: allow lookup_blob to handle arbitrary repositories
object: allow lookup_object to handle arbitrary repositories
object: allow object_as_type to handle arbitrary repositories
tag: add repository argument to deref_tag
tag: add repository argument to parse_tag_buffer
tag: add repository argument to lookup_tag
...
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 80 |
1 files changed, 50 insertions, 30 deletions
@@ -24,24 +24,26 @@ int save_commit_buffer = 1; const char *commit_type = "commit"; -struct commit *lookup_commit_reference_gently(const struct object_id *oid, - int quiet) +struct commit *lookup_commit_reference_gently(struct repository *r, + const struct object_id *oid, int quiet) { - struct object *obj = deref_tag(parse_object(oid), NULL, 0); + struct object *obj = deref_tag(r, + parse_object(r, oid), + NULL, 0); if (!obj) return NULL; - return object_as_type(obj, OBJ_COMMIT, quiet); + return object_as_type(r, obj, OBJ_COMMIT, quiet); } -struct commit *lookup_commit_reference(const struct object_id *oid) +struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid) { - return lookup_commit_reference_gently(oid, 0); + return lookup_commit_reference_gently(r, oid, 0); } struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name) { - struct commit *c = lookup_commit_reference(oid); + struct commit *c = lookup_commit_reference(the_repository, oid); if (!c) die(_("could not parse %s"), ref_name); if (oidcmp(oid, &c->object.oid)) { @@ -51,13 +53,13 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } -struct commit *lookup_commit(const struct object_id *oid) +struct commit *lookup_commit(struct repository *r, const struct object_id *oid) { - struct object *obj = lookup_object(oid->hash); + struct object *obj = lookup_object(r, oid->hash); if (!obj) - return create_object(the_repository, oid->hash, - alloc_commit_node(the_repository)); - return object_as_type(obj, OBJ_COMMIT, 0); + return create_object(r, oid->hash, + alloc_commit_node(r)); + return object_as_type(r, obj, OBJ_COMMIT, 0); } struct commit *lookup_commit_reference_by_name(const char *name) @@ -67,7 +69,7 @@ struct commit *lookup_commit_reference_by_name(const char *name) if (get_oid_committish(name, &oid)) return NULL; - commit = lookup_commit_reference(&oid); + commit = lookup_commit_reference(the_repository, &oid); if (parse_commit(commit)) return NULL; return commit; @@ -259,18 +261,32 @@ struct commit_buffer { unsigned long size; }; define_commit_slab(buffer_slab, struct commit_buffer); -static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab); -void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size) +struct buffer_slab *allocate_commit_buffer_slab(void) { - struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + struct buffer_slab *bs = xmalloc(sizeof(*bs)); + init_buffer_slab(bs); + return bs; +} + +void free_commit_buffer_slab(struct buffer_slab *bs) +{ + clear_buffer_slab(bs); + free(bs); +} + +void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size) +{ + struct commit_buffer *v = buffer_slab_at( + r->parsed_objects->buffer_slab, commit); v->buffer = buffer; v->size = size; } -const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep) +const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + r->parsed_objects->buffer_slab, commit); if (!v) { if (sizep) *sizep = 0; @@ -283,7 +299,7 @@ const void *get_cached_commit_buffer(const struct commit *commit, unsigned long const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) { - const void *ret = get_cached_commit_buffer(commit, sizep); + const void *ret = get_cached_commit_buffer(the_repository, commit, sizep); if (!ret) { enum object_type type; unsigned long size; @@ -302,14 +318,16 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) void unuse_commit_buffer(const struct commit *commit, const void *buffer) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); if (!(v && v->buffer == buffer)) free((void *)buffer); } void free_commit_buffer(struct commit *commit) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); if (v) { FREE_AND_NULL(v->buffer); v->size = 0; @@ -345,7 +363,8 @@ void release_commit_memory(struct commit *c) const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) { - struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit); + struct commit_buffer *v = buffer_slab_peek( + the_repository->parsed_objects->buffer_slab, commit); void *ret; if (!v) { @@ -362,7 +381,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) return ret; } -int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size, int check_graph) +int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph) { const char *tail = buffer; const char *bufptr = buffer; @@ -382,11 +401,11 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s if (get_oid_hex(bufptr + 5, &parent) < 0) return error("bad tree pointer in commit %s", oid_to_hex(&item->object.oid)); - item->maybe_tree = lookup_tree(&parent); + item->maybe_tree = lookup_tree(r, &parent); bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; - graft = lookup_commit_graft(the_repository, &item->object.oid); + graft = lookup_commit_graft(r, &item->object.oid); while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { struct commit *new_parent; @@ -401,7 +420,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s */ if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; - new_parent = lookup_commit(&parent); + new_parent = lookup_commit(r, &parent); if (new_parent) pptr = &commit_list_insert(new_parent, pptr)->next; } @@ -409,7 +428,8 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s int i; struct commit *new_parent; for (i = 0; i < graft->nr_parent; i++) { - new_parent = lookup_commit(&graft->parent[i]); + new_parent = lookup_commit(r, + &graft->parent[i]); if (!new_parent) continue; pptr = &commit_list_insert(new_parent, pptr)->next; @@ -447,9 +467,9 @@ int parse_commit_internal(struct commit *item, int quiet_on_missing, int use_com oid_to_hex(&item->object.oid)); } - ret = parse_commit_buffer(item, buffer, size, 0); + ret = parse_commit_buffer(the_repository, item, buffer, size, 0); if (save_commit_buffer && !ret) { - set_commit_buffer(item, buffer, size); + set_commit_buffer(the_repository, item, buffer, size); return 0; } free(buffer); @@ -1698,7 +1718,7 @@ struct commit *get_merge_parent(const char *name) struct object_id oid; if (get_oid(name, &oid)) return NULL; - obj = parse_object(&oid); + obj = parse_object(the_repository, &oid); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); if (commit && !merge_remote_util(commit)) set_merge_remote_desc(commit, name, obj); |