From: Junio C Hamano Date: Thu, 7 Feb 2019 06:05:27 +0000 (-0800) Subject: Merge branch 'sl/const' X-Git-Tag: v2.21.0-rc0~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3a14fdec88125c4fd093f938cf406231b932e3a2?hp=-c Merge branch 'sl/const' Code cleanup. * sl/const: various: tighten constness of some local variables --- 3a14fdec88125c4fd093f938cf406231b932e3a2 diff --combined builtin/diff.c index 74351a5757,84a362ff56..9f6109224b --- a/builtin/diff.c +++ b/builtin/diff.c @@@ -3,7 -3,6 +3,7 @@@ * * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" @@@ -103,7 -102,7 +103,7 @@@ static int builtin_diff_blobs(struct re int argc, const char **argv, struct object_array_entry **blob) { - unsigned mode = canon_mode(S_IFREG | 0644); + const unsigned mode = canon_mode(S_IFREG | 0644); if (argc > 1) usage(builtin_diff_usage); @@@ -213,7 -212,7 +213,7 @@@ static void refresh_index_quietly(void discard_cache(); read_cache(); refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED); - update_index_if_able(&the_index, &lock_file); + repo_update_index_if_able(the_repository, &lock_file); } static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv) diff --combined builtin/pack-objects.c index 68e2e66db2,5c406ab494..a9fac7c128 --- 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; @@@ -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(). */ @@@ -1902,10 -1901,10 +1902,10 @@@ static int type_size_sort(const void *_ { const struct object_entry *a = *(struct object_entry **)_a; const struct object_entry *b = *(struct object_entry **)_b; - enum object_type a_type = oe_type(a); - enum object_type b_type = oe_type(b); - unsigned long a_size = SIZE(a); - unsigned long b_size = SIZE(b); + const enum object_type a_type = oe_type(a); + const enum object_type b_type = oe_type(b); + const unsigned long a_size = SIZE(a); + const unsigned long b_size = SIZE(b); if (a_type > b_type) return -1; @@@ -1920,7 -1919,7 +1920,7 @@@ if (a->preferred_base < b->preferred_base) return 1; if (use_delta_islands) { - int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid); + const int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid); if (island_cmp) return island_cmp; } @@@ -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; @@@ -2167,7 -2171,7 +2167,7 @@@ static unsigned int check_delta_limit(s struct object_entry *child = DELTA_CHILD(me); unsigned int m = n; while (child) { - unsigned int c = check_delta_limit(child, n + 1); + const unsigned int c = check_delta_limit(child, n + 1); if (m < c) m = c; child = DELTA_SIBLING(child); @@@ -2222,7 -2226,7 +2222,7 @@@ static void find_deltas(struct object_e while (window_memory_limit && mem_usage > window_memory_limit && count > 1) { - uint32_t tail = (idx + window - count) % window; + const uint32_t tail = (idx + window - count) % window; mem_usage -= free_unpacked(array + tail); count--; } @@@ -2333,9 -2337,9 +2333,9 @@@ 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) @@@ -3135,7 -3137,7 +3135,7 @@@ static void get_object_list(int ac, con 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 -3294,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