From: Junio C Hamano Date: Thu, 7 Feb 2019 06:05:27 +0000 (-0800) Subject: Merge branch 'jk/loose-object-cache-oid' X-Git-Tag: v2.21.0-rc0~12 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cba595ab1a7764aecfde2e8e59994f89b2cd2f2e?ds=inline;hp=-c Merge branch 'jk/loose-object-cache-oid' Code clean-up. * jk/loose-object-cache-oid: prefer "hash mismatch" to "sha1 mismatch" sha1-file: avoid "sha1 file" for generic use in messages sha1-file: prefer "loose object file" to "sha1 file" in messages sha1-file: drop has_sha1_file() convert has_sha1_file() callers to has_object_file() sha1-file: convert pass-through functions to object_id sha1-file: modernize loose header/stream functions sha1-file: modernize loose object file functions http: use struct object_id instead of bare sha1 update comment references to sha1_object_info() sha1-file: fix outdated sha1 comment references --- cba595ab1a7764aecfde2e8e59994f89b2cd2f2e diff --combined apply.c index beed3091d2,b8e257ead2..892ede5a31 --- a/apply.c +++ b/apply.c @@@ -467,6 -467,7 +467,6 @@@ static char *squash_slash(char *name static char *find_name_gnu(struct apply_state *state, const char *line, - const char *def, int p_value) { struct strbuf name = STRBUF_INIT; @@@ -713,7 -714,7 +713,7 @@@ static char *find_name(struct apply_sta int terminate) { if (*line == '"') { - char *name = find_name_gnu(state, line, def, p_value); + char *name = find_name_gnu(state, line, p_value); if (name) return name; } @@@ -730,7 -731,7 +730,7 @@@ static char *find_name_traditional(stru size_t date_len; if (*line == '"') { - char *name = find_name_gnu(state, line, def, p_value); + char *name = find_name_gnu(state, line, p_value); if (name) return name; } @@@ -3182,7 -3183,7 +3182,7 @@@ static int apply_binary(struct apply_st return 0; /* deletion patch */ } - if (has_sha1_file(oid.hash)) { + if (has_object_file(&oid)) { /* We already have the postimage */ enum object_type type; unsigned long size; @@@ -3351,8 -3352,7 +3351,8 @@@ static int checkout_target(struct index costate.refresh_cache = 1; costate.istate = istate; - if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st)) + if (checkout_entry(ce, &costate, NULL, NULL) || + lstat(ce->name, st)) return error(_("cannot checkout %s"), ce->name); return 0; } @@@ -4019,7 -4019,7 +4019,7 @@@ static int read_apply_cache(struct appl return read_index_from(state->repo->index, state->index_file, get_git_dir()); else - return read_index(state->repo->index); + return repo_read_index(state->repo); } /* This function tries to read the object name from the current index */ @@@ -4712,8 -4712,7 +4712,8 @@@ static int apply_patch(struct apply_sta state->index_file, LOCK_DIE_ON_ERROR); else - hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(state->repo, &state->lock_file, + LOCK_DIE_ON_ERROR); } if (state->check_index && read_apply_cache(state) < 0) { diff --combined builtin/cat-file.c index 8487cd7dba,baaafbdcf3..0f092382e1 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@@ -3,7 -3,6 +3,7 @@@ * * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" @@@ -74,8 -73,7 +74,8 @@@ static int cat_one_file(int opt, const if (unknown_type) flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE; - if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH, + if (get_oid_with_context(the_repository, obj_name, + GET_OID_RECORD_PATH, &oid, &obj_context)) die("Not a valid object name %s", obj_name); @@@ -211,14 -209,14 +211,14 @@@ struct expand_data /* * After a mark_query run, this object_info is set up to be - * passed to sha1_object_info_extended. It will point to the data + * passed to oid_object_info_extended. It will point to the data * elements above, so you can retrieve the response from there. */ struct object_info info; /* * This flag will be true if the requested batch format and options - * don't require us to call sha1_object_info, which can then be + * don't require us to call oid_object_info, which can then be * optimized out. */ unsigned skip_object_info : 1; @@@ -382,18 -380,14 +382,18 @@@ static void batch_one_object(const cha { struct object_context ctx; int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; - enum follow_symlinks_result result; + enum get_oid_result result; - result = get_oid_with_context(obj_name, flags, &data->oid, &ctx); + result = get_oid_with_context(the_repository, obj_name, + flags, &data->oid, &ctx); if (result != FOUND) { switch (result) { case MISSING_OBJECT: printf("%s missing\n", obj_name); break; + case SHORT_NAME_AMBIGUOUS: + printf("%s ambiguous\n", obj_name); + break; case DANGLING_SYMLINK: printf("dangling %"PRIuMAX"\n%s\n", (uintmax_t)strlen(obj_name), obj_name); @@@ -496,7 -490,7 +496,7 @@@ static int batch_objects(struct batch_o /* * Expand once with our special mark_query flag, which will prime the - * object_info to be handed to sha1_object_info_extended for each + * object_info to be handed to oid_object_info_extended for each * object. */ memset(&data, 0, sizeof(data)); diff --combined builtin/fetch.c index 39c4210610,57f35c6a0a..5a09fe24cd --- a/builtin/fetch.c +++ b/builtin/fetch.c @@@ -317,8 -317,7 +317,7 @@@ static void find_non_local_tags(const s !has_object_file_with_flags(&ref->old_oid, OBJECT_INFO_QUICK) && !will_fetch(head, ref->old_oid.hash) && - !has_sha1_file_with_flags(item->oid.hash, - OBJECT_INFO_QUICK) && + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) oidclr(&item->oid); item = NULL; @@@ -332,7 -331,7 +331,7 @@@ * fetch. */ if (item && - !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) && + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) oidclr(&item->oid); @@@ -353,7 -352,7 +352,7 @@@ * checked to see if it needs fetching. */ if (item && - !has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) && + !has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) && !will_fetch(head, item->oid.hash)) oidclr(&item->oid); @@@ -629,14 -628,9 +628,14 @@@ static int find_and_replace(struct strb const char *needle, const char *placeholder) { - const char *p = strstr(haystack->buf, needle); + const char *p = NULL; int plen, nlen; + nlen = strlen(needle); + if (ends_with(haystack->buf, needle)) + p = haystack->buf + haystack->len - nlen; + else + p = strstr(haystack->buf, needle); if (!p) return 0; @@@ -644,6 -638,7 +643,6 @@@ return 0; plen = strlen(p); - nlen = strlen(needle); if (plen > nlen && p[nlen] != '/') return 0; @@@ -767,6 -762,9 +766,6 @@@ static int update_local_ref(struct ref what = _("[new ref]"); } - if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && - (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(&ref->new_oid); r = s_update_ref(msg, ref, 0); format_display(display, r ? '!' : '*', what, r ? _("unable to update local ref") : NULL, @@@ -780,6 -778,9 +779,6 @@@ strbuf_add_unique_abbrev(&quickref, ¤t->object.oid, DEFAULT_ABBREV); strbuf_addstr(&quickref, ".."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); - if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && - (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(&ref->new_oid); r = s_update_ref("fast-forward", ref, 1); format_display(display, r ? '!' : ' ', quickref.buf, r ? _("unable to update local ref") : NULL, @@@ -792,6 -793,9 +791,6 @@@ strbuf_add_unique_abbrev(&quickref, ¤t->object.oid, DEFAULT_ABBREV); strbuf_addstr(&quickref, "..."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); - if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && - (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(&ref->new_oid); r = s_update_ref("forced-update", ref, 1); format_display(display, r ? '!' : '+', quickref.buf, r ? _("unable to update local ref") : _("forced update"), @@@ -887,8 -891,6 +886,8 @@@ static int store_updated_refs(const cha ref->force = rm->peer_ref->force; } + if (recurse_submodules != RECURSE_SUBMODULES_OFF) + check_for_new_submodule_commits(&rm->old_oid); if (!strcmp(rm->name, "HEAD")) { kind = ""; @@@ -1169,7 -1171,6 +1168,7 @@@ static void add_negotiation_tips(struc static struct transport *prepare_transport(struct remote *remote, int deepen) { struct transport *transport; + transport = transport_get(remote, NULL); transport_set_verbosity(transport, verbosity, progress); transport->family = family; @@@ -1189,13 -1190,9 +1188,13 @@@ if (update_shallow) set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes"); if (filter_options.choice) { + struct strbuf expanded_filter_spec = STRBUF_INIT; + expand_list_objects_filter_spec(&filter_options, + &expanded_filter_spec); set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER, - filter_options.filter_spec); + expanded_filter_spec.buf); set_option(transport, TRANS_OPT_FROM_PROMISOR, "1"); + strbuf_release(&expanded_filter_spec); } if (negotiation_tip.nr) { if (transport->smart_options) @@@ -1480,8 -1477,7 +1479,8 @@@ static inline void fetch_one_setup_part */ if (strcmp(remote->name, repository_format_partial_clone)) { if (filter_options.choice) - die(_("--filter can only be used with the remote configured in core.partialClone")); + die(_("--filter can only be used with the remote " + "configured in extensions.partialclone")); return; } @@@ -1649,8 -1645,7 +1648,8 @@@ int cmd_fetch(int argc, const char **ar result = fetch_one(remote, argc, argv, prune_tags_ok); } else { if (filter_options.choice) - die(_("--filter can only be used with the remote configured in core.partialClone")); + die(_("--filter can only be used with the remote " + "configured in extensions.partialclone")); /* TODO should this also die if we have a previous partial-clone? */ result = fetch_multiple(&list); } diff --combined builtin/pack-objects.c index bd67491c16,d4c3987f3e..68e2e66db2 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@@ -84,7 -84,6 +84,7 @@@ static unsigned long pack_size_limit static int depth = 50; static int delta_search_threads; static int pack_to_stdout; +static int sparse; static int thin; static int num_preferred_base; static struct progress *progress_state; @@@ -971,7 -970,7 +971,7 @@@ static int no_try_delta(const char *pat if (!check) check = attr_check_initl("delta", NULL); - git_check_attr(&the_index, path, check); + git_check_attr(the_repository->index, path, check); if (ATTR_FALSE(check->items[0].value)) return 1; return 0; @@@ -1335,7 -1334,7 +1335,7 @@@ static void add_pbase_object(struct tre if (cmp < 0) return; if (name[cmplen] != '/') { - add_object_entry(entry.oid, + add_object_entry(&entry.oid, object_type(entry.mode), fullname, 1); return; @@@ -1346,7 -1345,7 +1346,7 @@@ const char *down = name+cmplen+1; int downlen = name_cmp_len(down); - tree = pbase_tree_get(entry.oid); + tree = pbase_tree_get(&entry.oid); if (!tree) return; init_tree_desc(&sub, tree->tree_data, tree->tree_size); @@@ -1643,7 -1642,7 +1643,7 @@@ static void check_object(struct object_ /* * No choice but to fall back to the recursive delta walk - * with sha1_object_info() to find about the object type + * with oid_object_info() to find about the object type * at this point... */ give_up: @@@ -1719,7 -1718,7 +1719,7 @@@ static void drop_reused_delta(struct ob if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) { /* * We failed to get the info from this pack for some reason; - * fall back to sha1_object_info, which may find another copy. + * fall back to oid_object_info, which may find another copy. * And if that fails, the error will be recorded in oe_type(entry) * and dealt with in prepare_pack(). */ @@@ -1954,6 -1953,11 +1954,6 @@@ static int delta_cacheable(unsigned lon return 0; } -/* Protect access to object database */ -static pthread_mutex_t read_mutex; -#define read_lock() pthread_mutex_lock(&read_mutex) -#define read_unlock() pthread_mutex_unlock(&read_mutex) - /* Protect delta_cache_size */ static pthread_mutex_t cache_mutex; #define cache_lock() pthread_mutex_lock(&cache_mutex) @@@ -1989,11 -1993,11 +1989,11 @@@ unsigned long oe_get_size_slow(struct p unsigned long used, avail, size; if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { - read_lock(); + packing_data_lock(&to_pack); if (oid_object_info(the_repository, &e->idx.oid, &size) < 0) die(_("unable to get size of %s"), oid_to_hex(&e->idx.oid)); - read_unlock(); + packing_data_unlock(&to_pack); return size; } @@@ -2001,7 -2005,7 +2001,7 @@@ if (!p) BUG("when e->type is a delta, it must belong to a pack"); - read_lock(); + packing_data_lock(&to_pack); w_curs = NULL; buf = use_pack(p, &w_curs, e->in_pack_offset, &avail); used = unpack_object_header_buffer(buf, avail, &type, &size); @@@ -2010,7 -2014,7 +2010,7 @@@ oid_to_hex(&e->idx.oid)); unuse_pack(&w_curs); - read_unlock(); + packing_data_unlock(&to_pack); return size; } @@@ -2072,9 -2076,9 +2072,9 @@@ static int try_delta(struct unpacked *t /* Load data if not already done */ if (!trg->data) { - read_lock(); + packing_data_lock(&to_pack); trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz); - read_unlock(); + packing_data_unlock(&to_pack); if (!trg->data) die(_("object %s cannot be read"), oid_to_hex(&trg_entry->idx.oid)); @@@ -2085,9 -2089,9 +2085,9 @@@ *mem_usage += sz; } if (!src->data) { - read_lock(); + packing_data_lock(&to_pack); src->data = read_object_file(&src_entry->idx.oid, &type, &sz); - read_unlock(); + packing_data_unlock(&to_pack); if (!src->data) { if (src_entry->preferred_base) { static int warned = 0; @@@ -2333,9 -2337,9 +2333,9 @@@ static void find_deltas(struct object_e static void try_to_free_from_threads(size_t size) { - read_lock(); + packing_data_lock(&to_pack); release_pack_memory(size); - read_unlock(); + packing_data_unlock(&to_pack); } static try_to_free_t old_try_to_free_routine; @@@ -2377,6 -2381,7 +2377,6 @@@ static pthread_cond_t progress_cond */ static void init_threaded_search(void) { - init_recursive_mutex(&read_mutex); pthread_mutex_init(&cache_mutex, NULL); pthread_mutex_init(&progress_mutex, NULL); pthread_cond_init(&progress_cond, NULL); @@@ -2387,6 -2392,7 +2387,6 @@@ static void cleanup_threaded_search(voi { set_try_to_free_routine(old_try_to_free_routine); pthread_cond_destroy(&progress_cond); - pthread_mutex_destroy(&read_mutex); pthread_mutex_destroy(&cache_mutex); pthread_mutex_destroy(&progress_mutex); } @@@ -2704,10 -2710,6 +2704,10 @@@ static int git_pack_config(const char * use_bitmap_index_default = git_config_bool(k, v); return 0; } + if (!strcmp(k, "pack.usesparse")) { + sparse = git_config_bool(k, v); + return 0; + } if (!strcmp(k, "pack.threads")) { delta_search_threads = git_config_int(k, v); if (delta_search_threads < 0) @@@ -3082,16 -3084,14 +3082,16 @@@ static void record_recent_commit(struc static void get_object_list(int ac, const char **av) { struct rev_info revs; + struct setup_revision_opt s_r_opt = { + .allow_exclude_promisor_objects = 1, + }; char line[1000]; int flags = 0; int save_warning; repo_init_revisions(the_repository, &revs, NULL); save_commit_buffer = 0; - revs.allow_exclude_promisor_objects_opt = 1; - setup_revisions(ac, av, &revs, NULL); + setup_revisions(ac, av, &revs, &s_r_opt); /* make sure shallows are read */ is_repository_shallow(the_repository); @@@ -3135,7 -3135,7 +3135,7 @@@ if (prepare_revision_walk(&revs)) die(_("revision walk setup failed")); - mark_edges_uninteresting(&revs, show_edge); + mark_edges_uninteresting(&revs, show_edge, sparse); if (!fn_show_object) fn_show_object = show_object; @@@ -3292,8 -3292,6 +3292,8 @@@ int cmd_pack_objects(int argc, const ch { OPTION_CALLBACK, 0, "unpack-unreachable", NULL, N_("time"), N_("unpack unreachable objects newer than