Add a create_*() function for our built-in types as a handy but trivial wrapper around their calls to create_object(). This allows for slightly simplifying code added in 96af91d410c (commit-graph: verify objects exist, 2018-06-27). The remaining three functions are added for consistency for now. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- blob.c | 7 ++++++- commit-graph.c | 2 +- commit.c | 7 ++++++- commit.h | 1 + t/helper/test-fast-rebase.c | 4 ++-- tag.c | 7 ++++++- tree.c | 7 ++++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/blob.c b/blob.c index 182718aba9..d98b6badc7 100644 --- a/blob.c +++ b/blob.c @@ -5,11 +5,16 @@ const char *blob_type = "blob"; +static struct blob *create_blob(struct repository *r, const struct object_id *oid) +{ + return create_object(r, oid, alloc_blob_node(r)); +} + struct blob *lookup_blob(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); if (!obj) - return create_object(r, oid, alloc_blob_node(r)); + return create_blob(r, oid); return object_as_type(obj, OBJ_BLOB, 0); } diff --git a/commit-graph.c b/commit-graph.c index f18380b922..c456f84f41 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2504,7 +2504,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags) hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i); graph_commit = lookup_commit(r, &cur_oid); - odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r)); + odb_commit = create_commit(r, &cur_oid); if (parse_commit_internal(odb_commit, 0, 0)) { graph_report(_("failed to parse commit %s from object database for commit-graph"), oid_to_hex(&cur_oid)); diff --git a/commit.c b/commit.c index 8ea55a447f..3580c62b92 100644 --- a/commit.c +++ b/commit.c @@ -57,11 +57,16 @@ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref return c; } +struct commit *create_commit(struct repository *r, const struct object_id *oid) +{ + return create_object(r, oid, alloc_commit_node(r)); +} + struct commit *lookup_commit(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); if (!obj) - return create_object(r, oid, alloc_commit_node(r)); + return create_commit(r, oid); return object_as_type(obj, OBJ_COMMIT, 0); } diff --git a/commit.h b/commit.h index df42eb434f..09e2167f8c 100644 --- a/commit.h +++ b/commit.h @@ -63,6 +63,7 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); +struct commit *create_commit(struct repository *r, const struct object_id *oid); struct commit *lookup_commit(struct repository *r, const struct object_id *oid); struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid); diff --git a/t/helper/test-fast-rebase.c b/t/helper/test-fast-rebase.c index 373212256a..e3d3e991a5 100644 --- a/t/helper/test-fast-rebase.c +++ b/t/helper/test-fast-rebase.c @@ -51,7 +51,7 @@ static char *get_author(const char *message) return NULL; } -static struct commit *create_commit(struct tree *tree, +static struct commit *make_a_commit(struct tree *tree, struct commit *based_on, struct commit *parent) { @@ -177,7 +177,7 @@ int cmd__fast_rebase(int argc, const char **argv) if (!result.clean) die("Aborting: Hit a conflict and restarting is not implemented."); last_picked_commit = commit; - last_commit = create_commit(result.tree, commit, last_commit); + last_commit = make_a_commit(result.tree, commit, last_commit); } fprintf(stderr, "\nDone.\n"); /* TODO: There should be some kind of rev_info_free(&revs) call... */ diff --git a/tag.c b/tag.c index 3e18a41841..ed7037256e 100644 --- a/tag.c +++ b/tag.c @@ -99,11 +99,16 @@ struct object *deref_tag_noverify(struct object *o) return o; } +static struct tag *create_tag(struct repository *r, const struct object_id *oid) +{ + return create_object(r, oid, alloc_tag_node(r)); +} + struct tag *lookup_tag(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); if (!obj) - return create_object(r, oid, alloc_tag_node(r)); + return create_tag(r, oid); return object_as_type(obj, OBJ_TAG, 0); } diff --git a/tree.c b/tree.c index 410e3b477e..00958c581e 100644 --- a/tree.c +++ b/tree.c @@ -102,11 +102,16 @@ int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } +static struct tree *create_tree(struct repository *r, const struct object_id *oid) +{ + return create_object(r, oid, alloc_tree_node(r)); +} + struct tree *lookup_tree(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); if (!obj) - return create_object(r, oid, alloc_tree_node(r)); + return create_tree(r, oid); return object_as_type(obj, OBJ_TREE, 0); } -- 2.31.1.723.ga5d7868e4a