From bc83266abe36905cade4719cbaeb8a62d0a382da Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:10 +0000 Subject: Convert lookup_commit* to struct object_id Convert lookup_commit, lookup_commit_or_die, lookup_commit_reference, and lookup_commit_reference_gently to take struct object_id arguments. Introduce a temporary in parse_object buffer in order to convert this function. This is required since in order to convert parse_object and parse_object_buffer, lookup_commit_reference_gently and lookup_commit_or_die would need to be converted. Not introducing a temporary would therefore require that lookup_commit_or_die take a struct object_id *, but lookup_commit would take unsigned char *, leaving a confusing and hard-to-use interface. parse_object_buffer will lose this temporary in a later patch. This commit was created with manual changes to commit.c, commit.h, and object.c, plus the following semantic patch: @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1.hash, E2) + lookup_commit_reference_gently(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_reference_gently(E1->hash, E2) + lookup_commit_reference_gently(E1, E2) @@ expression E1; @@ - lookup_commit_reference(E1.hash) + lookup_commit_reference(&E1) @@ expression E1; @@ - lookup_commit_reference(E1->hash) + lookup_commit_reference(E1) @@ expression E1; @@ - lookup_commit(E1.hash) + lookup_commit(&E1) @@ expression E1; @@ - lookup_commit(E1->hash) + lookup_commit(E1) @@ expression E1, E2; @@ - lookup_commit_or_die(E1.hash, E2) + lookup_commit_or_die(&E1, E2) @@ expression E1, E2; @@ - lookup_commit_or_die(E1->hash, E2) + lookup_commit_or_die(E1, E2) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/checkout.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index bfa5419f33..afa99fb8a0 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -393,7 +393,7 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("unable to write new index file")); read_ref_full("HEAD", 0, rev.hash, NULL); - head = lookup_commit_reference_gently(rev.hash, 1); + head = lookup_commit_reference_gently(&rev, 1); errs |= post_checkout_hook(head, head, 0); return errs; @@ -833,7 +833,7 @@ static int switch_branches(const struct checkout_opts *opts, int flag, writeout_error = 0; memset(&old, 0, sizeof(old)); old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag); - old.commit = lookup_commit_reference_gently(rev.hash, 1); + old.commit = lookup_commit_reference_gently(&rev, 1); if (!(flag & REF_ISSYMREF)) old.path = NULL; @@ -1047,7 +1047,7 @@ static int parse_branchname_arg(int argc, const char **argv, else new->path = NULL; /* not an existing branch */ - new->commit = lookup_commit_reference_gently(rev->hash, 1); + new->commit = lookup_commit_reference_gently(rev, 1); if (!new->commit) { /* not a commit */ *source_tree = parse_tree_indirect(rev->hash); -- cgit v1.2.3 From a58a1b01ff86465f503bf835a41c83e34be376ce Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:26 +0000 Subject: revision: rename add_pending_sha1 to add_pending_oid Rename this function and convert it to take a pointer to struct object_id. This is a prerequisite for converting get_reference, which is needed to convert parse_object. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/checkout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index afa99fb8a0..7f1eeea943 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -721,7 +721,7 @@ static int add_pending_uninteresting_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { - add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING); + add_pending_oid(cb_data, refname, oid, UNINTERESTING); return 0; } @@ -807,7 +807,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) add_pending_object(&revs, object, oid_to_hex(&object->oid)); for_each_ref(add_pending_uninteresting_ref, &revs); - add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING); + add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING); refs = revs.pending; revs.leak_pending = 1; -- cgit v1.2.3 From a9dbc179100b7119cb44eb5b4adcb47967f346a6 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Sat, 6 May 2017 22:10:37 +0000 Subject: tree: convert parse_tree_indirect to struct object_id Convert parse_tree_indirect to take a pointer to struct object_id. Update all the callers. This transformation was achieved using the following semantic patch and manual updates to the declaration and definition. Update builtin/checkout.c manually as well, since it uses a ternary expression not handled by the semantic patch. @@ expression E1; @@ - parse_tree_indirect(E1.hash) + parse_tree_indirect(&E1) @@ expression E1; @@ - parse_tree_indirect(E1->hash) + parse_tree_indirect(E1) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/checkout.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'builtin/checkout.c') diff --git a/builtin/checkout.c b/builtin/checkout.c index 7f1eeea943..13365fb621 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts, setup_standard_excludes(topts.dir); } tree = parse_tree_indirect(old->commit ? - old->commit->object.oid.hash : - EMPTY_TREE_SHA1_BIN); + &old->commit->object.oid : + &empty_tree_oid); init_tree_desc(&trees[0], tree->buffer, tree->size); - tree = parse_tree_indirect(new->commit->object.oid.hash); + tree = parse_tree_indirect(&new->commit->object.oid); init_tree_desc(&trees[1], tree->buffer, tree->size); ret = unpack_trees(2, trees, &topts); @@ -1050,7 +1050,7 @@ static int parse_branchname_arg(int argc, const char **argv, new->commit = lookup_commit_reference_gently(rev, 1); if (!new->commit) { /* not a commit */ - *source_tree = parse_tree_indirect(rev->hash); + *source_tree = parse_tree_indirect(rev); } else { parse_commit_or_die(new->commit); *source_tree = new->commit->tree; -- cgit v1.2.3