From 8353847e85128e0d0bbed862889f6f36c608c73b Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 25 May 2015 18:38:27 +0000 Subject: refs: convert struct ref_entry to use struct object_id Signed-off-by: brian m. carlson Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 8480d8d..9ca4651 100644 --- a/refs.c +++ b/refs.c @@ -161,7 +161,7 @@ struct ref_value { * null. If REF_ISSYMREF, then this is the name of the object * referred to by the last reference in the symlink chain. */ - unsigned char sha1[20]; + struct object_id oid; /* * If REF_KNOWS_PEELED, then this field holds the peeled value @@ -169,7 +169,7 @@ struct ref_value { * be peelable. See the documentation for peel_ref() for an * exact definition of "peelable". */ - unsigned char peeled[20]; + struct object_id peeled; }; struct ref_cache; @@ -351,8 +351,8 @@ static struct ref_entry *create_ref_entry(const char *refname, die("Reference has invalid format: '%s'", refname); len = strlen(refname) + 1; ref = xmalloc(sizeof(struct ref_entry) + len); - hashcpy(ref->u.value.sha1, sha1); - hashclr(ref->u.value.peeled); + hashcpy(ref->u.value.oid.hash, sha1); + oidclr(&ref->u.value.peeled); memcpy(ref->name, refname, len); ref->flag = flag; return ref; @@ -626,7 +626,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2 /* This is impossible by construction */ die("Reference directory conflict: %s", ref1->name); - if (hashcmp(ref1->u.value.sha1, ref2->u.value.sha1)) + if (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid)) die("Duplicated ref, and SHA1s don't match: %s", ref1->name); warning("Duplicated ref: %s", ref1->name); @@ -674,7 +674,7 @@ static int ref_resolves_to_object(struct ref_entry *entry) { if (entry->flag & REF_ISBROKEN) return 0; - if (!has_sha1_file(entry->u.value.sha1)) { + if (!has_sha1_file(entry->u.value.oid.hash)) { error("%s does not point to a valid object!", entry->name); return 0; } @@ -722,7 +722,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data) /* Store the old value, in case this is a recursive call: */ old_current_ref = current_ref; current_ref = entry; - retval = data->fn(entry->name + data->trim, entry->u.value.sha1, + retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash, entry->flag, data->cb_data); current_ref = old_current_ref; return retval; @@ -1258,7 +1258,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir) line.len == PEELED_LINE_LENGTH && line.buf[PEELED_LINE_LENGTH - 1] == '\n' && !get_sha1_hex(line.buf + 1, sha1)) { - hashcpy(last->u.value.peeled, sha1); + hashcpy(last->u.value.peeled.hash, sha1); /* * Regardless of what the file header said, * we definitely know the value of *this* @@ -1439,7 +1439,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs, if (ref == NULL) return -1; - hashcpy(sha1, ref->u.value.sha1); + hashcpy(sha1, ref->u.value.oid.hash); return 0; } @@ -1526,7 +1526,7 @@ static int resolve_missing_loose_ref(const char *refname, */ entry = get_packed_ref(refname); if (entry) { - hashcpy(sha1, entry->u.value.sha1); + hashcpy(sha1, entry->u.value.oid.hash); if (flags) *flags |= REF_ISPACKED; return 0; @@ -1836,9 +1836,9 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel) if (entry->flag & REF_KNOWS_PEELED) { if (repeel) { entry->flag &= ~REF_KNOWS_PEELED; - hashclr(entry->u.value.peeled); + oidclr(&entry->u.value.peeled); } else { - return is_null_sha1(entry->u.value.peeled) ? + return is_null_oid(&entry->u.value.peeled) ? PEEL_NON_TAG : PEEL_PEELED; } } @@ -1847,7 +1847,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel) if (entry->flag & REF_ISSYMREF) return PEEL_IS_SYMREF; - status = peel_object(entry->u.value.sha1, entry->u.value.peeled); + status = peel_object(entry->u.value.oid.hash, entry->u.value.peeled.hash); if (status == PEEL_PEELED || status == PEEL_NON_TAG) entry->flag |= REF_KNOWS_PEELED; return status; @@ -1862,7 +1862,7 @@ int peel_ref(const char *refname, unsigned char *sha1) || !strcmp(current_ref->name, refname))) { if (peel_entry(current_ref, 0)) return -1; - hashcpy(sha1, current_ref->u.value.peeled); + hashcpy(sha1, current_ref->u.value.peeled.hash); return 0; } @@ -1882,7 +1882,7 @@ int peel_ref(const char *refname, unsigned char *sha1) if (r) { if (peel_entry(r, 0)) return -1; - hashcpy(sha1, r->u.value.peeled); + hashcpy(sha1, r->u.value.peeled.hash); return 0; } } @@ -2496,9 +2496,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data) if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG) error("internal error: %s is not a valid packed reference!", entry->name); - write_packed_entry(cb_data, entry->name, entry->u.value.sha1, + write_packed_entry(cb_data, entry->name, entry->u.value.oid.hash, peel_status == PEEL_PEELED ? - entry->u.value.peeled : NULL); + entry->u.value.peeled.hash : NULL); return 0; } @@ -2615,24 +2615,24 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data) peel_status = peel_entry(entry, 1); if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG) die("internal error peeling reference %s (%s)", - entry->name, sha1_to_hex(entry->u.value.sha1)); + entry->name, oid_to_hex(&entry->u.value.oid)); packed_entry = find_ref(cb->packed_refs, entry->name); if (packed_entry) { /* Overwrite existing packed entry with info from loose entry */ packed_entry->flag = REF_ISPACKED | REF_KNOWS_PEELED; - hashcpy(packed_entry->u.value.sha1, entry->u.value.sha1); + oidcpy(&packed_entry->u.value.oid, &entry->u.value.oid); } else { - packed_entry = create_ref_entry(entry->name, entry->u.value.sha1, + packed_entry = create_ref_entry(entry->name, entry->u.value.oid.hash, REF_ISPACKED | REF_KNOWS_PEELED, 0); add_ref(cb->packed_refs, packed_entry); } - hashcpy(packed_entry->u.value.peeled, entry->u.value.peeled); + oidcpy(&packed_entry->u.value.peeled, &entry->u.value.peeled); /* Schedule the loose reference for pruning if requested. */ if ((cb->flags & PACK_REFS_PRUNE)) { int namelen = strlen(entry->name) + 1; struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen); - hashcpy(n->sha1, entry->u.value.sha1); + hashcpy(n->sha1, entry->u.value.oid.hash); strcpy(n->name, entry->name); n->next = cb->ref_to_prune; cb->ref_to_prune = n; -- cgit v0.10.2-6-g49f6 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 diff --git a/Documentation/technical/api-ref-iteration.txt b/Documentation/technical/api-ref-iteration.txt index 02adfd4..37379d8 100644 --- a/Documentation/technical/api-ref-iteration.txt +++ b/Documentation/technical/api-ref-iteration.txt @@ -6,7 +6,7 @@ Iteration of refs is done by using an iterate function which will call a callback function for every ref. The callback function has this signature: - int handle_one_ref(const char *refname, const unsigned char *sha1, + int handle_one_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data); There are different kinds of iterate functions which all take a diff --git a/bisect.c b/bisect.c index 10f5e57..0848d91 100644 --- a/bisect.c +++ b/bisect.c @@ -417,7 +417,10 @@ static int register_ref(const char *refname, const unsigned char *sha1, static int read_bisect_refs(void) { - return for_each_ref_in("refs/bisect/", register_ref, NULL); + struct each_ref_fn_sha1_adapter wrapped_register_ref = + {register_ref, NULL}; + + return for_each_ref_in("refs/bisect/", each_ref_fn_adapter, &wrapped_register_ref); } static void read_bisect_paths(struct argv_array *array) diff --git a/builtin/branch.c b/builtin/branch.c index 9cbab18..b27adcb 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -631,6 +631,8 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru int i; struct append_ref_cb cb; struct ref_list ref_list; + struct each_ref_fn_sha1_adapter wrapped_append_ref = + {append_ref, &cb}; memset(&ref_list, 0, sizeof(ref_list)); ref_list.kinds = kinds; @@ -642,7 +644,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru cb.ref_list = &ref_list; cb.pattern = pattern; cb.ret = 0; - for_each_rawref(append_ref, &cb); + for_each_rawref(each_ref_fn_adapter, &wrapped_append_ref); if (merge_filter != NO_FILTER) { struct commit *filter; filter = lookup_commit_reference_gently(merge_filter_ref, 0); diff --git a/builtin/checkout.c b/builtin/checkout.c index 2f92328..9416aa2 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -784,6 +784,8 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) struct rev_info revs; struct object *object = &old->object; struct object_array refs; + struct each_ref_fn_sha1_adapter wrapped_add_pending_uninteresting_ref = + {add_pending_uninteresting_ref, &revs}; init_revisions(&revs, NULL); setup_revisions(0, NULL, &revs, NULL); @@ -791,7 +793,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) object->flags &= ~UNINTERESTING; add_pending_object(&revs, object, sha1_to_hex(object->sha1)); - for_each_ref(add_pending_uninteresting_ref, &revs); + for_each_ref(each_ref_fn_adapter, &wrapped_add_pending_uninteresting_ref); add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING); refs = revs.pending; diff --git a/builtin/describe.c b/builtin/describe.c index e00a75b..7d0c855 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -413,6 +413,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix) PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"}, OPT_END(), }; + struct each_ref_fn_sha1_adapter wrapped_get_name = + {get_name, NULL}; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, describe_usage, 0); @@ -451,7 +453,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) } hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0); - for_each_rawref(get_name, NULL); + for_each_rawref(each_ref_fn_adapter, &wrapped_get_name); if (!names.size && !always) die(_("No names found, cannot describe anything.")); diff --git a/builtin/fetch.c b/builtin/fetch.c index 7910419..4878c3d 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -208,8 +208,10 @@ static void find_non_local_tags(struct transport *transport, struct string_list remote_refs = STRING_LIST_INIT_NODUP; const struct ref *ref; struct string_list_item *item = NULL; + struct each_ref_fn_sha1_adapter wrapped_add_existing = + {add_existing, &existing_refs}; - for_each_ref(add_existing, &existing_refs); + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) { if (!starts_with(ref->name, "refs/tags/")) continue; @@ -884,8 +886,10 @@ static int do_fetch(struct transport *transport, struct ref *rm; int autotags = (transport->remote->fetch_tags == 1); int retcode = 0; + struct each_ref_fn_sha1_adapter wrapped_add_existing = + {add_existing, &existing_refs}; - for_each_ref(add_existing, &existing_refs); + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); if (tags == TAGS_DEFAULT) { if (transport->remote->fetch_tags == 2) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 83f9cf9..caccd93 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -1072,6 +1072,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) int maxcount = 0, quote_style = 0; struct refinfo **refs; struct grab_ref_cbdata cbdata; + struct each_ref_fn_sha1_adapter wrapped_grab_single_ref = + {grab_single_ref, &cbdata}; struct option opts[] = { OPT_BIT('s', "shell", "e_style, @@ -1111,7 +1113,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) memset(&cbdata, 0, sizeof(cbdata)); cbdata.grab_pattern = argv; - for_each_rawref(grab_single_ref, &cbdata); + for_each_rawref(each_ref_fn_adapter, &wrapped_grab_single_ref); refs = cbdata.grab_array; num_refs = cbdata.grab_cnt; diff --git a/builtin/fsck.c b/builtin/fsck.c index 4783896..48d0c2e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -504,11 +504,16 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f static void get_default_heads(void) { + struct each_ref_fn_sha1_adapter wrapped_fsck_handle_ref = + {fsck_handle_ref, NULL}; + struct each_ref_fn_sha1_adapter wrapped_fsck_handle_reflog = + {fsck_handle_reflog, NULL}; + if (head_points_at && !is_null_sha1(head_sha1)) fsck_handle_ref("HEAD", head_sha1, 0, NULL); - for_each_rawref(fsck_handle_ref, NULL); + for_each_rawref(each_ref_fn_adapter, &wrapped_fsck_handle_ref); if (include_reflogs) - for_each_reflog(fsck_handle_reflog, NULL); + for_each_reflog(each_ref_fn_adapter, &wrapped_fsck_handle_reflog); /* * Not having any default heads isn't really fatal, but diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 9736d44..41bdf0a 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -305,6 +305,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) struct object_array revs = OBJECT_ARRAY_INIT; int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0; struct name_ref_data data = { 0, 0, NULL }; + struct each_ref_fn_sha1_adapter wrapped_name_ref = + {name_ref, &data}; struct option opts[] = { OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")), OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")), @@ -377,7 +379,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (cutoff) cutoff = cutoff - CUTOFF_DATE_SLOP; - for_each_ref(name_ref, &data); + for_each_ref(each_ref_fn_adapter, &wrapped_name_ref); if (transform_stdin) { char buffer[2048]; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index c067107..81f0e57 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -626,6 +626,8 @@ static struct object_entry **compute_write_order(void) struct object_entry **wo = xmalloc(to_pack.nr_objects * sizeof(*wo)); struct object_entry *objects = to_pack.objects; + struct each_ref_fn_sha1_adapter wrapped_mark_tagged = + {mark_tagged, NULL}; for (i = 0; i < to_pack.nr_objects; i++) { objects[i].tagged = 0; @@ -651,7 +653,7 @@ static struct object_entry **compute_write_order(void) /* * Mark objects that are at the tip of tags. */ - for_each_tag_ref(mark_tagged, NULL); + for_each_tag_ref(each_ref_fn_adapter, &wrapped_mark_tagged); /* * Give the objects in the original recency order until @@ -2784,8 +2786,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) argv_array_clear(&rp); } cleanup_preferred_base(); - if (include_tag && nr_result) - for_each_ref(add_ref_tag, NULL); + if (include_tag && nr_result) { + struct each_ref_fn_sha1_adapter wrapped_add_ref_tag = + {add_ref_tag, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_tag); + } stop_progress(&progress_state); if (non_empty && !nr_result) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d2ec52b..12ecacd 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -228,10 +228,13 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data) static void write_head_info(void) { struct sha1_array sa = SHA1_ARRAY_INIT; + struct each_ref_fn_sha1_adapter wrapped_show_ref_cb = + {show_ref_cb, NULL}; + for_each_alternate_ref(collect_one_alternate_ref, &sa); sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL); sha1_array_clear(&sa); - for_each_ref(show_ref_cb, NULL); + for_each_ref(each_ref_fn_adapter, &wrapped_show_ref_cb); if (!sent_capabilities) show_ref("capabilities^{}", null_sha1); diff --git a/builtin/reflog.c b/builtin/reflog.c index 8182b64..1163dd6 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -352,7 +352,10 @@ static void reflog_expiry_prepare(const char *refname, if (cb->unreachable_expire_kind != UE_ALWAYS) { if (cb->unreachable_expire_kind == UE_HEAD) { struct commit_list *elem; - for_each_ref(push_tip_to_list, &cb->tips); + struct each_ref_fn_sha1_adapter wrapped_push_tip_to_list = + {push_tip_to_list, &cb->tips}; + + for_each_ref(each_ref_fn_adapter, &wrapped_push_tip_to_list); for (elem = cb->tips; elem; elem = elem->next) commit_list_insert(elem->item, &cb->mark_list); } else { @@ -588,9 +591,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) if (do_all) { struct collect_reflog_cb collected; int i; + struct each_ref_fn_sha1_adapter wrapped_collect_reflog = + {collect_reflog, &collected}; memset(&collected, 0, sizeof(collected)); - for_each_reflog(collect_reflog, &collected); + for_each_reflog(each_ref_fn_adapter, &wrapped_collect_reflog); for (i = 0; i < collected.nr; i++) { struct collected_reflog *e = collected.e[i]; set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); diff --git a/builtin/remote.c b/builtin/remote.c index ad57fc9..27a611b 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); } diff --git a/builtin/replace.c b/builtin/replace.c index 54bf01a..bcf1508 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -66,6 +66,8 @@ static int show_reference(const char *refname, const unsigned char *sha1, static int list_replace_refs(const char *pattern, const char *format) { struct show_data data; + struct each_ref_fn_sha1_adapter wrapped_show_reference = + {show_reference, (void *) &data}; if (pattern == NULL) pattern = "*"; @@ -82,7 +84,7 @@ static int list_replace_refs(const char *pattern, const char *format) "valid formats are 'short', 'medium' and 'long'\n", format); - for_each_replace_ref(show_reference, (void *) &data); + for_each_replace_ref(each_ref_fn_adapter, &wrapped_show_reference); return 0; } diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 4d10dd9..e75ce75 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -511,6 +511,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) unsigned int flags = 0; const char *name = NULL; struct object_context unused; + struct each_ref_fn_sha1_adapter wrapped_show_reference = + {show_reference, NULL}; + struct each_ref_fn_sha1_adapter wrapped_anti_reference = + {anti_reference, NULL}; if (argc > 1 && !strcmp("--parseopt", argv[1])) return cmd_parseopt(argc - 1, argv + 1, prefix); @@ -652,7 +656,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--all")) { - for_each_ref(show_reference, NULL); + for_each_ref(each_ref_fn_adapter, &wrapped_show_reference); continue; } if (starts_with(arg, "--disambiguate=")) { @@ -660,45 +664,48 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--bisect")) { - for_each_ref_in("refs/bisect/bad", show_reference, NULL); - for_each_ref_in("refs/bisect/good", anti_reference, NULL); + for_each_ref_in("refs/bisect/bad", + each_ref_fn_adapter, &wrapped_show_reference); + for_each_ref_in("refs/bisect/good", + each_ref_fn_adapter, &wrapped_anti_reference); continue; } if (starts_with(arg, "--branches=")) { - for_each_glob_ref_in(show_reference, arg + 11, - "refs/heads/", NULL); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 11, + "refs/heads/", &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--branches")) { - for_each_branch_ref(show_reference, NULL); + for_each_branch_ref(each_ref_fn_adapter, &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--tags=")) { - for_each_glob_ref_in(show_reference, arg + 7, - "refs/tags/", NULL); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 7, + "refs/tags/", &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--tags")) { - for_each_tag_ref(show_reference, NULL); + for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--glob=")) { - for_each_glob_ref(show_reference, arg + 7, NULL); + for_each_glob_ref(each_ref_fn_adapter, arg + 7, + &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--remotes=")) { - for_each_glob_ref_in(show_reference, arg + 10, - "refs/remotes/", NULL); + for_each_glob_ref_in(each_ref_fn_adapter, arg + 10, + "refs/remotes/", &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--remotes")) { - for_each_remote_ref(show_reference, NULL); + for_each_remote_ref(each_ref_fn_adapter, &wrapped_show_reference); clear_ref_exclusion(&ref_excludes); continue; } diff --git a/builtin/show-branch.c b/builtin/show-branch.c index e69fb7c..cf918f4 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -466,12 +466,18 @@ static void snarf_refs(int head, int remotes) { if (head) { int orig_cnt = ref_name_cnt; - for_each_ref(append_head_ref, NULL); + struct each_ref_fn_sha1_adapter wrapped_append_head_ref = + {append_head_ref, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref); sort_ref_range(orig_cnt, ref_name_cnt); } if (remotes) { int orig_cnt = ref_name_cnt; - for_each_ref(append_remote_ref, NULL); + struct each_ref_fn_sha1_adapter wrapped_append_remote_ref = + {append_remote_ref, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref); sort_ref_range(orig_cnt, ref_name_cnt); } } @@ -538,9 +544,12 @@ static void append_one_rev(const char *av) if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) { /* glob style match */ int saved_matches = ref_name_cnt; + struct each_ref_fn_sha1_adapter wrapped_append_matching_ref = + {append_matching_ref, NULL}; + match_ref_pattern = av; match_ref_slash = count_slash(av); - for_each_ref(append_matching_ref, NULL); + for_each_ref(each_ref_fn_adapter, &wrapped_append_matching_ref); if (saved_matches == ref_name_cnt && ref_name_cnt < MAX_REVS) error("no matching refs with %s", av); diff --git a/builtin/show-ref.c b/builtin/show-ref.c index afb1030..8e25536 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -109,8 +109,10 @@ static int exclude_existing(const char *match) static struct string_list existing_refs = STRING_LIST_INIT_DUP; char buf[1024]; int matchlen = match ? strlen(match) : 0; + struct each_ref_fn_sha1_adapter wrapped_add_existing = + {add_existing, &existing_refs}; - for_each_ref(add_existing, &existing_refs); + for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); while (fgets(buf, sizeof(buf), stdin)) { char *ref; int len = strlen(buf); @@ -191,6 +193,9 @@ static const struct option show_ref_options[] = { int cmd_show_ref(int argc, const char **argv, const char *prefix) { + struct each_ref_fn_sha1_adapter wrapped_show_ref = + {show_ref, NULL}; + if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(show_ref_usage, show_ref_options); @@ -225,8 +230,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) } if (show_head) - head_ref(show_ref, NULL); - for_each_ref(show_ref, NULL); + head_ref(each_ref_fn_adapter, &wrapped_show_ref); + for_each_ref(each_ref_fn_adapter, &wrapped_show_ref); if (!found_match) { if (verify && !quiet) die("No match"); diff --git a/builtin/tag.c b/builtin/tag.c index 6f07ac6..7d8cd8c 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -260,6 +260,8 @@ static int list_tags(const char **patterns, int lines, struct commit_list *with_commit, int sort) { struct tag_filter filter; + struct each_ref_fn_sha1_adapter wrapped_show_reference = + {show_reference, (void *)&filter}; filter.patterns = patterns; filter.lines = lines; @@ -268,7 +270,7 @@ static int list_tags(const char **patterns, int lines, memset(&filter.tags, 0, sizeof(filter.tags)); filter.tags.strdup_strings = 1; - for_each_tag_ref(show_reference, (void *) &filter); + for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference); if (sort) { int i; if ((sort & SORT_MASK) == VERCMP_SORT) diff --git a/fetch-pack.c b/fetch-pack.c index 48526aa..5380b1b 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -256,14 +256,20 @@ static int find_common(struct fetch_pack_args *args, int got_ready = 0; struct strbuf req_buf = STRBUF_INIT; size_t state_len = 0; + struct each_ref_fn_sha1_adapter wrapped_rev_list_insert_ref = + {rev_list_insert_ref, NULL}; if (args->stateless_rpc && multi_ack == 1) die("--stateless-rpc requires multi_ack_detailed"); - if (marked) - for_each_ref(clear_marks, NULL); + if (marked) { + struct each_ref_fn_sha1_adapter wrapped_clear_marks = + {clear_marks, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_clear_marks); + } marked = 1; - for_each_ref(rev_list_insert_ref, NULL); + for_each_ref(each_ref_fn_adapter, &wrapped_rev_list_insert_ref); for_each_alternate_ref(insert_one_alternate_ref, NULL); fetching = 0; @@ -599,7 +605,10 @@ static int everything_local(struct fetch_pack_args *args, } if (!args->depth) { - for_each_ref(mark_complete, NULL); + struct each_ref_fn_sha1_adapter wrapped_mark_complete = + {mark_complete, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete); for_each_alternate_ref(mark_alternate_complete, NULL); commit_list_sort_by_date(&complete); if (cutoff) diff --git a/help.c b/help.c index 2072a87..f813093 100644 --- a/help.c +++ b/help.c @@ -425,10 +425,12 @@ static struct string_list guess_refs(const char *ref) { struct similar_ref_cb ref_cb; struct string_list similar_refs = STRING_LIST_INIT_NODUP; + struct each_ref_fn_sha1_adapter wrapped_append_similar_ref = + {append_similar_ref, &ref_cb}; ref_cb.base_ref = ref; ref_cb.similar_refs = &similar_refs; - for_each_ref(append_similar_ref, &ref_cb); + for_each_ref(each_ref_fn_adapter, &wrapped_append_similar_ref); return similar_refs; } diff --git a/http-backend.c b/http-backend.c index b6c0484..e4f3de3 100644 --- a/http-backend.c +++ b/http-backend.c @@ -395,8 +395,11 @@ static void get_info_refs(char *arg) run_service(argv); } else { + struct each_ref_fn_sha1_adapter wrapped_show_text_ref = + {show_text_ref, &buf}; + select_getanyfile(); - for_each_namespaced_ref(show_text_ref, &buf); + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_show_text_ref); send_strbuf("text/plain", &buf); } strbuf_release(&buf); @@ -425,9 +428,11 @@ static int show_head_ref(const char *refname, const unsigned char *sha1, static void get_head(char *arg) { struct strbuf buf = STRBUF_INIT; + struct each_ref_fn_sha1_adapter wrapped_show_head_ref = + {show_head_ref, &buf}; select_getanyfile(); - head_ref_namespaced(show_head_ref, &buf); + head_ref_namespaced(each_ref_fn_adapter, &wrapped_show_head_ref); send_strbuf("text/plain", &buf); strbuf_release(&buf); } diff --git a/log-tree.c b/log-tree.c index 8dba7be..1a0e170 100644 --- a/log-tree.c +++ b/log-tree.c @@ -149,10 +149,13 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) void load_ref_decorations(int flags) { if (!decoration_loaded) { + struct each_ref_fn_sha1_adapter wrapped_add_ref_decoration = + {add_ref_decoration, NULL}; + decoration_loaded = 1; decoration_flags = flags; - for_each_ref(add_ref_decoration, NULL); - head_ref(add_ref_decoration, NULL); + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration); + head_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration); for_each_commit_graft(add_graft_decoration, NULL); } } diff --git a/notes.c b/notes.c index 2be4d7f..baa1c41 100644 --- a/notes.c +++ b/notes.c @@ -932,9 +932,12 @@ static int string_list_add_one_ref(const char *refname, const unsigned char *sha */ void string_list_add_refs_by_glob(struct string_list *list, const char *glob) { + struct each_ref_fn_sha1_adapter wrapped_string_list_add_one_ref = + {string_list_add_one_ref, list}; + assert(list->strdup_strings); if (has_glob_specials(glob)) { - for_each_glob_ref(string_list_add_one_ref, glob, list); + for_each_glob_ref(each_ref_fn_adapter, glob, &wrapped_string_list_add_one_ref); } else { unsigned char sha1[20]; if (get_sha1(glob, sha1)) diff --git a/reachable.c b/reachable.c index 69fa685..acac86a 100644 --- a/reachable.c +++ b/reachable.c @@ -155,6 +155,8 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog, struct progress *progress) { struct connectivity_progress cp; + struct each_ref_fn_sha1_adapter wrapped_add_one_ref = + {add_one_ref, revs}; /* * Set up revision parsing, and mark us as being interested @@ -168,10 +170,10 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog, add_index_objects_to_pending(revs, 0); /* Add all external refs */ - for_each_ref(add_one_ref, revs); + for_each_ref(each_ref_fn_adapter, &wrapped_add_one_ref); /* detached HEAD is not included in the list above */ - head_ref(add_one_ref, revs); + head_ref(each_ref_fn_adapter, &wrapped_add_one_ref); /* Add all reflog info */ if (mark_reflog) diff --git a/refs.c b/refs.c index 9ca4651..43dce01 100644 --- a/refs.c +++ b/refs.c @@ -722,7 +722,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data) /* Store the old value, in case this is a recursive call: */ old_current_ref = current_ref; current_ref = entry; - retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash, + retval = data->fn(entry->name + data->trim, &entry->u.value.oid, entry->flag, data->cb_data); current_ref = old_current_ref; return retval; @@ -1756,13 +1756,14 @@ int ref_exists(const char *refname) return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL); } -static int filter_refs(const char *refname, const unsigned char *sha1, int flags, - void *data) +static int filter_refs(const char *refname, const struct object_id *oid, + int flags, void *data) { struct ref_filter *filter = (struct ref_filter *)data; + if (wildmatch(filter->pattern, refname, 0, NULL)) return 0; - return filter->fn(refname, sha1, flags, filter->cb_data); + return filter->fn(refname, oid, flags, filter->cb_data); } enum peel_status { @@ -1897,7 +1898,7 @@ struct warn_if_dangling_data { const char *msg_fmt; }; -static int warn_if_dangling_symref(const char *refname, const unsigned char *sha1, +static int warn_if_dangling_symref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct warn_if_dangling_data *d = cb_data; @@ -2027,18 +2028,18 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base, static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data) { - unsigned char sha1[20]; + struct object_id oid; int flag; if (submodule) { - if (resolve_gitlink_ref(submodule, "HEAD", sha1) == 0) - return fn("HEAD", sha1, 0, cb_data); + if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0) + return fn("HEAD", &oid, 0, cb_data); return 0; } - if (!read_ref_full("HEAD", RESOLVE_REF_READING, sha1, &flag)) - return fn("HEAD", sha1, flag, cb_data); + if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) + return fn("HEAD", &oid, flag, cb_data); return 0; } @@ -2113,12 +2114,12 @@ int head_ref_namespaced(each_ref_fn fn, void *cb_data) { struct strbuf buf = STRBUF_INIT; int ret = 0; - unsigned char sha1[20]; + struct object_id oid; int flag; strbuf_addf(&buf, "%sHEAD", get_git_namespace()); - if (!read_ref_full(buf.buf, RESOLVE_REF_READING, sha1, &flag)) - ret = fn(buf.buf, sha1, flag, cb_data); + if (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag)) + ret = fn(buf.buf, &oid, flag, cb_data); strbuf_release(&buf); return ret; @@ -2175,6 +2176,14 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } +int each_ref_fn_adapter(const char *refname, + const struct object_id *oid, int flags, void *cb_data) +{ + struct each_ref_fn_sha1_adapter *cb = cb_data; + + return cb->original_fn(refname, oid->hash, flags, cb->original_cb_data); +} + const char *prettify_refname(const char *name) { return name + ( @@ -3616,11 +3625,12 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data strbuf_addch(name, '/'); retval = do_for_each_reflog(name, fn, cb_data); } else { - unsigned char sha1[20]; - if (read_ref_full(name->buf, 0, sha1, NULL)) + struct object_id oid; + + if (read_ref_full(name->buf, 0, oid.hash, NULL)) retval = error("bad ref for %s", name->buf); else - retval = fn(name->buf, sha1, 0, cb_data); + retval = fn(name->buf, &oid, 0, cb_data); } if (retval) break; diff --git a/refs.h b/refs.h index 6d7d9b4..4042109 100644 --- a/refs.h +++ b/refs.h @@ -67,7 +67,18 @@ struct ref_transaction; * single callback invocation. */ typedef int each_ref_fn(const char *refname, - const unsigned char *sha1, int flags, void *cb_data); + const struct object_id *oid, int flags, void *cb_data); + +typedef int each_ref_sha1_fn(const char *refname, + const unsigned char *sha1, int flags, void *cb_data); + +struct each_ref_fn_sha1_adapter { + each_ref_sha1_fn *original_fn; + void *original_cb_data; +}; + +extern int each_ref_fn_adapter(const char *refname, + const struct object_id *oid, int flags, void *cb_data); /* * The following functions invoke the specified callback function for diff --git a/remote.c b/remote.c index 68901b0..6d66ec1 100644 --- a/remote.c +++ b/remote.c @@ -2046,7 +2046,10 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla struct ref *get_local_heads(void) { struct ref *local_refs = NULL, **local_tail = &local_refs; - for_each_ref(one_local_ref, &local_tail); + struct each_ref_fn_sha1_adapter wrapped_one_local_ref = + {one_local_ref, &local_tail}; + + for_each_ref(each_ref_fn_adapter, &wrapped_one_local_ref); return local_refs; } @@ -2141,6 +2144,9 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet struct ref *ref, *stale_refs = NULL; struct string_list ref_names = STRING_LIST_INIT_NODUP; struct stale_heads_info info; + struct each_ref_fn_sha1_adapter wrapped_get_stale_heads_cb = + {get_stale_heads_cb, &info}; + info.ref_names = &ref_names; info.stale_refs_tail = &stale_refs; info.refs = refs; @@ -2148,7 +2154,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet for (ref = fetch_map; ref; ref = ref->next) string_list_append(&ref_names, ref->name); string_list_sort(&ref_names); - for_each_ref(get_stale_heads_cb, &info); + for_each_ref(each_ref_fn_adapter, &wrapped_get_stale_heads_cb); string_list_clear(&ref_names, 0); return stale_refs; } diff --git a/replace_object.c b/replace_object.c index 0ab2dc1..a8a2da9 100644 --- a/replace_object.c +++ b/replace_object.c @@ -80,11 +80,13 @@ static int register_replace_ref(const char *refname, static void prepare_replace_object(void) { static int replace_object_prepared; + struct each_ref_fn_sha1_adapter wrapped_register_replace_ref = + {register_replace_ref, NULL}; if (replace_object_prepared) return; - for_each_replace_ref(register_replace_ref, NULL); + for_each_replace_ref(each_ref_fn_adapter, &wrapped_register_replace_ref); replace_object_prepared = 1; if (!replace_object_nr) check_replace_refs = 0; diff --git a/revision.c b/revision.c index 7ddbaa0..93b23a6 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); diff --git a/server-info.c b/server-info.c index 34b0253..317dda8 100644 --- a/server-info.c +++ b/server-info.c @@ -69,7 +69,10 @@ static int add_info_ref(const char *path, const unsigned char *sha1, int flag, v static int generate_info_refs(FILE *fp) { - return for_each_ref(add_info_ref, fp); + struct each_ref_fn_sha1_adapter wrapped_add_info_ref = + {add_info_ref, fp}; + + return for_each_ref(each_ref_fn_adapter, &wrapped_add_info_ref); } static int update_info_refs(int force) diff --git a/sha1_name.c b/sha1_name.c index 6d10f05..1aad0a3 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -1371,7 +1371,10 @@ static int get_sha1_with_context_1(const char *name, int pos; if (!only_to_die && namelen > 2 && name[1] == '/') { struct commit_list *list = NULL; - for_each_ref(handle_one_ref, &list); + struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = + {handle_one_ref, &list}; + + for_each_ref(each_ref_fn_adapter, &wrapped_handle_one_ref); commit_list_sort_by_date(&list); return get_sha1_oneline(name + 2, sha1, list); } diff --git a/shallow.c b/shallow.c index d08d264..9488edc 100644 --- a/shallow.c +++ b/shallow.c @@ -512,6 +512,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, unsigned int i, nr; int *shallow, nr_shallow = 0; struct paint_info pi; + struct each_ref_fn_sha1_adapter wrapped_mark_uninteresting = + {mark_uninteresting, NULL}; trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n"); shallow = xmalloc(sizeof(*shallow) * (info->nr_ours + info->nr_theirs)); @@ -542,8 +544,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, * connect to old refs. If not (e.g. force ref updates) it'll * have to go down to the current shallow commits. */ - head_ref(mark_uninteresting, NULL); - for_each_ref(mark_uninteresting, NULL); + head_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting); + for_each_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting); /* Mark potential bottoms so we won't go out of bound */ for (i = 0; i < nr_shallow; i++) { @@ -618,6 +620,8 @@ static void post_assign_shallow(struct shallow_info *info, int dst, i, j; int bitmap_nr = (info->ref->nr + 31) / 32; struct commit_array ca; + struct each_ref_fn_sha1_adapter wrapped_add_ref = + {add_ref, &ca}; trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n"); if (ref_status) @@ -641,8 +645,8 @@ static void post_assign_shallow(struct shallow_info *info, info->nr_theirs = dst; memset(&ca, 0, sizeof(ca)); - head_ref(add_ref, &ca); - for_each_ref(add_ref, &ca); + head_ref(each_ref_fn_adapter, &wrapped_add_ref); + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref); /* Remove unreachable shallow commits from "ours" */ for (i = dst = 0; i < info->nr_ours; i++) { @@ -674,9 +678,12 @@ int delayed_reachability_test(struct shallow_info *si, int c) if (!si->commits) { struct commit_array ca; + struct each_ref_fn_sha1_adapter wrapped_add_ref = + {add_ref, &ca}; + memset(&ca, 0, sizeof(ca)); - head_ref(add_ref, &ca); - for_each_ref(add_ref, &ca); + head_ref(each_ref_fn_adapter, &wrapped_add_ref); + for_each_ref(each_ref_fn_adapter, &wrapped_add_ref); si->commits = ca.commits; si->nr_commits = ca.nr; } diff --git a/submodule.c b/submodule.c index d491e6a..f0f34b6 100644 --- a/submodule.c +++ b/submodule.c @@ -429,10 +429,13 @@ static int has_remote(const char *refname, const unsigned char *sha1, int flags, static int submodule_needs_pushing(const char *path, const unsigned char sha1[20]) { + struct each_ref_fn_sha1_adapter wrapped_has_remote = + {has_remote, NULL}; + if (add_submodule_odb(path) || !lookup_commit_reference(sha1)) return 0; - if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { + if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) { struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL}; struct strbuf buf = STRBUF_INIT; @@ -519,10 +522,13 @@ int find_unpushed_submodules(unsigned char new_sha1[20], static int push_submodule(const char *path) { + struct each_ref_fn_sha1_adapter wrapped_has_remote = + {has_remote, NULL}; + if (add_submodule_odb(path)) return 1; - if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { + if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) { struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"push", NULL}; @@ -626,7 +632,10 @@ static int add_sha1_to_array(const char *ref, const unsigned char *sha1, void check_for_new_submodule_commits(unsigned char new_sha1[20]) { if (!initialized_fetch_ref_tips) { - for_each_ref(add_sha1_to_array, &ref_tips_before_fetch); + struct each_ref_fn_sha1_adapter wrapped_add_sha1_to_array = + {add_sha1_to_array, &ref_tips_before_fetch}; + + for_each_ref(each_ref_fn_adapter, &wrapped_add_sha1_to_array); initialized_fetch_ref_tips = 1; } diff --git a/transport.c b/transport.c index f080e93..58cb9ed 100644 --- a/transport.c +++ b/transport.c @@ -363,7 +363,10 @@ static int rsync_transport_push(struct transport *transport, strbuf_addch(&temp_dir, '/'); if (flags & TRANSPORT_PUSH_ALL) { - if (for_each_ref(write_one_ref, &temp_dir)) + struct each_ref_fn_sha1_adapter wrapped_write_one_ref = + {write_one_ref, &temp_dir}; + + if (for_each_ref(each_ref_fn_adapter, &wrapped_write_one_ref)) return -1; } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec)) return -1; diff --git a/upload-pack.c b/upload-pack.c index 745fda8..52fab23 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -761,18 +761,26 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag, static void upload_pack(void) { struct string_list symref = STRING_LIST_INIT_DUP; + struct each_ref_fn_sha1_adapter wrapped_find_symref = + {find_symref, &symref}; - head_ref_namespaced(find_symref, &symref); + head_ref_namespaced(each_ref_fn_adapter, &wrapped_find_symref); if (advertise_refs || !stateless_rpc) { + struct each_ref_fn_sha1_adapter wrapped_send_ref = + {send_ref, &symref}; + reset_timeout(); - head_ref_namespaced(send_ref, &symref); - for_each_namespaced_ref(send_ref, &symref); + head_ref_namespaced(each_ref_fn_adapter, &wrapped_send_ref); + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_send_ref); advertise_shallow_grafts(1); packet_flush(1); } else { - head_ref_namespaced(check_ref, NULL); - for_each_namespaced_ref(check_ref, NULL); + struct each_ref_fn_sha1_adapter wrapped_check_ref = + {check_ref, NULL}; + + head_ref_namespaced(each_ref_fn_adapter, &wrapped_check_ref); + for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_check_ref); } string_list_clear(&symref, 1); if (advertise_refs) diff --git a/walker.c b/walker.c index 58ffeca..bb2e0b9 100644 --- a/walker.c +++ b/walker.c @@ -269,7 +269,10 @@ int walker_fetch(struct walker *walker, int targets, char **target, } if (!walker->get_recover) { - for_each_ref(mark_complete, NULL); + struct each_ref_fn_sha1_adapter wrapped_mark_complete = + {mark_complete, NULL}; + + for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete); commit_list_sort_by_date(&complete); } -- cgit v0.10.2-6-g49f6 From e23b0368635263e59d9ca0f1186e498a57c2c079 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:29 +0000 Subject: builtin/rev-parse: rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index e75ce75..b623239 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -190,17 +190,17 @@ static int show_default(void) return 0; } -static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { if (ref_excluded(ref_excludes, refname)) return 0; - show_rev(NORMAL, sha1, refname); + show_rev(NORMAL, oid->hash, refname); return 0; } -static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - show_rev(REVERSED, sha1, refname); + show_rev(REVERSED, oid->hash, refname); return 0; } @@ -511,10 +511,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) unsigned int flags = 0; const char *name = NULL; struct object_context unused; - struct each_ref_fn_sha1_adapter wrapped_show_reference = - {show_reference, NULL}; - struct each_ref_fn_sha1_adapter wrapped_anti_reference = - {anti_reference, NULL}; if (argc > 1 && !strcmp("--parseopt", argv[1])) return cmd_parseopt(argc - 1, argv + 1, prefix); @@ -656,7 +652,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--all")) { - for_each_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_ref(show_reference, NULL); continue; } if (starts_with(arg, "--disambiguate=")) { @@ -664,48 +660,45 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--bisect")) { - for_each_ref_in("refs/bisect/bad", - each_ref_fn_adapter, &wrapped_show_reference); - for_each_ref_in("refs/bisect/good", - each_ref_fn_adapter, &wrapped_anti_reference); + for_each_ref_in("refs/bisect/bad", show_reference, NULL); + for_each_ref_in("refs/bisect/good", anti_reference, NULL); continue; } if (starts_with(arg, "--branches=")) { - for_each_glob_ref_in(each_ref_fn_adapter, arg + 11, - "refs/heads/", &wrapped_show_reference); + for_each_glob_ref_in(show_reference, arg + 11, + "refs/heads/", NULL); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--branches")) { - for_each_branch_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_branch_ref(show_reference, NULL); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--tags=")) { - for_each_glob_ref_in(each_ref_fn_adapter, arg + 7, - "refs/tags/", &wrapped_show_reference); + for_each_glob_ref_in(show_reference, arg + 7, + "refs/tags/", NULL); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--tags")) { - for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_tag_ref(show_reference, NULL); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--glob=")) { - for_each_glob_ref(each_ref_fn_adapter, arg + 7, - &wrapped_show_reference); + for_each_glob_ref(show_reference, arg + 7, NULL); clear_ref_exclusion(&ref_excludes); continue; } if (starts_with(arg, "--remotes=")) { - for_each_glob_ref_in(each_ref_fn_adapter, arg + 10, - "refs/remotes/", &wrapped_show_reference); + for_each_glob_ref_in(show_reference, arg + 10, + "refs/remotes/", NULL); clear_ref_exclusion(&ref_excludes); continue; } if (!strcmp(arg, "--remotes")) { - for_each_remote_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_remote_ref(show_reference, NULL); clear_ref_exclusion(&ref_excludes); continue; } -- cgit v0.10.2-6-g49f6 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 diff --git a/revision.c b/revision.c index 93b23a6..cfe3876 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 v0.10.2-6-g49f6 From eed2514802569f292077214d1a04bccf91b250bd Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:31 +0000 Subject: register_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 diff --git a/bisect.c b/bisect.c index 0848d91..03d5cd9 100644 --- a/bisect.c +++ b/bisect.c @@ -400,16 +400,16 @@ struct commit_list *find_bisection(struct commit_list *list, return best; } -static int register_ref(const char *refname, const unsigned char *sha1, +static int register_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { if (!strcmp(refname, "bad")) { current_bad_oid = xmalloc(sizeof(*current_bad_oid)); - hashcpy(current_bad_oid->hash, sha1); + oidcpy(current_bad_oid, oid); } else if (starts_with(refname, "good-")) { - sha1_array_append(&good_revs, sha1); + sha1_array_append(&good_revs, oid->hash); } else if (starts_with(refname, "skip-")) { - sha1_array_append(&skipped_revs, sha1); + sha1_array_append(&skipped_revs, oid->hash); } return 0; @@ -417,10 +417,7 @@ static int register_ref(const char *refname, const unsigned char *sha1, static int read_bisect_refs(void) { - struct each_ref_fn_sha1_adapter wrapped_register_ref = - {register_ref, NULL}; - - return for_each_ref_in("refs/bisect/", each_ref_fn_adapter, &wrapped_register_ref); + return for_each_ref_in("refs/bisect/", register_ref, NULL); } static void read_bisect_paths(struct argv_array *array) -- cgit v0.10.2-6-g49f6 From a55ce971857c5fcaf9d390c826de6a0e5c6a74eb Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:32 +0000 Subject: append_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 diff --git a/builtin/branch.c b/builtin/branch.c index b27adcb..0d3b9af 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -328,7 +328,7 @@ static int match_patterns(const char **pattern, const char *refname) return 0; } -static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +static int append_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data); struct ref_list *ref_list = cb->ref_list; @@ -365,7 +365,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags, commit = NULL; if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) { - commit = lookup_commit_reference_gently(sha1, 1); + commit = lookup_commit_reference_gently(oid->hash, 1); if (!commit) { cb->ret = error(_("branch '%s' does not point at a commit"), refname); return 0; @@ -631,8 +631,6 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru int i; struct append_ref_cb cb; struct ref_list ref_list; - struct each_ref_fn_sha1_adapter wrapped_append_ref = - {append_ref, &cb}; memset(&ref_list, 0, sizeof(ref_list)); ref_list.kinds = kinds; @@ -644,7 +642,7 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru cb.ref_list = &ref_list; cb.pattern = pattern; cb.ret = 0; - for_each_rawref(each_ref_fn_adapter, &wrapped_append_ref); + for_each_rawref(append_ref, &cb); if (merge_filter != NO_FILTER) { struct commit *filter; filter = lookup_commit_reference_gently(merge_filter_ref, 0); -- cgit v0.10.2-6-g49f6 From fcb615f51f303177a8454e988f8e8ef9fb3e94d9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:33 +0000 Subject: add_pending_uninteresting_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 diff --git a/builtin/checkout.c b/builtin/checkout.c index 9416aa2..9b49f0e 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -702,10 +702,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } static int add_pending_uninteresting_ref(const char *refname, - const unsigned char *sha1, + const struct object_id *oid, int flags, void *cb_data) { - add_pending_sha1(cb_data, refname, sha1, UNINTERESTING); + add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING); return 0; } @@ -784,8 +784,6 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) struct rev_info revs; struct object *object = &old->object; struct object_array refs; - struct each_ref_fn_sha1_adapter wrapped_add_pending_uninteresting_ref = - {add_pending_uninteresting_ref, &revs}; init_revisions(&revs, NULL); setup_revisions(0, NULL, &revs, NULL); @@ -793,7 +791,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) object->flags &= ~UNINTERESTING; add_pending_object(&revs, object, sha1_to_hex(object->sha1)); - for_each_ref(each_ref_fn_adapter, &wrapped_add_pending_uninteresting_ref); + for_each_ref(add_pending_uninteresting_ref, &revs); add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING); refs = revs.pending; -- cgit v0.10.2-6-g49f6 From 99a2cfbfe639ccd13e48ac48e8bd4461c9c1b178 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:34 +0000 Subject: get_name(): rewrite to take an object_id argument Rewrite to take an object_id argument and convert the local variable "peeled" object_id. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/describe.c b/builtin/describe.c index 7d0c855..a36c829 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -119,10 +119,10 @@ static void add_to_known_names(const char *path, } } -static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data) { int is_tag = starts_with(path, "refs/tags/"); - unsigned char peeled[20]; + struct object_id peeled; int is_annotated, prio; /* Reject anything outside refs/tags/ unless --all */ @@ -134,10 +134,10 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void return 0; /* Is it annotated? */ - if (!peel_ref(path, peeled)) { - is_annotated = !!hashcmp(sha1, peeled); + if (!peel_ref(path, peeled.hash)) { + is_annotated = !!oidcmp(oid, &peeled); } else { - hashcpy(peeled, sha1); + oidcpy(&peeled, oid); is_annotated = 0; } @@ -154,7 +154,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void else prio = 0; - add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1); + add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash); return 0; } @@ -413,8 +413,6 @@ int cmd_describe(int argc, const char **argv, const char *prefix) PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"}, OPT_END(), }; - struct each_ref_fn_sha1_adapter wrapped_get_name = - {get_name, NULL}; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, describe_usage, 0); @@ -453,7 +451,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) } hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0); - for_each_rawref(each_ref_fn_adapter, &wrapped_get_name); + for_each_rawref(get_name, NULL); if (!names.size && !always) die(_("No names found, cannot describe anything.")); -- cgit v0.10.2-6-g49f6 From 0e0b7de4c78427deeb58860519e6a93d4b52e3cd Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:35 +0000 Subject: builtin/fetch: rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/fetch.c b/builtin/fetch.c index 4878c3d..8d5b2db 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -179,13 +179,15 @@ static void add_merge_config(struct ref **head, } } -static int add_existing(const char *refname, const unsigned char *sha1, +static int add_existing(const char *refname, const struct object_id *oid, int flag, void *cbdata) { struct string_list *list = (struct string_list *)cbdata; struct string_list_item *item = string_list_insert(list, refname); - item->util = xmalloc(20); - hashcpy(item->util, sha1); + struct object_id *old_oid = xmalloc(sizeof(*old_oid)); + + oidcpy(old_oid, oid); + item->util = old_oid; return 0; } @@ -208,10 +210,8 @@ static void find_non_local_tags(struct transport *transport, struct string_list remote_refs = STRING_LIST_INIT_NODUP; const struct ref *ref; struct string_list_item *item = NULL; - struct each_ref_fn_sha1_adapter wrapped_add_existing = - {add_existing, &existing_refs}; - for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); + for_each_ref(add_existing, &existing_refs); for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) { if (!starts_with(ref->name, "refs/tags/")) continue; @@ -886,10 +886,8 @@ static int do_fetch(struct transport *transport, struct ref *rm; int autotags = (transport->remote->fetch_tags == 1); int retcode = 0; - struct each_ref_fn_sha1_adapter wrapped_add_existing = - {add_existing, &existing_refs}; - for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); + for_each_ref(add_existing, &existing_refs); if (tags == TAGS_DEFAULT) { if (transport->remote->fetch_tags == 2) @@ -917,9 +915,10 @@ static int do_fetch(struct transport *transport, struct string_list_item *peer_item = string_list_lookup(&existing_refs, rm->peer_ref->name); - if (peer_item) - hashcpy(rm->peer_ref->old_sha1, - peer_item->util); + if (peer_item) { + struct object_id *old_oid = peer_item->util; + hashcpy(rm->peer_ref->old_sha1, old_oid->hash); + } } } -- cgit v0.10.2-6-g49f6 From 30a3fd40500c31a74ebab808d741d2fc6c449a29 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:36 +0000 Subject: grab_single_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 diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index caccd93..05ce28c 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -840,7 +840,8 @@ struct grab_ref_cbdata { * A call-back given to for_each_ref(). Filter refs and keep them for * later object processing. */ -static int grab_single_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int grab_single_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { struct grab_ref_cbdata *cb = cb_data; struct refinfo *ref; @@ -878,7 +879,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f */ ref = xcalloc(1, sizeof(*ref)); ref->refname = xstrdup(refname); - hashcpy(ref->objectname, sha1); + hashcpy(ref->objectname, oid->hash); ref->flag = flag; cnt = cb->grab_cnt; @@ -1072,8 +1073,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) int maxcount = 0, quote_style = 0; struct refinfo **refs; struct grab_ref_cbdata cbdata; - struct each_ref_fn_sha1_adapter wrapped_grab_single_ref = - {grab_single_ref, &cbdata}; struct option opts[] = { OPT_BIT('s', "shell", "e_style, @@ -1113,7 +1112,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) memset(&cbdata, 0, sizeof(cbdata)); cbdata.grab_pattern = argv; - for_each_rawref(each_ref_fn_adapter, &wrapped_grab_single_ref); + for_each_rawref(grab_single_ref, &cbdata); refs = cbdata.grab_array; num_refs = cbdata.grab_cnt; -- cgit v0.10.2-6-g49f6 From 73868486f0ef6c5572681913fc2d204f12846bc5 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:37 +0000 Subject: name_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 diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 41bdf0a..248a3eb 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -138,9 +138,9 @@ static int tipcmp(const void *a_, const void *b_) return hashcmp(a->sha1, b->sha1); } -static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data) +static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data) { - struct object *o = parse_object(sha1); + struct object *o = parse_object(oid->hash); struct name_ref_data *data = cb_data; int can_abbreviate_output = data->tags_only && data->name_only; int deref = 0; @@ -160,7 +160,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void } } - add_to_tip_table(sha1, path, can_abbreviate_output); + add_to_tip_table(oid->hash, path, can_abbreviate_output); while (o && o->type == OBJ_TAG) { struct tag *t = (struct tag *) o; @@ -305,8 +305,6 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) struct object_array revs = OBJECT_ARRAY_INIT; int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0; struct name_ref_data data = { 0, 0, NULL }; - struct each_ref_fn_sha1_adapter wrapped_name_ref = - {name_ref, &data}; struct option opts[] = { OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")), OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")), @@ -379,7 +377,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) if (cutoff) cutoff = cutoff - CUTOFF_DATE_SLOP; - for_each_ref(each_ref_fn_adapter, &wrapped_name_ref); + for_each_ref(name_ref, &data); if (transform_stdin) { char buffer[2048]; -- cgit v0.10.2-6-g49f6 From d155254c73cfa5cbd82e8ad97840e4c9dbf762b0 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:38 +0000 Subject: builtin/pack-objects: rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 81f0e57..80fe8c7 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -540,11 +540,11 @@ static enum write_one_status write_one(struct sha1file *f, return WRITE_ONE_WRITTEN; } -static int mark_tagged(const char *path, const unsigned char *sha1, int flag, +static int mark_tagged(const char *path, const struct object_id *oid, int flag, void *cb_data) { unsigned char peeled[20]; - struct object_entry *entry = packlist_find(&to_pack, sha1, NULL); + struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL); if (entry) entry->tagged = 1; @@ -626,8 +626,6 @@ static struct object_entry **compute_write_order(void) struct object_entry **wo = xmalloc(to_pack.nr_objects * sizeof(*wo)); struct object_entry *objects = to_pack.objects; - struct each_ref_fn_sha1_adapter wrapped_mark_tagged = - {mark_tagged, NULL}; for (i = 0; i < to_pack.nr_objects; i++) { objects[i].tagged = 0; @@ -653,7 +651,7 @@ static struct object_entry **compute_write_order(void) /* * Mark objects that are at the tip of tags. */ - for_each_tag_ref(each_ref_fn_adapter, &wrapped_mark_tagged); + for_each_tag_ref(mark_tagged, NULL); /* * Give the objects in the original recency order until @@ -2099,14 +2097,14 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, #define ll_find_deltas(l, s, w, d, p) find_deltas(l, &s, w, d, p) #endif -static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data) { - unsigned char peeled[20]; + struct object_id peeled; if (starts_with(path, "refs/tags/") && /* is a tag? */ - !peel_ref(path, peeled) && /* peelable? */ - packlist_find(&to_pack, peeled, NULL)) /* object packed? */ - add_object_entry(sha1, OBJ_TAG, NULL, 0); + !peel_ref(path, peeled.hash) && /* peelable? */ + packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */ + add_object_entry(oid->hash, OBJ_TAG, NULL, 0); return 0; } @@ -2786,12 +2784,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) argv_array_clear(&rp); } cleanup_preferred_base(); - if (include_tag && nr_result) { - struct each_ref_fn_sha1_adapter wrapped_add_ref_tag = - {add_ref_tag, NULL}; - - for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_tag); - } + if (include_tag && nr_result) + for_each_ref(add_ref_tag, NULL); stop_progress(&progress_state); if (non_empty && !nr_result) -- cgit v0.10.2-6-g49f6 From ce2a9873297e30ad9514627bc90800280226dfd4 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:39 +0000 Subject: show_ref_cb(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 12ecacd..94d0571 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -197,7 +197,7 @@ static void show_ref(const char *path, const unsigned char *sha1) } } -static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused) +static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused) { path = strip_namespace(path); /* @@ -210,7 +210,7 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo */ if (!path) path = ".have"; - show_ref(path, sha1); + show_ref(path, oid->hash); return 0; } @@ -228,13 +228,11 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data) static void write_head_info(void) { struct sha1_array sa = SHA1_ARRAY_INIT; - struct each_ref_fn_sha1_adapter wrapped_show_ref_cb = - {show_ref_cb, NULL}; for_each_alternate_ref(collect_one_alternate_ref, &sa); sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL); sha1_array_clear(&sa); - for_each_ref(each_ref_fn_adapter, &wrapped_show_ref_cb); + for_each_ref(show_ref_cb, NULL); if (!sent_capabilities) show_ref("capabilities^{}", null_sha1); -- cgit v0.10.2-6-g49f6 From 5bcad1bce2a2ce20a7d1a24842a2f66be4507b6b Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:40 +0000 Subject: builtin/reflog: rewrite ref functions to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/reflog.c b/builtin/reflog.c index 1163dd6..c2eb8ff 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -313,14 +313,14 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, return 0; } -static int push_tip_to_list(const char *refname, const unsigned char *sha1, +static int push_tip_to_list(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct commit_list **list = cb_data; struct commit *tip_commit; if (flags & REF_ISSYMREF) return 0; - tip_commit = lookup_commit_reference_gently(sha1, 1); + tip_commit = lookup_commit_reference_gently(oid->hash, 1); if (!tip_commit) return 0; commit_list_insert(tip_commit, list); @@ -352,10 +352,8 @@ static void reflog_expiry_prepare(const char *refname, if (cb->unreachable_expire_kind != UE_ALWAYS) { if (cb->unreachable_expire_kind == UE_HEAD) { struct commit_list *elem; - struct each_ref_fn_sha1_adapter wrapped_push_tip_to_list = - {push_tip_to_list, &cb->tips}; - for_each_ref(each_ref_fn_adapter, &wrapped_push_tip_to_list); + for_each_ref(push_tip_to_list, &cb->tips); for (elem = cb->tips; elem; elem = elem->next) commit_list_insert(elem->item, &cb->mark_list); } else { @@ -382,14 +380,14 @@ static void reflog_expiry_cleanup(void *cb_data) } } -static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data) +static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data) { struct collected_reflog *e; struct collect_reflog_cb *cb = cb_data; size_t namelen = strlen(ref); e = xmalloc(sizeof(*e) + namelen + 1); - hashcpy(e->sha1, sha1); + hashcpy(e->sha1, oid->hash); memcpy(e->reflog, ref, namelen + 1); ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc); cb->e[cb->nr++] = e; @@ -591,11 +589,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) if (do_all) { struct collect_reflog_cb collected; int i; - struct each_ref_fn_sha1_adapter wrapped_collect_reflog = - {collect_reflog, &collected}; memset(&collected, 0, sizeof(collected)); - for_each_reflog(each_ref_fn_adapter, &wrapped_collect_reflog); + for_each_reflog(collect_reflog, &collected); for (i = 0; i < collected.nr; i++) { struct collected_reflog *e = collected.e[i]; set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); -- cgit v0.10.2-6-g49f6 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 diff --git a/builtin/remote.c b/builtin/remote.c index 27a611b..1986e98 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 v0.10.2-6-g49f6 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 diff --git a/builtin/remote.c b/builtin/remote.c index 1986e98..ab39fea 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 v0.10.2-6-g49f6 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 diff --git a/builtin/remote.c b/builtin/remote.c index ab39fea..f4a6ec9 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 v0.10.2-6-g49f6 From d70d7a8a4d1e985dea02713a3b1fda3a08d4325e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:44 +0000 Subject: show_reference(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/replace.c b/builtin/replace.c index bcf1508..0d52e7f 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -35,7 +35,7 @@ struct show_data { enum replace_format format; }; -static int show_reference(const char *refname, const unsigned char *sha1, +static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { struct show_data *data = cb_data; @@ -44,19 +44,19 @@ static int show_reference(const char *refname, const unsigned char *sha1, if (data->format == REPLACE_FORMAT_SHORT) printf("%s\n", refname); else if (data->format == REPLACE_FORMAT_MEDIUM) - printf("%s -> %s\n", refname, sha1_to_hex(sha1)); + printf("%s -> %s\n", refname, oid_to_hex(oid)); else { /* data->format == REPLACE_FORMAT_LONG */ - unsigned char object[20]; + struct object_id object; enum object_type obj_type, repl_type; - if (get_sha1(refname, object)) + if (get_sha1(refname, object.hash)) return error("Failed to resolve '%s' as a valid ref.", refname); - obj_type = sha1_object_info(object, NULL); - repl_type = sha1_object_info(sha1, NULL); + obj_type = sha1_object_info(object.hash, NULL); + repl_type = sha1_object_info(oid->hash, NULL); printf("%s (%s) -> %s (%s)\n", refname, typename(obj_type), - sha1_to_hex(sha1), typename(repl_type)); + oid_to_hex(oid), typename(repl_type)); } } @@ -66,8 +66,6 @@ static int show_reference(const char *refname, const unsigned char *sha1, static int list_replace_refs(const char *pattern, const char *format) { struct show_data data; - struct each_ref_fn_sha1_adapter wrapped_show_reference = - {show_reference, (void *) &data}; if (pattern == NULL) pattern = "*"; @@ -84,7 +82,7 @@ static int list_replace_refs(const char *pattern, const char *format) "valid formats are 'short', 'medium' and 'long'\n", format); - for_each_replace_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_replace_ref(show_reference, (void *)&data); return 0; } -- cgit v0.10.2-6-g49f6 From a00595fbd2cbe16d48a50fd7b9bcd417d062e6d4 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:45 +0000 Subject: append_matching_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 diff --git a/builtin/show-branch.c b/builtin/show-branch.c index cf918f4..b06f966 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -440,7 +440,8 @@ static int count_slash(const char *s) return cnt; } -static int append_matching_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int append_matching_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { /* we want to allow pattern hold/ to show all * branches under refs/heads/hold/, and v0.99.9? to show @@ -456,10 +457,10 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i if (wildmatch(match_ref_pattern, tail, 0, NULL)) return 0; if (starts_with(refname, "refs/heads/")) - return append_head_ref(refname, sha1, flag, cb_data); + return append_head_ref(refname, oid->hash, flag, cb_data); if (starts_with(refname, "refs/tags/")) - return append_tag_ref(refname, sha1, flag, cb_data); - return append_ref(refname, sha1, 0); + return append_tag_ref(refname, oid->hash, flag, cb_data); + return append_ref(refname, oid->hash, 0); } static void snarf_refs(int head, int remotes) @@ -544,12 +545,10 @@ static void append_one_rev(const char *av) if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) { /* glob style match */ int saved_matches = ref_name_cnt; - struct each_ref_fn_sha1_adapter wrapped_append_matching_ref = - {append_matching_ref, NULL}; match_ref_pattern = av; match_ref_slash = count_slash(av); - for_each_ref(each_ref_fn_adapter, &wrapped_append_matching_ref); + for_each_ref(append_matching_ref, NULL); if (saved_matches == ref_name_cnt && ref_name_cnt < MAX_REVS) error("no matching refs with %s", av); -- cgit v0.10.2-6-g49f6 From 2e253a4a12a63e7c3e807e555641539dd19ae2fa Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:46 +0000 Subject: builtin/show-branch: rewrite functions to take object_id arguments Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-branch.c b/builtin/show-branch.c index b06f966..7e00657 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -394,39 +394,42 @@ static int append_ref(const char *refname, const unsigned char *sha1, return 0; } -static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int append_head_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { - unsigned char tmp[20]; + struct object_id tmp; int ofs = 11; if (!starts_with(refname, "refs/heads/")) return 0; /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. */ - if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1)) + if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) ofs = 5; - return append_ref(refname + ofs, sha1, 0); + return append_ref(refname + ofs, oid->hash, 0); } -static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int append_remote_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { - unsigned char tmp[20]; + struct object_id tmp; int ofs = 13; if (!starts_with(refname, "refs/remotes/")) return 0; /* If both heads/foo and tags/foo exists, get_sha1 would * get confused. */ - if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1)) + if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) ofs = 5; - return append_ref(refname + ofs, sha1, 0); + return append_ref(refname + ofs, oid->hash, 0); } -static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int append_tag_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { if (!starts_with(refname, "refs/tags/")) return 0; - return append_ref(refname + 5, sha1, 0); + return append_ref(refname + 5, oid->hash, 0); } static const char *match_ref_pattern = NULL; @@ -457,9 +460,9 @@ static int append_matching_ref(const char *refname, const struct object_id *oid, if (wildmatch(match_ref_pattern, tail, 0, NULL)) return 0; if (starts_with(refname, "refs/heads/")) - return append_head_ref(refname, oid->hash, flag, cb_data); + return append_head_ref(refname, oid, flag, cb_data); if (starts_with(refname, "refs/tags/")) - return append_tag_ref(refname, oid->hash, flag, cb_data); + return append_tag_ref(refname, oid, flag, cb_data); return append_ref(refname, oid->hash, 0); } @@ -467,18 +470,14 @@ static void snarf_refs(int head, int remotes) { if (head) { int orig_cnt = ref_name_cnt; - struct each_ref_fn_sha1_adapter wrapped_append_head_ref = - {append_head_ref, NULL}; - for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref); + for_each_ref(append_head_ref, NULL); sort_ref_range(orig_cnt, ref_name_cnt); } if (remotes) { int orig_cnt = ref_name_cnt; - struct each_ref_fn_sha1_adapter wrapped_append_remote_ref = - {append_remote_ref, NULL}; - for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref); + for_each_ref(append_remote_ref, NULL); sort_ref_range(orig_cnt, ref_name_cnt); } } -- cgit v0.10.2-6-g49f6 From 7a456c1eea83b7589b9f37fd56f53719ab431b86 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:47 +0000 Subject: append_one_rev(): rewrite to work with object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 7e00657..b861e41 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -536,9 +536,9 @@ static int show_independent(struct commit **rev, static void append_one_rev(const char *av) { - unsigned char revkey[20]; - if (!get_sha1(av, revkey)) { - append_ref(av, revkey, 0); + struct object_id revkey; + if (!get_sha1(av, revkey.hash)) { + append_ref(av, revkey.hash, 0); return; } if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) { -- cgit v0.10.2-6-g49f6 From d1516bf4629cf2b4382a307ea0b3d7c26d2bfdca Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:48 +0000 Subject: builtin/show-branch: rewrite functions to work with object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-branch.c b/builtin/show-branch.c index b861e41..826d9fa 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -369,10 +369,10 @@ static void sort_ref_range(int bottom, int top) compare_ref_name); } -static int append_ref(const char *refname, const unsigned char *sha1, +static int append_ref(const char *refname, const struct object_id *oid, int allow_dups) { - struct commit *commit = lookup_commit_reference_gently(sha1, 1); + struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); int i; if (!commit) @@ -406,7 +406,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid, */ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) ofs = 5; - return append_ref(refname + ofs, oid->hash, 0); + return append_ref(refname + ofs, oid, 0); } static int append_remote_ref(const char *refname, const struct object_id *oid, @@ -421,7 +421,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid, */ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid)) ofs = 5; - return append_ref(refname + ofs, oid->hash, 0); + return append_ref(refname + ofs, oid, 0); } static int append_tag_ref(const char *refname, const struct object_id *oid, @@ -429,7 +429,7 @@ static int append_tag_ref(const char *refname, const struct object_id *oid, { if (!starts_with(refname, "refs/tags/")) return 0; - return append_ref(refname + 5, oid->hash, 0); + return append_ref(refname + 5, oid, 0); } static const char *match_ref_pattern = NULL; @@ -463,7 +463,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid, return append_head_ref(refname, oid, flag, cb_data); if (starts_with(refname, "refs/tags/")) return append_tag_ref(refname, oid, flag, cb_data); - return append_ref(refname, oid->hash, 0); + return append_ref(refname, oid, 0); } static void snarf_refs(int head, int remotes) @@ -538,7 +538,7 @@ static void append_one_rev(const char *av) { struct object_id revkey; if (!get_sha1(av, revkey.hash)) { - append_ref(av, revkey.hash, 0); + append_ref(av, &revkey, 0); return; } if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) { @@ -643,7 +643,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) char head[128]; const char *head_p; int head_len; - unsigned char head_sha1[20]; + struct object_id head_oid; int merge_base = 0; int independent = 0; int no_name = 0; @@ -729,7 +729,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) all_heads = 1; if (reflog) { - unsigned char sha1[20]; + struct object_id oid; char nth_desc[256]; char *ref; int base = 0; @@ -740,7 +740,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) fake_av[0] = resolve_refdup("HEAD", RESOLVE_REF_READING, - sha1, NULL); + oid.hash, NULL); fake_av[1] = NULL; av = fake_av; ac = 1; @@ -751,7 +751,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (MAX_REVS < reflog) die("Only %d entries can be shown at one time.", MAX_REVS); - if (!dwim_ref(*av, strlen(*av), sha1, &ref)) + if (!dwim_ref(*av, strlen(*av), oid.hash, &ref)) die("No such ref %s", *av); /* Has the base been specified? */ @@ -762,7 +762,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) /* Ah, that is a date spec... */ unsigned long at; at = approxidate(reflog_base); - read_ref_at(ref, flags, at, -1, sha1, NULL, + read_ref_at(ref, flags, at, -1, oid.hash, NULL, NULL, NULL, &base); } } @@ -773,7 +773,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) unsigned long timestamp; int tz; - if (read_ref_at(ref, flags, 0, base+i, sha1, &logmsg, + if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg, ×tamp, &tz, NULL)) { reflog = i; break; @@ -788,7 +788,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) msg); free(logmsg); sprintf(nth_desc, "%s@{%d}", *av, base+i); - append_ref(nth_desc, sha1, 1); + append_ref(nth_desc, &oid, 1); } free(ref); } @@ -802,7 +802,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) } head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, - head_sha1, NULL); + head_oid.hash, NULL); if (head_p) { head_len = strlen(head_p); memcpy(head, head_p, head_len + 1); @@ -821,7 +821,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (rev_is_head(head, head_len, ref_name[i], - head_sha1, NULL)) + head_oid.hash, NULL)) has_head++; } if (!has_head) { @@ -836,17 +836,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) } for (num_rev = 0; ref_name[num_rev]; num_rev++) { - unsigned char revkey[20]; + struct object_id revkey; unsigned int flag = 1u << (num_rev + REV_SHIFT); if (MAX_REVS <= num_rev) die("cannot handle more than %d revs.", MAX_REVS); - if (get_sha1(ref_name[num_rev], revkey)) + if (get_sha1(ref_name[num_rev], revkey.hash)) die("'%s' is not a valid ref.", ref_name[num_rev]); - commit = lookup_commit_reference(revkey); + commit = lookup_commit_reference(revkey.hash); if (!commit) die("cannot find commit %s (%s)", - ref_name[num_rev], revkey); + ref_name[num_rev], revkey.hash); parse_commit(commit); mark_seen(commit, &seen); @@ -880,7 +880,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) int is_head = rev_is_head(head, head_len, ref_name[i], - head_sha1, + head_oid.hash, rev[i]->object.sha1); if (extra < 0) printf("%c [%s] ", -- cgit v0.10.2-6-g49f6 From 96062b576224cfad55a1cb03c6fbe1c0bc16f722 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:49 +0000 Subject: cmd_show_branch(): fix error message We need to convert the SHA-1 to hexadecimal before printing it. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 826d9fa..323f857 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -846,7 +846,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) commit = lookup_commit_reference(revkey.hash); if (!commit) die("cannot find commit %s (%s)", - ref_name[num_rev], revkey.hash); + ref_name[num_rev], oid_to_hex(&revkey)); parse_commit(commit); mark_seen(commit, &seen); -- cgit v0.10.2-6-g49f6 From 635b99a0c715c87fe535b9174a453c2deec4566f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:50 +0000 Subject: fsck: change functions to use object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/fsck.c b/builtin/fsck.c index 48d0c2e..4e8e2ee 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -25,7 +25,7 @@ static int include_reflogs = 1; static int check_full = 1; static int check_strict; static int keep_cache_objects; -static unsigned char head_sha1[20]; +static struct object_id head_oid; static const char *head_points_at; static int errors_found; static int write_lost_and_found; @@ -476,19 +476,21 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1, return 0; } -static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data) +static int fsck_handle_reflog(const char *logname, const struct object_id *oid, + int flag, void *cb_data) { for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL); return 0; } -static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int fsck_handle_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { struct object *obj; - obj = parse_object(sha1); + obj = parse_object(oid->hash); if (!obj) { - error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1)); + error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid)); errors_found |= ERROR_REACHABLE; /* We'll continue with the rest despite the error.. */ return 0; @@ -504,16 +506,11 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f static void get_default_heads(void) { - struct each_ref_fn_sha1_adapter wrapped_fsck_handle_ref = - {fsck_handle_ref, NULL}; - struct each_ref_fn_sha1_adapter wrapped_fsck_handle_reflog = - {fsck_handle_reflog, NULL}; - - if (head_points_at && !is_null_sha1(head_sha1)) - fsck_handle_ref("HEAD", head_sha1, 0, NULL); - for_each_rawref(each_ref_fn_adapter, &wrapped_fsck_handle_ref); + if (head_points_at && !is_null_oid(&head_oid)) + fsck_handle_ref("HEAD", &head_oid, 0, NULL); + for_each_rawref(fsck_handle_ref, NULL); if (include_reflogs) - for_each_reflog(each_ref_fn_adapter, &wrapped_fsck_handle_reflog); + for_each_reflog(fsck_handle_reflog, NULL); /* * Not having any default heads isn't really fatal, but @@ -561,7 +558,7 @@ static int fsck_head_link(void) if (verbose) fprintf(stderr, "Checking HEAD link\n"); - head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag); + head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, &flag); if (!head_points_at) return error("Invalid HEAD"); if (!strcmp(head_points_at, "HEAD")) @@ -570,7 +567,7 @@ static int fsck_head_link(void) else if (!starts_with(head_points_at, "refs/heads/")) return error("HEAD points to something strange (%s)", head_points_at); - if (is_null_sha1(head_sha1)) { + if (is_null_oid(&head_oid)) { if (null_is_error) return error("HEAD: detached HEAD points at nothing"); fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n", -- cgit v0.10.2-6-g49f6 From f0a011fa1f3030e49de9f316b02119b390c33e92 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:51 +0000 Subject: builtin/show-ref: rewrite to use object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 8e25536..18f84fb 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -17,16 +17,17 @@ static int deref_tags, show_head, tags_only, heads_only, found_match, verify, static const char **pattern; static const char *exclude_existing_arg; -static void show_one(const char *refname, const unsigned char *sha1) +static void show_one(const char *refname, const struct object_id *oid) { - const char *hex = find_unique_abbrev(sha1, abbrev); + const char *hex = find_unique_abbrev(oid->hash, abbrev); if (hash_only) printf("%s\n", hex); else printf("%s %s\n", hex, refname); } -static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata) +static int show_ref(const char *refname, const struct object_id *oid, + int flag, void *cbdata) { const char *hex; unsigned char peeled[20]; @@ -69,14 +70,14 @@ match: * detect and return error if the repository is corrupt and * ref points at a nonexistent object. */ - if (!has_sha1_file(sha1)) + if (!has_sha1_file(oid->hash)) die("git show-ref: bad ref %s (%s)", refname, - sha1_to_hex(sha1)); + oid_to_hex(oid)); if (quiet) return 0; - show_one(refname, sha1); + show_one(refname, oid); if (!deref_tags) return 0; @@ -88,7 +89,8 @@ match: return 0; } -static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata) +static int add_existing(const char *refname, const struct object_id *oid, + int flag, void *cbdata) { struct string_list *list = (struct string_list *)cbdata; string_list_insert(list, refname); @@ -109,10 +111,8 @@ static int exclude_existing(const char *match) static struct string_list existing_refs = STRING_LIST_INIT_DUP; char buf[1024]; int matchlen = match ? strlen(match) : 0; - struct each_ref_fn_sha1_adapter wrapped_add_existing = - {add_existing, &existing_refs}; - for_each_ref(each_ref_fn_adapter, &wrapped_add_existing); + for_each_ref(add_existing, &existing_refs); while (fgets(buf, sizeof(buf), stdin)) { char *ref; int len = strlen(buf); @@ -193,9 +193,6 @@ static const struct option show_ref_options[] = { int cmd_show_ref(int argc, const char **argv, const char *prefix) { - struct each_ref_fn_sha1_adapter wrapped_show_ref = - {show_ref, NULL}; - if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(show_ref_usage, show_ref_options); @@ -213,12 +210,12 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) if (!pattern) die("--verify requires a reference"); while (*pattern) { - unsigned char sha1[20]; + struct object_id oid; if (starts_with(*pattern, "refs/") && - !read_ref(*pattern, sha1)) { + !read_ref(*pattern, oid.hash)) { if (!quiet) - show_one(*pattern, sha1); + show_one(*pattern, &oid); } else if (!quiet) die("'%s' - not a valid ref", *pattern); @@ -230,8 +227,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) } if (show_head) - head_ref(each_ref_fn_adapter, &wrapped_show_ref); - for_each_ref(each_ref_fn_adapter, &wrapped_show_ref); + head_ref(show_ref, NULL); + for_each_ref(show_ref, NULL); if (!found_match) { if (verify && !quiet) die("No match"); -- cgit v0.10.2-6-g49f6 From a0cde90ebfe22d879fd9c272afdef9301ca8b51d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:52 +0000 Subject: show_ref(): convert local variable peeled to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 18f84fb..dfbc314 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -30,7 +30,7 @@ static int show_ref(const char *refname, const struct object_id *oid, int flag, void *cbdata) { const char *hex; - unsigned char peeled[20]; + struct object_id peeled; if (show_head && !strcmp(refname, "HEAD")) goto match; @@ -82,8 +82,8 @@ match: if (!deref_tags) return 0; - if (!peel_ref(refname, peeled)) { - hex = find_unique_abbrev(peeled, abbrev); + if (!peel_ref(refname, peeled.hash)) { + hex = find_unique_abbrev(peeled.hash, abbrev); printf("%s %s^{}\n", hex, refname); } return 0; -- cgit v0.10.2-6-g49f6 From 6c4461e8d9d9f04920c53d98da9c4ed3bc42a237 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:53 +0000 Subject: builtin/show-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 diff --git a/builtin/tag.c b/builtin/tag.c index 7d8cd8c..5f6cdc5 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -176,7 +176,7 @@ static enum contains_result contains(struct commit *candidate, return contains_test(candidate, want); } -static void show_tag_lines(const unsigned char *sha1, int lines) +static void show_tag_lines(const struct object_id *oid, int lines) { int i; unsigned long size; @@ -184,14 +184,14 @@ static void show_tag_lines(const unsigned char *sha1, int lines) char *buf, *sp, *eol; size_t len; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); if (!buf) - die_errno("unable to read object %s", sha1_to_hex(sha1)); + die_errno("unable to read object %s", oid_to_hex(oid)); if (type != OBJ_COMMIT && type != OBJ_TAG) goto free_return; if (!size) die("an empty %s object %s?", - typename(type), sha1_to_hex(sha1)); + typename(type), oid_to_hex(oid)); /* skip header */ sp = strstr(buf, "\n\n"); @@ -215,7 +215,7 @@ free_return: free(buf); } -static int show_reference(const char *refname, const unsigned char *sha1, +static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { struct tag_filter *filter = cb_data; @@ -224,14 +224,14 @@ static int show_reference(const char *refname, const unsigned char *sha1, if (filter->with_commit) { struct commit *commit; - commit = lookup_commit_reference_gently(sha1, 1); + commit = lookup_commit_reference_gently(oid->hash, 1); if (!commit) return 0; if (!contains(commit, filter->with_commit)) return 0; } - if (points_at.nr && !match_points_at(refname, sha1)) + if (points_at.nr && !match_points_at(refname, oid->hash)) return 0; if (!filter->lines) { @@ -242,7 +242,7 @@ static int show_reference(const char *refname, const unsigned char *sha1, return 0; } printf("%-15s ", refname); - show_tag_lines(sha1, filter->lines); + show_tag_lines(oid, filter->lines); putchar('\n'); } @@ -260,8 +260,6 @@ static int list_tags(const char **patterns, int lines, struct commit_list *with_commit, int sort) { struct tag_filter filter; - struct each_ref_fn_sha1_adapter wrapped_show_reference = - {show_reference, (void *)&filter}; filter.patterns = patterns; filter.lines = lines; @@ -270,7 +268,7 @@ static int list_tags(const char **patterns, int lines, memset(&filter.tags, 0, sizeof(filter.tags)); filter.tags.strdup_strings = 1; - for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference); + for_each_tag_ref(show_reference, (void *)&filter); if (sort) { int i; if ((sort & SORT_MASK) == VERCMP_SORT) -- cgit v0.10.2-6-g49f6 From 91d6e94ea6238f6678718c53b8aaef733c7b5a05 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:54 +0000 Subject: append_similar_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 diff --git a/help.c b/help.c index f813093..6f3415b 100644 --- a/help.c +++ b/help.c @@ -407,7 +407,7 @@ struct similar_ref_cb { struct string_list *similar_refs; }; -static int append_similar_ref(const char *refname, const unsigned char *sha1, +static int append_similar_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data); @@ -425,12 +425,10 @@ static struct string_list guess_refs(const char *ref) { struct similar_ref_cb ref_cb; struct string_list similar_refs = STRING_LIST_INIT_NODUP; - struct each_ref_fn_sha1_adapter wrapped_append_similar_ref = - {append_similar_ref, &ref_cb}; ref_cb.base_ref = ref; ref_cb.similar_refs = &similar_refs; - for_each_ref(each_ref_fn_adapter, &wrapped_append_similar_ref); + for_each_ref(append_similar_ref, &ref_cb); return similar_refs; } -- cgit v0.10.2-6-g49f6 From f72f54210728a3550fa314e99470dcbbef001297 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:55 +0000 Subject: http-backend: rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/http-backend.c b/http-backend.c index e4f3de3..a2d388d 100644 --- a/http-backend.c +++ b/http-backend.c @@ -350,16 +350,16 @@ static void run_service(const char **argv) exit(1); } -static int show_text_ref(const char *name, const unsigned char *sha1, - int flag, void *cb_data) +static int show_text_ref(const char *name, const struct object_id *oid, + int flag, void *cb_data) { const char *name_nons = strip_namespace(name); struct strbuf *buf = cb_data; - struct object *o = parse_object(sha1); + struct object *o = parse_object(oid->hash); if (!o) return 0; - strbuf_addf(buf, "%s\t%s\n", sha1_to_hex(sha1), name_nons); + strbuf_addf(buf, "%s\t%s\n", oid_to_hex(oid), name_nons); if (o->type == OBJ_TAG) { o = deref_tag(o, name, 0); if (!o) @@ -395,18 +395,15 @@ static void get_info_refs(char *arg) run_service(argv); } else { - struct each_ref_fn_sha1_adapter wrapped_show_text_ref = - {show_text_ref, &buf}; - select_getanyfile(); - for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_show_text_ref); + for_each_namespaced_ref(show_text_ref, &buf); send_strbuf("text/plain", &buf); } strbuf_release(&buf); } -static int show_head_ref(const char *refname, const unsigned char *sha1, - int flag, void *cb_data) +static int show_head_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { struct strbuf *buf = cb_data; @@ -419,7 +416,7 @@ static int show_head_ref(const char *refname, const unsigned char *sha1, strbuf_addf(buf, "ref: %s\n", target_nons); } else { - strbuf_addf(buf, "%s\n", sha1_to_hex(sha1)); + strbuf_addf(buf, "%s\n", oid_to_hex(oid)); } return 0; @@ -428,11 +425,9 @@ static int show_head_ref(const char *refname, const unsigned char *sha1, static void get_head(char *arg) { struct strbuf buf = STRBUF_INIT; - struct each_ref_fn_sha1_adapter wrapped_show_head_ref = - {show_head_ref, &buf}; select_getanyfile(); - head_ref_namespaced(each_ref_fn_adapter, &wrapped_show_head_ref); + head_ref_namespaced(show_head_ref, &buf); send_strbuf("text/plain", &buf); strbuf_release(&buf); } -- cgit v0.10.2-6-g49f6 From 5f9cf5abd2f918d374d11a0f468bc2387a3d32c2 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:56 +0000 Subject: show_head_ref(): convert local variable "unused" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/http-backend.c b/http-backend.c index a2d388d..55353ad 100644 --- a/http-backend.c +++ b/http-backend.c @@ -408,10 +408,10 @@ static int show_head_ref(const char *refname, const struct object_id *oid, struct strbuf *buf = cb_data; if (flag & REF_ISSYMREF) { - unsigned char unused[20]; + struct object_id unused; const char *target = resolve_ref_unsafe(refname, RESOLVE_REF_READING, - unused, NULL); + unused.hash, NULL); const char *target_nons = strip_namespace(target); strbuf_addf(buf, "ref: %s\n", target_nons); -- cgit v0.10.2-6-g49f6 From f124b7302353fb38f39bf4b44fd8bb0fc950c7d1 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:57 +0000 Subject: add_ref_decoration(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/log-tree.c b/log-tree.c index 1a0e170..abf5cc3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -89,7 +89,8 @@ const struct name_decoration *get_name_decoration(const struct object *obj) return lookup_decoration(&name_decoration, obj); } -static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +static int add_ref_decoration(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { struct object *obj; enum decoration_type type = DECORATION_NONE; @@ -110,7 +111,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in return 0; } - obj = parse_object(sha1); + obj = parse_object(oid->hash); if (!obj) return 0; @@ -149,13 +150,11 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) void load_ref_decorations(int flags) { if (!decoration_loaded) { - struct each_ref_fn_sha1_adapter wrapped_add_ref_decoration = - {add_ref_decoration, NULL}; decoration_loaded = 1; decoration_flags = flags; - for_each_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration); - head_ref(each_ref_fn_adapter, &wrapped_add_ref_decoration); + for_each_ref(add_ref_decoration, NULL); + head_ref(add_ref_decoration, NULL); for_each_commit_graft(add_graft_decoration, NULL); } } -- cgit v0.10.2-6-g49f6 From 3d79f65735bb60b8135f26748c285a877ebb7b69 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:58 +0000 Subject: add_ref_decoration(): convert local variable original_sha1 to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/log-tree.c b/log-tree.c index abf5cc3..01beb11 100644 --- a/log-tree.c +++ b/log-tree.c @@ -98,14 +98,14 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, assert(cb_data == NULL); if (starts_with(refname, "refs/replace/")) { - unsigned char original_sha1[20]; + struct object_id original_oid; if (!check_replace_refs) return 0; - if (get_sha1_hex(refname + 13, original_sha1)) { + if (get_oid_hex(refname + 13, &original_oid)) { warning("invalid replace ref %s", refname); return 0; } - obj = parse_object(original_sha1); + obj = parse_object(original_oid.hash); if (obj) add_name_decoration(DECORATION_GRAFTED, "replaced", obj); return 0; -- cgit v0.10.2-6-g49f6 From fd95035fdb817f228b6e5223883dcda081bde546 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:38:59 +0000 Subject: string_list_add_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 diff --git a/notes.c b/notes.c index baa1c41..df08209 100644 --- a/notes.c +++ b/notes.c @@ -918,7 +918,7 @@ out: return ret; } -static int string_list_add_one_ref(const char *refname, const unsigned char *sha1, +static int string_list_add_one_ref(const char *refname, const struct object_id *oid, int flag, void *cb) { struct string_list *refs = cb; @@ -932,12 +932,9 @@ static int string_list_add_one_ref(const char *refname, const unsigned char *sha */ void string_list_add_refs_by_glob(struct string_list *list, const char *glob) { - struct each_ref_fn_sha1_adapter wrapped_string_list_add_one_ref = - {string_list_add_one_ref, list}; - assert(list->strdup_strings); if (has_glob_specials(glob)) { - for_each_glob_ref(each_ref_fn_adapter, glob, &wrapped_string_list_add_one_ref); + for_each_glob_ref(string_list_add_one_ref, glob, list); } else { unsigned char sha1[20]; if (get_sha1(glob, sha1)) -- cgit v0.10.2-6-g49f6 From 635170f2bb34116441b562a93d3ce37ae4373ecc Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:00 +0000 Subject: add_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 diff --git a/reachable.c b/reachable.c index acac86a..9cff25b 100644 --- a/reachable.c +++ b/reachable.c @@ -22,9 +22,10 @@ static void update_progress(struct connectivity_progress *cp) display_progress(cp->progress, cp->count); } -static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int add_one_ref(const char *path, const struct object_id *oid, + int flag, void *cb_data) { - struct object *object = parse_object_or_die(sha1, path); + struct object *object = parse_object_or_die(oid->hash, path); struct rev_info *revs = (struct rev_info *)cb_data; add_pending_object(revs, object, ""); @@ -155,8 +156,6 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog, struct progress *progress) { struct connectivity_progress cp; - struct each_ref_fn_sha1_adapter wrapped_add_one_ref = - {add_one_ref, revs}; /* * Set up revision parsing, and mark us as being interested @@ -170,10 +169,10 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog, add_index_objects_to_pending(revs, 0); /* Add all external refs */ - for_each_ref(each_ref_fn_adapter, &wrapped_add_one_ref); + for_each_ref(add_one_ref, revs); /* detached HEAD is not included in the list above */ - head_ref(each_ref_fn_adapter, &wrapped_add_one_ref); + head_ref(add_one_ref, revs); /* Add all reflog info */ if (mark_reflog) -- cgit v0.10.2-6-g49f6 From 455ade659823ab01e7c1c5ec91be65c622319b01 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:01 +0000 Subject: 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 diff --git a/remote.c b/remote.c index 6d66ec1..1623eae 100644 --- a/remote.c +++ b/remote.c @@ -2024,7 +2024,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb) return 1; } -static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int one_local_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { struct ref ***local_tail = cb_data; struct ref *ref; @@ -2036,7 +2037,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla len = strlen(refname) + 1; ref = xcalloc(1, sizeof(*ref) + len); - hashcpy(ref->new_sha1, sha1); + hashcpy(ref->new_sha1, oid->hash); memcpy(ref->name, refname, len); **local_tail = ref; *local_tail = &ref->next; @@ -2046,10 +2047,8 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla struct ref *get_local_heads(void) { struct ref *local_refs = NULL, **local_tail = &local_refs; - struct each_ref_fn_sha1_adapter wrapped_one_local_ref = - {one_local_ref, &local_tail}; - for_each_ref(each_ref_fn_adapter, &wrapped_one_local_ref); + for_each_ref(one_local_ref, &local_tail); return local_refs; } @@ -2101,8 +2100,8 @@ struct stale_heads_info { int ref_count; }; -static int get_stale_heads_cb(const char *refname, - const unsigned char *sha1, int flags, void *cb_data) +static int get_stale_heads_cb(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { struct stale_heads_info *info = cb_data; struct string_list matches = STRING_LIST_INIT_DUP; @@ -2131,7 +2130,7 @@ static int get_stale_heads_cb(const char *refname, if (stale) { struct ref *ref = make_linked_ref(refname, &info->stale_refs_tail); - hashcpy(ref->new_sha1, sha1); + hashcpy(ref->new_sha1, oid->hash); } clean_exit: @@ -2144,8 +2143,6 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet struct ref *ref, *stale_refs = NULL; struct string_list ref_names = STRING_LIST_INIT_NODUP; struct stale_heads_info info; - struct each_ref_fn_sha1_adapter wrapped_get_stale_heads_cb = - {get_stale_heads_cb, &info}; info.ref_names = &ref_names; info.stale_refs_tail = &stale_refs; @@ -2154,7 +2151,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet for (ref = fetch_map; ref; ref = ref->next) string_list_append(&ref_names, ref->name); string_list_sort(&ref_names); - for_each_ref(each_ref_fn_adapter, &wrapped_get_stale_heads_cb); + for_each_ref(get_stale_heads_cb, &info); string_list_clear(&ref_names, 0); return stale_refs; } -- cgit v0.10.2-6-g49f6 From 00530834fb17f0ec070018270d0fb3e97e5dba07 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:02 +0000 Subject: register_replace_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 diff --git a/replace_object.c b/replace_object.c index a8a2da9..f0b39f0 100644 --- a/replace_object.c +++ b/replace_object.c @@ -53,7 +53,7 @@ static int register_replace_object(struct replace_object *replace, } static int register_replace_ref(const char *refname, - const unsigned char *sha1, + const struct object_id *oid, int flag, void *cb_data) { /* Get sha1 from refname */ @@ -68,7 +68,7 @@ static int register_replace_ref(const char *refname, } /* Copy sha1 from the read ref */ - hashcpy(repl_obj->replacement, sha1); + hashcpy(repl_obj->replacement, oid->hash); /* Register new object */ if (register_replace_object(repl_obj, 1)) @@ -80,13 +80,11 @@ static int register_replace_ref(const char *refname, static void prepare_replace_object(void) { static int replace_object_prepared; - struct each_ref_fn_sha1_adapter wrapped_register_replace_ref = - {register_replace_ref, NULL}; if (replace_object_prepared) return; - for_each_replace_ref(each_ref_fn_adapter, &wrapped_register_replace_ref); + for_each_replace_ref(register_replace_ref, NULL); replace_object_prepared = 1; if (!replace_object_nr) check_replace_refs = 0; -- cgit v0.10.2-6-g49f6 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 diff --git a/revision.c b/revision.c index cfe3876..1d903cf 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 v0.10.2-6-g49f6 From e2b0bcdf4a1106342dd443b7f86aef63bbe54897 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:04 +0000 Subject: add_info_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 diff --git a/server-info.c b/server-info.c index 317dda8..c82e9ee 100644 --- a/server-info.c +++ b/server-info.c @@ -47,14 +47,15 @@ out: return ret; } -static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int add_info_ref(const char *path, const struct object_id *oid, + int flag, void *cb_data) { FILE *fp = cb_data; - struct object *o = parse_object(sha1); + struct object *o = parse_object(oid->hash); if (!o) return -1; - if (fprintf(fp, "%s %s\n", sha1_to_hex(sha1), path) < 0) + if (fprintf(fp, "%s %s\n", oid_to_hex(oid), path) < 0) return -1; if (o->type == OBJ_TAG) { @@ -69,10 +70,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1, int flag, v static int generate_info_refs(FILE *fp) { - struct each_ref_fn_sha1_adapter wrapped_add_info_ref = - {add_info_ref, fp}; - - return for_each_ref(each_ref_fn_adapter, &wrapped_add_info_ref); + return for_each_ref(add_info_ref, fp); } static int update_info_refs(int force) -- cgit v0.10.2-6-g49f6 From 9c5fe0b846c1abe5655f6885c83437adc979d022 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:05 +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 diff --git a/sha1_name.c b/sha1_name.c index 1aad0a3..1cb8108 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -831,11 +831,11 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l /* Remember to update object flag allocation in object.h */ #define ONELINE_SEEN (1u<<20) -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 commit_list **list = cb_data; - struct object *object = parse_object(sha1); + struct object *object = parse_object(oid->hash); if (!object) return 0; if (object->type == OBJ_TAG) { @@ -1371,10 +1371,8 @@ static int get_sha1_with_context_1(const char *name, int pos; if (!only_to_die && namelen > 2 && name[1] == '/') { struct commit_list *list = NULL; - struct each_ref_fn_sha1_adapter wrapped_handle_one_ref = - {handle_one_ref, &list}; - for_each_ref(each_ref_fn_adapter, &wrapped_handle_one_ref); + for_each_ref(handle_one_ref, &list); commit_list_sort_by_date(&list); return get_sha1_oneline(name + 2, sha1, list); } -- cgit v0.10.2-6-g49f6 From 580b04ef98b366b71491ad816bacd02bfe64b4f9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:06 +0000 Subject: shallow: rewrite functions to take object_id arguments Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/shallow.c b/shallow.c index 9488edc..257d811 100644 --- a/shallow.c +++ b/shallow.c @@ -475,11 +475,10 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, free(tmp); } -static int mark_uninteresting(const char *refname, - const unsigned char *sha1, +static int mark_uninteresting(const char *refname, const struct object_id *oid, int flags, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(sha1, 1); + struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); if (!commit) return 0; commit->object.flags |= UNINTERESTING; @@ -512,8 +511,6 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, unsigned int i, nr; int *shallow, nr_shallow = 0; struct paint_info pi; - struct each_ref_fn_sha1_adapter wrapped_mark_uninteresting = - {mark_uninteresting, NULL}; trace_printf_key(&trace_shallow, "shallow: assign_shallow_commits_to_refs\n"); shallow = xmalloc(sizeof(*shallow) * (info->nr_ours + info->nr_theirs)); @@ -544,8 +541,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, * connect to old refs. If not (e.g. force ref updates) it'll * have to go down to the current shallow commits. */ - head_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting); - for_each_ref(each_ref_fn_adapter, &wrapped_mark_uninteresting); + head_ref(mark_uninteresting, NULL); + for_each_ref(mark_uninteresting, NULL); /* Mark potential bottoms so we won't go out of bound */ for (i = 0; i < nr_shallow; i++) { @@ -586,12 +583,12 @@ struct commit_array { int nr, alloc; }; -static int add_ref(const char *refname, - const unsigned char *sha1, int flags, void *cb_data) +static int add_ref(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { struct commit_array *ca = cb_data; ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc); - ca->commits[ca->nr] = lookup_commit_reference_gently(sha1, 1); + ca->commits[ca->nr] = lookup_commit_reference_gently(oid->hash, 1); if (ca->commits[ca->nr]) ca->nr++; return 0; @@ -620,8 +617,6 @@ static void post_assign_shallow(struct shallow_info *info, int dst, i, j; int bitmap_nr = (info->ref->nr + 31) / 32; struct commit_array ca; - struct each_ref_fn_sha1_adapter wrapped_add_ref = - {add_ref, &ca}; trace_printf_key(&trace_shallow, "shallow: post_assign_shallow\n"); if (ref_status) @@ -645,8 +640,8 @@ static void post_assign_shallow(struct shallow_info *info, info->nr_theirs = dst; memset(&ca, 0, sizeof(ca)); - head_ref(each_ref_fn_adapter, &wrapped_add_ref); - for_each_ref(each_ref_fn_adapter, &wrapped_add_ref); + head_ref(add_ref, &ca); + for_each_ref(add_ref, &ca); /* Remove unreachable shallow commits from "ours" */ for (i = dst = 0; i < info->nr_ours; i++) { @@ -678,12 +673,10 @@ int delayed_reachability_test(struct shallow_info *si, int c) if (!si->commits) { struct commit_array ca; - struct each_ref_fn_sha1_adapter wrapped_add_ref = - {add_ref, &ca}; memset(&ca, 0, sizeof(ca)); - head_ref(each_ref_fn_adapter, &wrapped_add_ref); - for_each_ref(each_ref_fn_adapter, &wrapped_add_ref); + head_ref(add_ref, &ca); + for_each_ref(add_ref, &ca); si->commits = ca.commits; si->nr_commits = ca.nr; } -- cgit v0.10.2-6-g49f6 From 7290ef5898ce343006ede558cb5755d35947b585 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:07 +0000 Subject: submodule: rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/submodule.c b/submodule.c index f0f34b6..e4c59df 100644 --- a/submodule.c +++ b/submodule.c @@ -422,20 +422,18 @@ void set_config_fetch_recurse_submodules(int value) config_fetch_recurse_submodules = value; } -static int has_remote(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +static int has_remote(const char *refname, const struct object_id *oid, + int flags, void *cb_data) { return 1; } static int submodule_needs_pushing(const char *path, const unsigned char sha1[20]) { - struct each_ref_fn_sha1_adapter wrapped_has_remote = - {has_remote, NULL}; - if (add_submodule_odb(path) || !lookup_commit_reference(sha1)) return 0; - if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) { + if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"rev-list", NULL, "--not", "--remotes", "-n", "1" , NULL}; struct strbuf buf = STRBUF_INIT; @@ -522,13 +520,10 @@ int find_unpushed_submodules(unsigned char new_sha1[20], static int push_submodule(const char *path) { - struct each_ref_fn_sha1_adapter wrapped_has_remote = - {has_remote, NULL}; - if (add_submodule_odb(path)) return 1; - if (for_each_remote_ref_submodule(path, each_ref_fn_adapter, &wrapped_has_remote) > 0) { + if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { struct child_process cp = CHILD_PROCESS_INIT; const char *argv[] = {"push", NULL}; @@ -622,20 +617,17 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q, } } -static int add_sha1_to_array(const char *ref, const unsigned char *sha1, +static int add_sha1_to_array(const char *ref, const struct object_id *oid, int flags, void *data) { - sha1_array_append(data, sha1); + sha1_array_append(data, oid->hash); return 0; } void check_for_new_submodule_commits(unsigned char new_sha1[20]) { if (!initialized_fetch_ref_tips) { - struct each_ref_fn_sha1_adapter wrapped_add_sha1_to_array = - {add_sha1_to_array, &ref_tips_before_fetch}; - - for_each_ref(each_ref_fn_adapter, &wrapped_add_sha1_to_array); + for_each_ref(add_sha1_to_array, &ref_tips_before_fetch); initialized_fetch_ref_tips = 1; } -- cgit v0.10.2-6-g49f6 From f31ba7e11611d17a460ed203ed3aa8142d662ff9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:08 +0000 Subject: write_refs_to_temp_dir(): convert local variable sha1 to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/transport.c b/transport.c index 58cb9ed..df87386 100644 --- a/transport.c +++ b/transport.c @@ -299,18 +299,18 @@ static int write_one_ref(const char *name, const unsigned char *sha1, } static int write_refs_to_temp_dir(struct strbuf *temp_dir, - int refspec_nr, const char **refspec) + int refspec_nr, const char **refspec) { int i; for (i = 0; i < refspec_nr; i++) { - unsigned char sha1[20]; + struct object_id oid; char *ref; - if (dwim_ref(refspec[i], strlen(refspec[i]), sha1, &ref) != 1) + if (dwim_ref(refspec[i], strlen(refspec[i]), oid.hash, &ref) != 1) return error("Could not get ref %s", refspec[i]); - if (write_one_ref(ref, sha1, 0, temp_dir)) { + if (write_one_ref(ref, oid.hash, 0, temp_dir)) { free(ref); return -1; } -- cgit v0.10.2-6-g49f6 From 1700cb3b057c6d7703f2452b22f0171630988d5f Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:09 +0000 Subject: write_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 diff --git a/transport.c b/transport.c index df87386..40692f8 100644 --- a/transport.c +++ b/transport.c @@ -278,8 +278,8 @@ static int fetch_objs_via_rsync(struct transport *transport, return run_command(&rsync); } -static int write_one_ref(const char *name, const unsigned char *sha1, - int flags, void *data) +static int write_one_ref(const char *name, const struct object_id *oid, + int flags, void *data) { struct strbuf *buf = data; int len = buf->len; @@ -291,7 +291,7 @@ static int write_one_ref(const char *name, const unsigned char *sha1, strbuf_addstr(buf, name); if (safe_create_leading_directories(buf->buf) || - write_file(buf->buf, 0, "%s\n", sha1_to_hex(sha1))) + write_file(buf->buf, 0, "%s\n", oid_to_hex(oid))) return error("problems writing temporary file %s: %s", buf->buf, strerror(errno)); strbuf_setlen(buf, len); @@ -310,7 +310,7 @@ static int write_refs_to_temp_dir(struct strbuf *temp_dir, if (dwim_ref(refspec[i], strlen(refspec[i]), oid.hash, &ref) != 1) return error("Could not get ref %s", refspec[i]); - if (write_one_ref(ref, oid.hash, 0, temp_dir)) { + if (write_one_ref(ref, &oid, 0, temp_dir)) { free(ref); return -1; } @@ -363,10 +363,7 @@ static int rsync_transport_push(struct transport *transport, strbuf_addch(&temp_dir, '/'); if (flags & TRANSPORT_PUSH_ALL) { - struct each_ref_fn_sha1_adapter wrapped_write_one_ref = - {write_one_ref, &temp_dir}; - - if (for_each_ref(each_ref_fn_adapter, &wrapped_write_one_ref)) + if (for_each_ref(write_one_ref, &temp_dir)) return -1; } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec)) return -1; -- cgit v0.10.2-6-g49f6 From 7dabd05634154687f99b41c917a0d119e530814e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:10 +0000 Subject: find_symref(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/upload-pack.c b/upload-pack.c index 52fab23..96dbedc 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -741,8 +741,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo return 0; } -static int find_symref(const char *refname, const unsigned char *sha1, int flag, - void *cb_data) +static int find_symref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { const char *symref_target; struct string_list_item *item; @@ -761,10 +761,8 @@ static int find_symref(const char *refname, const unsigned char *sha1, int flag, static void upload_pack(void) { struct string_list symref = STRING_LIST_INIT_DUP; - struct each_ref_fn_sha1_adapter wrapped_find_symref = - {find_symref, &symref}; - head_ref_namespaced(each_ref_fn_adapter, &wrapped_find_symref); + head_ref_namespaced(find_symref, &symref); if (advertise_refs || !stateless_rpc) { struct each_ref_fn_sha1_adapter wrapped_send_ref = -- cgit v0.10.2-6-g49f6 From e45a4949a28ef26fb3f27dc8ad2ad676269a5ea5 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:11 +0000 Subject: find_symref(): convert local variable "unused" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/upload-pack.c b/upload-pack.c index 96dbedc..8268037 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -746,11 +746,11 @@ static int find_symref(const char *refname, const struct object_id *oid, { const char *symref_target; struct string_list_item *item; - unsigned char unused[20]; + struct object_id unused; if ((flag & REF_ISSYMREF) == 0) return 0; - symref_target = resolve_ref_unsafe(refname, 0, unused, &flag); + symref_target = resolve_ref_unsafe(refname, 0, unused.hash, &flag); if (!symref_target || (flag & REF_ISSYMREF) == 0) die("'%s' is a symref but it is not?", refname); item = string_list_append(cb_data, refname); -- cgit v0.10.2-6-g49f6 From 363e98bfc27d810a0e41684b7744cc587c15c330 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:12 +0000 Subject: upload-pack: rewrite functions to take object_id arguments Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/upload-pack.c b/upload-pack.c index 8268037..929284f 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -681,9 +681,9 @@ static void receive_needs(void) } /* return non-zero if the ref is hidden, otherwise 0 */ -static int mark_our_ref(const char *refname, const unsigned char *sha1) +static int mark_our_ref(const char *refname, const struct object_id *oid) { - struct object *o = lookup_unknown_object(sha1); + struct object *o = lookup_unknown_object(oid->hash); if (ref_is_hidden(refname)) { o->flags |= HIDDEN_REF; @@ -693,9 +693,10 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1) return 0; } -static int check_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int check_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { - mark_our_ref(refname, sha1); + mark_our_ref(refname, oid); return 0; } @@ -709,7 +710,8 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref) strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); } -static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int send_ref(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { static const char *capabilities = "multi_ack thin-pack side-band" " side-band-64k ofs-delta shallow no-progress" @@ -717,7 +719,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo const char *refname_nons = strip_namespace(refname); unsigned char peeled[20]; - if (mark_our_ref(refname, sha1)) + if (mark_our_ref(refname, oid)) return 0; if (capabilities) { @@ -725,7 +727,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo format_symref_info(&symref_info, cb_data); packet_write(1, "%s %s%c%s%s%s%s agent=%s\n", - sha1_to_hex(sha1), refname_nons, + oid_to_hex(oid), refname_nons, 0, capabilities, allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "", stateless_rpc ? " no-done" : "", @@ -733,7 +735,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo git_user_agent_sanitized()); strbuf_release(&symref_info); } else { - packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons); + packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; if (!peel_ref(refname, peeled)) @@ -765,20 +767,14 @@ static void upload_pack(void) head_ref_namespaced(find_symref, &symref); if (advertise_refs || !stateless_rpc) { - struct each_ref_fn_sha1_adapter wrapped_send_ref = - {send_ref, &symref}; - reset_timeout(); - head_ref_namespaced(each_ref_fn_adapter, &wrapped_send_ref); - for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_send_ref); + head_ref_namespaced(send_ref, &symref); + for_each_namespaced_ref(send_ref, &symref); advertise_shallow_grafts(1); packet_flush(1); } else { - struct each_ref_fn_sha1_adapter wrapped_check_ref = - {check_ref, NULL}; - - head_ref_namespaced(each_ref_fn_adapter, &wrapped_check_ref); - for_each_namespaced_ref(each_ref_fn_adapter, &wrapped_check_ref); + head_ref_namespaced(check_ref, NULL); + for_each_namespaced_ref(check_ref, NULL); } string_list_clear(&symref, 1); if (advertise_refs) -- cgit v0.10.2-6-g49f6 From 21758affae79a23e402c46cb375a0fd0407050c9 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:13 +0000 Subject: send_ref(): convert local variable "peeled" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/upload-pack.c b/upload-pack.c index 929284f..1cb9a94 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -717,7 +717,7 @@ static int send_ref(const char *refname, const struct object_id *oid, " side-band-64k ofs-delta shallow no-progress" " include-tag multi_ack_detailed"; const char *refname_nons = strip_namespace(refname); - unsigned char peeled[20]; + struct object_id peeled; if (mark_our_ref(refname, oid)) return 0; @@ -738,8 +738,8 @@ static int send_ref(const char *refname, const struct object_id *oid, packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons); } capabilities = NULL; - if (!peel_ref(refname, peeled)) - packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons); + if (!peel_ref(refname, peeled.hash)) + packet_write(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); return 0; } -- cgit v0.10.2-6-g49f6 From b4ebaf9eea30a38a0462ff72ea3e0aec0101bb7e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:14 +0000 Subject: mark_complete(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/walker.c b/walker.c index bb2e0b9..44a936c 100644 --- a/walker.c +++ b/walker.c @@ -200,9 +200,11 @@ static int interpret_target(struct walker *walker, char *target, unsigned char * return -1; } -static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int mark_complete(const char *path, const struct object_id *oid, + int flag, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(sha1, 1); + struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); + if (commit) { commit->object.flags |= COMPLETE; commit_list_insert(commit, &complete); @@ -269,10 +271,7 @@ int walker_fetch(struct walker *walker, int targets, char **target, } if (!walker->get_recover) { - struct each_ref_fn_sha1_adapter wrapped_mark_complete = - {mark_complete, NULL}; - - for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete); + for_each_ref(mark_complete, NULL); commit_list_sort_by_date(&complete); } -- cgit v0.10.2-6-g49f6 From c50fb6cee6627ab9355e2d1e09fcab9dfe92cdb7 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:15 +0000 Subject: clear_marks(): rewrite to take an object_id argument Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/fetch-pack.c b/fetch-pack.c index 5380b1b..1e875cf 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -70,9 +70,10 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, i return 0; } -static int clear_marks(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int clear_marks(const char *refname, const struct object_id *oid, + int flag, void *cb_data) { - struct object *o = deref_tag(parse_object(sha1), refname, 0); + struct object *o = deref_tag(parse_object(oid->hash), refname, 0); if (o && o->type == OBJ_COMMIT) clear_commit_marks((struct commit *)o, @@ -261,12 +262,8 @@ static int find_common(struct fetch_pack_args *args, if (args->stateless_rpc && multi_ack == 1) die("--stateless-rpc requires multi_ack_detailed"); - if (marked) { - struct each_ref_fn_sha1_adapter wrapped_clear_marks = - {clear_marks, NULL}; - - for_each_ref(each_ref_fn_adapter, &wrapped_clear_marks); - } + if (marked) + for_each_ref(clear_marks, NULL); marked = 1; for_each_ref(each_ref_fn_adapter, &wrapped_rev_list_insert_ref); -- cgit v0.10.2-6-g49f6 From f8ee4d85229a26ec6d4ce403d953eea6b53c6396 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:16 +0000 Subject: mark_complete_oid(): new function, taking an object_oid This function can be used with for_each_ref() without having to be wrapped. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/fetch-pack.c b/fetch-pack.c index 1e875cf..d7a4a48 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -490,6 +490,12 @@ static int mark_complete(const char *refname, const unsigned char *sha1, int fla return 0; } +static int mark_complete_oid(const char *refname, const struct object_id *oid, + int flag, void *cb_data) +{ + return mark_complete(refname, oid->hash, flag, cb_data); +} + static void mark_recent_complete_commits(struct fetch_pack_args *args, unsigned long cutoff) { @@ -602,10 +608,7 @@ static int everything_local(struct fetch_pack_args *args, } if (!args->depth) { - struct each_ref_fn_sha1_adapter wrapped_mark_complete = - {mark_complete, NULL}; - - for_each_ref(each_ref_fn_adapter, &wrapped_mark_complete); + for_each_ref(mark_complete_oid, NULL); for_each_alternate_ref(mark_alternate_complete, NULL); commit_list_sort_by_date(&complete); if (cutoff) -- cgit v0.10.2-6-g49f6 From 6e20a51a8096059ecba6c7959d308c52f9fe8900 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:17 +0000 Subject: mark_complete(): remove unneeded arguments Now that the function is not being used as an each_ref_sha1_fn, we can delete the unused arguments in its signature. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/fetch-pack.c b/fetch-pack.c index d7a4a48..13a5000 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -469,7 +469,7 @@ done: static struct commit_list *complete; -static int mark_complete(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int mark_complete(const unsigned char *sha1) { struct object *o = parse_object(sha1); @@ -493,7 +493,7 @@ static int mark_complete(const char *refname, const unsigned char *sha1, int fla static int mark_complete_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - return mark_complete(refname, oid->hash, flag, cb_data); + return mark_complete(oid->hash); } static void mark_recent_complete_commits(struct fetch_pack_args *args, @@ -573,7 +573,7 @@ static void filter_refs(struct fetch_pack_args *args, static void mark_alternate_complete(const struct ref *ref, void *unused) { - mark_complete(NULL, ref->old_sha1, 0, NULL); + mark_complete(ref->old_sha1); } static int everything_local(struct fetch_pack_args *args, -- cgit v0.10.2-6-g49f6 From b1b49c6eb607b3f5697db7dae51e5152a3af3423 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:18 +0000 Subject: rev_list_insert_ref_oid(): new function, taking an object_oid This function can be used with for_each_ref() without having to be wrapped. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/fetch-pack.c b/fetch-pack.c index 13a5000..28c54c3 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -70,6 +70,12 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, i return 0; } +static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid, + int flag, void *cb_data) +{ + return rev_list_insert_ref(refname, oid->hash, flag, cb_data); +} + static int clear_marks(const char *refname, const struct object_id *oid, int flag, void *cb_data) { @@ -257,8 +263,6 @@ static int find_common(struct fetch_pack_args *args, int got_ready = 0; struct strbuf req_buf = STRBUF_INIT; size_t state_len = 0; - struct each_ref_fn_sha1_adapter wrapped_rev_list_insert_ref = - {rev_list_insert_ref, NULL}; if (args->stateless_rpc && multi_ack == 1) die("--stateless-rpc requires multi_ack_detailed"); @@ -266,7 +270,7 @@ static int find_common(struct fetch_pack_args *args, for_each_ref(clear_marks, NULL); marked = 1; - for_each_ref(each_ref_fn_adapter, &wrapped_rev_list_insert_ref); + for_each_ref(rev_list_insert_ref_oid, NULL); for_each_alternate_ref(insert_one_alternate_ref, NULL); fetching = 0; -- cgit v0.10.2-6-g49f6 From c38cd1c89d662dc0f4fd30f98cc8904c2143c7ab Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:19 +0000 Subject: rev_list_insert_ref(): remove unneeded arguments Now that the function is not being used as an each_ref_sha1_fn, we can delete the unused arguments in its signature. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/fetch-pack.c b/fetch-pack.c index 28c54c3..a1dcb27 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -60,7 +60,7 @@ static void rev_list_push(struct commit *commit, int mark) } } -static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data) +static int rev_list_insert_ref(const char *refname, const unsigned char *sha1) { struct object *o = deref_tag(parse_object(sha1), refname, 0); @@ -73,7 +73,7 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, i static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - return rev_list_insert_ref(refname, oid->hash, flag, cb_data); + return rev_list_insert_ref(refname, oid->hash); } static int clear_marks(const char *refname, const struct object_id *oid, @@ -233,7 +233,7 @@ static void send_request(struct fetch_pack_args *args, static void insert_one_alternate_ref(const struct ref *ref, void *unused) { - rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL); + rev_list_insert_ref(NULL, ref->old_sha1); } #define INITIAL_FLUSH 16 -- cgit v0.10.2-6-g49f6 From 0a0c9532170e6f2fec1a89aa4dff94c74d2d11d7 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:20 +0000 Subject: each_ref_fn_adapter(): remove adapter All of the callers of the for_each_ref family of functions have now been rewritten to work with object_ids, so this adapter is no longer needed. Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 43dce01..162760c 100644 --- a/refs.c +++ b/refs.c @@ -2176,14 +2176,6 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } -int each_ref_fn_adapter(const char *refname, - const struct object_id *oid, int flags, void *cb_data) -{ - struct each_ref_fn_sha1_adapter *cb = cb_data; - - return cb->original_fn(refname, oid->hash, flags, cb->original_cb_data); -} - const char *prettify_refname(const char *name) { return name + ( diff --git a/refs.h b/refs.h index 4042109..8c3d433 100644 --- a/refs.h +++ b/refs.h @@ -69,17 +69,6 @@ struct ref_transaction; typedef int each_ref_fn(const char *refname, const struct object_id *oid, int flags, void *cb_data); -typedef int each_ref_sha1_fn(const char *refname, - const unsigned char *sha1, int flags, void *cb_data); - -struct each_ref_fn_sha1_adapter { - each_ref_sha1_fn *original_fn; - void *original_cb_data; -}; - -extern int each_ref_fn_adapter(const char *refname, - const struct object_id *oid, int flags, void *cb_data); - /* * The following functions invoke the specified callback function for * each reference indicated. If the function ever returns a nonzero -- cgit v0.10.2-6-g49f6 From 4e675d17320ab98a946cef906f37938972a44be2 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:21 +0000 Subject: warn_if_dangling_symref(): convert local variable "junk" to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 162760c..7515c2e 100644 --- a/refs.c +++ b/refs.c @@ -1757,7 +1757,7 @@ int ref_exists(const char *refname) } static int filter_refs(const char *refname, const struct object_id *oid, - int flags, void *data) + int flags, void *data) { struct ref_filter *filter = (struct ref_filter *)data; @@ -1903,12 +1903,12 @@ static int warn_if_dangling_symref(const char *refname, const struct object_id * { struct warn_if_dangling_data *d = cb_data; const char *resolves_to; - unsigned char junk[20]; + struct object_id junk; if (!(flags & REF_ISSYMREF)) return 0; - resolves_to = resolve_ref_unsafe(refname, 0, junk, NULL); + resolves_to = resolve_ref_unsafe(refname, 0, junk.hash, NULL); if (!resolves_to || (d->refname ? strcmp(resolves_to, d->refname) -- cgit v0.10.2-6-g49f6 From 5cb901a4b0e19c87a1415f0f74995e54690598af Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Mon, 25 May 2015 18:39:22 +0000 Subject: struct ref_lock: convert old_sha1 member to object_id Signed-off-by: Michael Haggerty Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano diff --git a/refs.c b/refs.c index 7515c2e..a742d79 100644 --- a/refs.c +++ b/refs.c @@ -10,7 +10,7 @@ struct ref_lock { char *ref_name; char *orig_ref_name; struct lock_file *lk; - unsigned char old_sha1[20]; + struct object_id old_oid; }; /* @@ -2225,16 +2225,16 @@ static struct ref_lock *verify_lock(struct ref_lock *lock, { if (read_ref_full(lock->ref_name, mustexist ? RESOLVE_REF_READING : 0, - lock->old_sha1, NULL)) { + lock->old_oid.hash, NULL)) { int save_errno = errno; error("Can't verify ref %s", lock->ref_name); unlock_ref(lock); errno = save_errno; return NULL; } - if (hashcmp(lock->old_sha1, old_sha1)) { + if (hashcmp(lock->old_oid.hash, old_sha1)) { error("Ref %s is at %s but expected %s", lock->ref_name, - sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1)); + oid_to_hex(&lock->old_oid), sha1_to_hex(old_sha1)); unlock_ref(lock); errno = EBUSY; return NULL; @@ -2382,7 +2382,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, } refname = resolve_ref_unsafe(refname, resolve_flags, - lock->old_sha1, &type); + lock->old_oid.hash, &type); if (!refname && errno == EISDIR) { /* we are trying to lock foo but we used to * have foo/bar which now does not exist; @@ -2401,7 +2401,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, goto error_return; } refname = resolve_ref_unsafe(orig_refname, resolve_flags, - lock->old_sha1, &type); + lock->old_oid.hash, &type); } if (type_p) *type_p = type; @@ -2421,7 +2421,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname, * refname, nor a packed ref whose name is a proper prefix of * our refname. */ - if (is_null_sha1(lock->old_sha1) && + if (is_null_oid(&lock->old_oid) && verify_refname_available(refname, extras, skip, get_packed_refs(&ref_cache), err)) { last_errno = ENOTDIR; @@ -2944,7 +2944,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms strbuf_release(&err); goto rollback; } - hashcpy(lock->old_sha1, orig_sha1); + hashcpy(lock->old_oid.hash, orig_sha1); if (write_ref_to_lockfile(lock, orig_sha1) || commit_ref_update(lock, orig_sha1, logmsg)) { @@ -3199,9 +3199,9 @@ static int commit_ref_update(struct ref_lock *lock, const unsigned char *sha1, const char *logmsg) { clear_loose_ref_cache(&ref_cache); - if (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 || + if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg) < 0 || (strcmp(lock->ref_name, lock->orig_ref_name) && - log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) { + log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg) < 0)) { unlock_ref(lock); return -1; } @@ -3225,7 +3225,7 @@ static int commit_ref_update(struct ref_lock *lock, head_sha1, &head_flag); if (head_ref && (head_flag & REF_ISSYMREF) && !strcmp(head_ref, lock->ref_name)) - log_ref_write("HEAD", lock->old_sha1, sha1, logmsg); + log_ref_write("HEAD", lock->old_oid.hash, sha1, logmsg); } if (commit_ref(lock)) { error("Couldn't set %s", lock->ref_name); @@ -3923,7 +3923,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, (update->flags & REF_NODEREF)); if (!overwriting_symref && - !hashcmp(update->lock->old_sha1, update->new_sha1)) { + !hashcmp(update->lock->old_oid.hash, update->new_sha1)) { /* * The reference already has the desired * value, so we don't need to write it. -- cgit v0.10.2-6-g49f6