From 2b2a5be394bc67bed86bc009195c664dca740bd6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:28 +0000 Subject: each_ref_fn: change to take an object_id parameter Change typedef each_ref_fn to take a "const struct object_id *oid" parameter instead of "const unsigned char *sha1". To aid this transition, implement an adapter that can be used to wrap old-style functions matching the old typedef, which is now called "each_ref_sha1_fn"), and make such functions callable via the new interface. This requires the old function and its cb_data to be wrapped in a "struct each_ref_fn_sha1_adapter", and that object to be used as the cb_data for an adapter function, each_ref_fn_adapter(). This is an enormous diff, but most of it consists of simple, mechanical changes to the sites that call any of the "for_each_ref" family of functions. Subsequent to this change, the call sites can be rewritten one by one to use the new interface. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/remote.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'builtin/remote.c') diff --git a/builtin/remote.c b/builtin/remote.c index ad57fc984e..27a611bfad 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -623,6 +623,8 @@ static int mv(int argc, const char **argv) struct string_list remote_branches = STRING_LIST_INIT_NODUP; struct rename_info rename; int i, refspec_updated = 0; + struct each_ref_fn_sha1_adapter wrapped_read_remote_branches = + {read_remote_branches, &rename}; if (argc != 3) usage_with_options(builtin_remote_rename_usage, options); @@ -700,7 +702,7 @@ static int mv(int argc, const char **argv) * First remove symrefs, then rename the rest, finally create * the new symrefs. */ - for_each_ref(read_remote_branches, &rename); + for_each_ref(each_ref_fn_adapter, &wrapped_read_remote_branches); for (i = 0; i < remote_branches.nr; i++) { struct string_list_item *item = remote_branches.items + i; int flag = 0; @@ -781,6 +783,8 @@ static int rm(int argc, const char **argv) struct string_list skipped = STRING_LIST_INIT_DUP; struct branches_for_remote cb_data; int i, result; + struct each_ref_fn_sha1_adapter wrapped_add_branch_for_removal = + {add_branch_for_removal, &cb_data}; memset(&cb_data, 0, sizeof(cb_data)); cb_data.branches = &branches; @@ -821,7 +825,7 @@ static int rm(int argc, const char **argv) * refs, which are invalidated when deleting a branch. */ cb_data.remote = remote; - result = for_each_ref(add_branch_for_removal, &cb_data); + result = for_each_ref(each_ref_fn_adapter, &wrapped_add_branch_for_removal); strbuf_release(&buf); if (!result) @@ -910,7 +914,10 @@ static int get_remote_ref_states(const char *name, if (query & GET_PUSH_REF_STATES) get_push_ref_states(remote_refs, states); } else { - for_each_ref(append_ref_to_tracked_list, states); + struct each_ref_fn_sha1_adapter wrapped_append_ref_to_tracked_list = + {append_ref_to_tracked_list, states}; + + for_each_ref(each_ref_fn_adapter, &wrapped_append_ref_to_tracked_list); string_list_sort(&states->tracked); get_push_ref_states_noquery(states); } -- cgit v1.2.1 From 45690a57a3aaba862a66096f3ebdf9a412643cf1 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:41 +0000 Subject: add_branch_for_removal(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/remote.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'builtin/remote.c') diff --git a/builtin/remote.c b/builtin/remote.c index 27a611bfad..1986e987a5 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -509,7 +509,7 @@ struct branches_for_remote { }; static int add_branch_for_removal(const char *refname, - const unsigned char *sha1, int flags, void *cb_data) + const struct object_id *oid, int flags, void *cb_data) { struct branches_for_remote *branches = cb_data; struct refspec refspec; @@ -545,7 +545,7 @@ static int add_branch_for_removal(const char *refname, item = string_list_append(branches->branches, refname); item->util = xmalloc(20); - hashcpy(item->util, sha1); + hashcpy(item->util, oid->hash); return 0; } @@ -783,8 +783,6 @@ static int rm(int argc, const char **argv) struct string_list skipped = STRING_LIST_INIT_DUP; struct branches_for_remote cb_data; int i, result; - struct each_ref_fn_sha1_adapter wrapped_add_branch_for_removal = - {add_branch_for_removal, &cb_data}; memset(&cb_data, 0, sizeof(cb_data)); cb_data.branches = &branches; @@ -825,7 +823,7 @@ static int rm(int argc, const char **argv) * refs, which are invalidated when deleting a branch. */ cb_data.remote = remote; - result = for_each_ref(each_ref_fn_adapter, &wrapped_add_branch_for_removal); + result = for_each_ref(add_branch_for_removal, &cb_data); strbuf_release(&buf); if (!result) -- cgit v1.2.1 From e26cdf91c1a836045bcafa3f970b47c0967f3062 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:42 +0000 Subject: add_branch_for_removal(): don't set "util" field of string_list entries They were never used. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/remote.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'builtin/remote.c') diff --git a/builtin/remote.c b/builtin/remote.c index 1986e987a5..ab39fea2b7 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -513,7 +513,6 @@ static int add_branch_for_removal(const char *refname, { struct branches_for_remote *branches = cb_data; struct refspec refspec; - struct string_list_item *item; struct known_remote *kr; memset(&refspec, 0, sizeof(refspec)); @@ -543,9 +542,7 @@ static int add_branch_for_removal(const char *refname, if (flags & REF_ISSYMREF) return unlink(git_path("%s", refname)); - item = string_list_append(branches->branches, refname); - item->util = xmalloc(20); - hashcpy(item->util, oid->hash); + string_list_append(branches->branches, refname); return 0; } @@ -828,7 +825,7 @@ static int rm(int argc, const char **argv) if (!result) result = remove_branches(&branches); - string_list_clear(&branches, 1); + string_list_clear(&branches, 0); if (skipped.nr) { fprintf_ln(stderr, -- cgit v1.2.1 From 53dc95b5cfa1155c3bf9cf909cfc5cb133add1ac Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:43 +0000 Subject: builtin/remote: rewrite functions to take object_id arguments Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/remote.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'builtin/remote.c') diff --git a/builtin/remote.c b/builtin/remote.c index ab39fea2b7..f4a6ec9f13 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -554,20 +554,20 @@ struct rename_info { }; static int read_remote_branches(const char *refname, - const unsigned char *sha1, int flags, void *cb_data) + const struct object_id *oid, int flags, void *cb_data) { struct rename_info *rename = cb_data; struct strbuf buf = STRBUF_INIT; struct string_list_item *item; int flag; - unsigned char orig_sha1[20]; + struct object_id orig_oid; const char *symref; strbuf_addf(&buf, "refs/remotes/%s/", rename->old); if (starts_with(refname, buf.buf)) { item = string_list_append(rename->remote_branches, xstrdup(refname)); symref = resolve_ref_unsafe(refname, RESOLVE_REF_READING, - orig_sha1, &flag); + orig_oid.hash, &flag); if (flag & REF_ISSYMREF) item->util = xstrdup(symref); else @@ -620,8 +620,6 @@ static int mv(int argc, const char **argv) struct string_list remote_branches = STRING_LIST_INIT_NODUP; struct rename_info rename; int i, refspec_updated = 0; - struct each_ref_fn_sha1_adapter wrapped_read_remote_branches = - {read_remote_branches, &rename}; if (argc != 3) usage_with_options(builtin_remote_rename_usage, options); @@ -699,13 +697,13 @@ static int mv(int argc, const char **argv) * First remove symrefs, then rename the rest, finally create * the new symrefs. */ - for_each_ref(each_ref_fn_adapter, &wrapped_read_remote_branches); + for_each_ref(read_remote_branches, &rename); for (i = 0; i < remote_branches.nr; i++) { struct string_list_item *item = remote_branches.items + i; int flag = 0; - unsigned char sha1[20]; + struct object_id oid; - read_ref_full(item->string, RESOLVE_REF_READING, sha1, &flag); + read_ref_full(item->string, RESOLVE_REF_READING, oid.hash, &flag); if (!(flag & REF_ISSYMREF)) continue; if (delete_ref(item->string, NULL, REF_NODEREF)) @@ -866,7 +864,7 @@ static void free_remote_ref_states(struct ref_states *states) } static int append_ref_to_tracked_list(const char *refname, - const unsigned char *sha1, int flags, void *cb_data) + const struct object_id *oid, int flags, void *cb_data) { struct ref_states *states = cb_data; struct refspec refspec; @@ -909,10 +907,7 @@ static int get_remote_ref_states(const char *name, if (query & GET_PUSH_REF_STATES) get_push_ref_states(remote_refs, states); } else { - struct each_ref_fn_sha1_adapter wrapped_append_ref_to_tracked_list = - {append_ref_to_tracked_list, states}; - - for_each_ref(each_ref_fn_adapter, &wrapped_append_ref_to_tracked_list); + for_each_ref(append_ref_to_tracked_list, states); string_list_sort(&states->tracked); get_push_ref_states_noquery(states); } -- cgit v1.2.1