Skip to content

Commit 607bd83

Browse files
jrngitster
authored andcommitted
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>
1 parent 6867272 commit 607bd83

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ static int want_object_in_pack(const unsigned char *sha1,
10121012
return want;
10131013
}
10141014

1015-
for (entry = packed_git_mru->head; entry; entry = entry->next) {
1015+
for (entry = packed_git_mru.head; entry; entry = entry->next) {
10161016
struct packed_git *p = entry->item;
10171017
off_t offset;
10181018

@@ -1030,7 +1030,7 @@ static int want_object_in_pack(const unsigned char *sha1,
10301030
}
10311031
want = want_found_object(exclude, p);
10321032
if (!exclude && want > 0)
1033-
mru_mark(packed_git_mru, entry);
1033+
mru_mark(&packed_git_mru, entry);
10341034
if (want != -1)
10351035
return want;
10361036
}

cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "git-compat-util.h"
55
#include "strbuf.h"
66
#include "hashmap.h"
7+
#include "mru.h"
78
#include "advice.h"
89
#include "gettext.h"
910
#include "convert.h"
@@ -1589,8 +1590,7 @@ extern struct packed_git {
15891590
* A most-recently-used ordered version of the packed_git list, which can
15901591
* be iterated instead of packed_git (and marked via mru_mark).
15911592
*/
1592-
struct mru;
1593-
extern struct mru *packed_git_mru;
1593+
extern struct mru packed_git_mru;
15941594

15951595
struct pack_entry {
15961596
off_t offset;

packfile.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ static unsigned int pack_max_fds;
4040
static size_t peak_pack_mapped;
4141
static size_t pack_mapped;
4242
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;
4644

4745
#define SZ_FMT PRIuMAX
4846
static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -861,9 +859,9 @@ static void prepare_packed_git_mru(void)
861859
{
862860
struct packed_git *p;
863861

864-
mru_clear(packed_git_mru);
862+
mru_clear(&packed_git_mru);
865863
for (p = packed_git; p; p = p->next)
866-
mru_append(packed_git_mru, p);
864+
mru_append(&packed_git_mru, p);
867865
}
868866

869867
static int prepare_packed_git_run_once = 0;
@@ -1832,9 +1830,9 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
18321830
if (!packed_git)
18331831
return 0;
18341832

1835-
for (p = packed_git_mru->head; p; p = p->next) {
1833+
for (p = packed_git_mru.head; p; p = p->next) {
18361834
if (fill_pack_entry(sha1, e, p->item)) {
1837-
mru_mark(packed_git_mru, p);
1835+
mru_mark(&packed_git_mru, p);
18381836
return 1;
18391837
}
18401838
}

0 commit comments

Comments
 (0)