pack: make packed_git_mru global a value instead of a pointer

The MRU cache that keeps track of recently used packs is represented using two global variables: struct mru packed_git_mru_storage; struct mru *packed_git_mru = &packed_git_mru_storage; Callers never assign to the packed_git_mru pointer, though, so we can simplify by eliminating it and using &packed_git_mru_storage (renamed to &packed_git_mru) directly. This variable is only used by the packfile subsystem, making this a relatively uninvasive change (and any new unadapted callers would trigger a compile error). Noticed while moving these globals to the object_store struct. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Sep 12, 2017 at 10:28 UTC 607bd8315c6886eb61561bbba394616bc6fdf031
3 files changed +9 -11
builtin/pack-objects.c
+2 -2
@@ -1012,7 +1012,7 @@ static int want_object_in_pack(const unsigned char *sha1,
1012 return want;
1013 }
1014
1015 - for (entry = packed_git_mru->head; entry; entry = entry->next) {
1015 + for (entry = packed_git_mru.head; entry; entry = entry->next) {
1016 struct packed_git *p = entry->item;
1017 off_t offset;
1018
@@ -1030,7 +1030,7 @@ static int want_object_in_pack(const unsigned char *sha1,
1030 }
1031 want = want_found_object(exclude, p);
1032 if (!exclude && want > 0)
1033 - mru_mark(packed_git_mru, entry);
1033 + mru_mark(&packed_git_mru, entry);
1034 if (want != -1)
1035 return want;
1036 }
cache.h
+2 -2
@@ -4,6 +4,7 @@
4 #include "git-compat-util.h"
5 #include "strbuf.h"
6 #include "hashmap.h"
7 +#include "mru.h"
8 #include "advice.h"
9 #include "gettext.h"
10 #include "convert.h"
@@ -1589,8 +1590,7 @@ extern struct packed_git {
1590 * A most-recently-used ordered version of the packed_git list, which can
1591 * be iterated instead of packed_git (and marked via mru_mark).
1592 */
1592 -struct mru;
1593 -extern struct mru *packed_git_mru;
1593 +extern struct mru packed_git_mru;
1594
1595 struct pack_entry {
1596 off_t offset;
packfile.c
+5 -7
@@ -40,9 +40,7 @@ static unsigned int pack_max_fds;
40 static size_t peak_pack_mapped;
41 static size_t pack_mapped;
42 struct packed_git *packed_git;
43 -
44 -static struct mru packed_git_mru_storage;
45 -struct mru *packed_git_mru = &packed_git_mru_storage;
43 +struct mru packed_git_mru;
44
45 #define SZ_FMT PRIuMAX
46 static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -861,9 +859,9 @@ static void prepare_packed_git_mru(void)
859 {
860 struct packed_git *p;
861
864 - mru_clear(packed_git_mru);
862 + mru_clear(&packed_git_mru);
863 for (p = packed_git; p; p = p->next)
866 - mru_append(packed_git_mru, p);
864 + mru_append(&packed_git_mru, p);
865 }
866
867 static int prepare_packed_git_run_once = 0;
@@ -1832,9 +1830,9 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1830 if (!packed_git)
1831 return 0;
1832
1835 - for (p = packed_git_mru->head; p; p = p->next) {
1833 + for (p = packed_git_mru.head; p; p = p->next) {
1834 if (fill_pack_entry(sha1, e, p->item)) {
1837 - mru_mark(packed_git_mru, p);
1835 + mru_mark(&packed_git_mru, p);
1836 return 1;
1837 }
1838 }