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 --- revision.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 7ddbaa083e..93b23a632f 100644 --- a/revision.c +++ b/revision.c @@ -1261,8 +1261,11 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f int (*for_each)(const char *, each_ref_fn, void *)) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &cb}; + init_all_refs_cb(&cb, revs, flags); - for_each(submodule, handle_one_ref, &cb); + for_each(submodule, each_ref_fn_adapter, &wrapped_handle_one_ref); } static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data) @@ -1304,9 +1307,12 @@ static int handle_one_reflog(const char *path, const unsigned char *sha1, int fl void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_reflog = + {handle_one_reflog, &cb}; + cb.all_revs = revs; cb.all_flags = flags; - for_each_reflog(handle_one_reflog, &cb); + for_each_reflog(each_ref_fn_adapter, &wrapped_handle_one_reflog); } static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, @@ -2120,8 +2126,11 @@ static int handle_revision_pseudo_opt(const char *submodule, clear_ref_exclusion(&revs->ref_excludes); } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &cb}; + init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref(handle_one_ref, optarg, &cb); + for_each_glob_ref(each_ref_fn_adapter, optarg, &wrapped_handle_one_ref); clear_ref_exclusion(&revs->ref_excludes); return argcount; } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { @@ -2129,18 +2138,30 @@ static int handle_revision_pseudo_opt(const char *submodule, return argcount; } else if (starts_with(arg, "--branches=")) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &cb}; + init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 11, "refs/heads/", + &wrapped_handle_one_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (starts_with(arg, "--tags=")) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &cb}; + init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 7, "refs/tags/", + &wrapped_handle_one_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (starts_with(arg, "--remotes=")) { struct all_refs_cb cb; + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &cb}; + init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 10, "refs/remotes/", + &wrapped_handle_one_ref); clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--reflog")) { add_reflogs_to_pending(revs, *flags); -- cgit v1.2.3 From a217dcbd1efb8d68baf3dc9765aa8789970527fd Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:30 +0000 Subject: handle_one_ref(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- revision.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 93b23a632f..cfe3876ce8 100644 --- a/revision.c +++ b/revision.c @@ -1218,7 +1218,8 @@ int ref_excluded(struct string_list *ref_excludes, const char *path) return 0; } -static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int handle_one_ref(const char *path, const struct object_id *oid, + int flag, void *cb_data) { struct all_refs_cb *cb = cb_data; struct object *object; @@ -1226,9 +1227,9 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, if (ref_excluded(cb->all_revs->ref_excludes, path)) return 0; - object = get_reference(cb->all_revs, path, sha1, cb->all_flags); + object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags); add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); - add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags); + add_pending_sha1(cb->all_revs, path, oid->hash, cb->all_flags); return 0; } @@ -1261,11 +1262,8 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f int (*for_each)(const char *, each_ref_fn, void *)) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &cb}; - init_all_refs_cb(&cb, revs, flags); - for_each(submodule, each_ref_fn_adapter, &wrapped_handle_one_ref); + for_each(submodule, handle_one_ref, &cb); } static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data) @@ -2126,11 +2124,8 @@ static int handle_revision_pseudo_opt(const char *submodule, clear_ref_exclusion(&revs->ref_excludes); } else if ((argcount = parse_long_opt("glob", argv, &optarg))) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &cb}; - init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref(each_ref_fn_adapter, optarg, &wrapped_handle_one_ref); + for_each_glob_ref(handle_one_ref, optarg, &cb); clear_ref_exclusion(&revs->ref_excludes); return argcount; } else if ((argcount = parse_long_opt("exclude", argv, &optarg))) { @@ -2138,30 +2133,18 @@ static int handle_revision_pseudo_opt(const char *submodule, return argcount; } else if (starts_with(arg, "--branches=")) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &cb}; - init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(each_ref_fn_adapter, arg + 11, "refs/heads/", - &wrapped_handle_one_ref); + for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb); clear_ref_exclusion(&revs->ref_excludes); } else if (starts_with(arg, "--tags=")) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &cb}; - init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(each_ref_fn_adapter, arg + 7, "refs/tags/", - &wrapped_handle_one_ref); + for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb); clear_ref_exclusion(&revs->ref_excludes); } else if (starts_with(arg, "--remotes=")) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &cb}; - init_all_refs_cb(&cb, revs, *flags); - for_each_glob_ref_in(each_ref_fn_adapter, arg + 10, "refs/remotes/", - &wrapped_handle_one_ref); + for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb); clear_ref_exclusion(&revs->ref_excludes); } else if (!strcmp(arg, "--reflog")) { add_reflogs_to_pending(revs, *flags); -- cgit v1.2.3 From a89caf4bd41eff7e144831d48f0ed18a1e4e7630 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:03 +0000 Subject: handle_one_reflog(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- revision.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index cfe3876ce8..1d903cf311 100644 --- a/revision.c +++ b/revision.c @@ -1293,7 +1293,8 @@ static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, return 0; } -static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int handle_one_reflog(const char *path, const struct object_id *oid, + int flag, void *cb_data) { struct all_refs_cb *cb = cb_data; cb->warned_bad_reflog = 0; @@ -1305,12 +1306,10 @@ static int handle_one_reflog(const char *path, const unsigned char *sha1, int fl void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) { struct all_refs_cb cb; - struct each_ref_fn_sha1_adapter wrapped_handle_one_reflog = - {handle_one_reflog, &cb}; cb.all_revs = revs; cb.all_flags = flags; - for_each_reflog(each_ref_fn_adapter, &wrapped_handle_one_reflog); + for_each_reflog(handle_one_reflog, &cb); } static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, -- cgit v1.2.3