Skip to content

Commit ec2dd32

Browse files
gs0510gitster
authored andcommitted
mru: Replace mru.[ch] with list.h implementation
Replace the custom calls to mru.[ch] with calls to list.h. This patch is the final step in removing the mru API completely and inlining the logic. This patch leads to significant code reduction and the mru API hence, is not a useful abstraction anymore. Signed-off-by: Gargi Sharma <gs051095@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8865859 commit ec2dd32

File tree

7 files changed

+17
-86
lines changed

7 files changed

+17
-86
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,6 @@ LIB_OBJS += merge.o
814814
LIB_OBJS += merge-blobs.o
815815
LIB_OBJS += merge-recursive.o
816816
LIB_OBJS += mergesort.o
817-
LIB_OBJS += mru.o
818817
LIB_OBJS += name-hash.o
819818
LIB_OBJS += notes.o
820819
LIB_OBJS += notes-cache.o

builtin/pack-objects.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "reachable.h"
2525
#include "sha1-array.h"
2626
#include "argv-array.h"
27-
#include "mru.h"
27+
#include "list.h"
2828
#include "packfile.h"
2929

3030
static const char *pack_usage[] = {
@@ -1012,9 +1012,8 @@ static int want_object_in_pack(const unsigned char *sha1,
10121012
return want;
10131013
}
10141014

1015-
list_for_each(pos, &packed_git_mru.list) {
1016-
struct mru *entry = list_entry(pos, struct mru, list);
1017-
struct packed_git *p = entry->item;
1015+
list_for_each(pos, &packed_git_mru) {
1016+
struct packed_git *p = list_entry(pos, struct packed_git, mru);
10181017
off_t offset;
10191018

10201019
if (p == *found_pack)
@@ -1031,7 +1030,7 @@ static int want_object_in_pack(const unsigned char *sha1,
10311030
}
10321031
want = want_found_object(exclude, p);
10331032
if (!exclude && want > 0)
1034-
mru_mark(&packed_git_mru, entry);
1033+
list_move(&p->mru, &packed_git_mru);
10351034
if (want != -1)
10361035
return want;
10371036
}

cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "git-compat-util.h"
55
#include "strbuf.h"
66
#include "hashmap.h"
7-
#include "mru.h"
7+
#include "list.h"
88
#include "advice.h"
99
#include "gettext.h"
1010
#include "convert.h"
@@ -1566,6 +1566,7 @@ struct pack_window {
15661566

15671567
extern struct packed_git {
15681568
struct packed_git *next;
1569+
struct list_head mru;
15691570
struct pack_window *windows;
15701571
off_t pack_size;
15711572
const void *index_data;
@@ -1587,10 +1588,9 @@ extern struct packed_git {
15871588
} *packed_git;
15881589

15891590
/*
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).
1591+
* A most-recently-used ordered version of the packed_git list.
15921592
*/
1593-
extern struct mru packed_git_mru;
1593+
extern struct list_head packed_git_mru;
15941594

15951595
struct pack_entry {
15961596
off_t offset;

mru.c

Lines changed: 0 additions & 27 deletions
This file was deleted.

mru.h

Lines changed: 0 additions & 40 deletions
This file was deleted.

packfile.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "cache.h"
2-
#include "mru.h"
2+
#include "list.h"
33
#include "pack.h"
44
#include "dir.h"
55
#include "mergesort.h"
@@ -40,7 +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-
struct mru packed_git_mru = {{&packed_git_mru.list, &packed_git_mru.list}};
43+
LIST_HEAD(packed_git_mru);
4444

4545
#define SZ_FMT PRIuMAX
4646
static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -859,9 +859,10 @@ static void prepare_packed_git_mru(void)
859859
{
860860
struct packed_git *p;
861861

862-
mru_clear(&packed_git_mru);
862+
INIT_LIST_HEAD(&packed_git_mru);
863+
863864
for (p = packed_git; p; p = p->next)
864-
mru_append(&packed_git_mru, p);
865+
list_add_tail(&p->mru, &packed_git_mru);
865866
}
866867

867868
static int prepare_packed_git_run_once = 0;
@@ -1830,10 +1831,10 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
18301831
if (!packed_git)
18311832
return 0;
18321833

1833-
list_for_each(pos, &packed_git_mru.list) {
1834-
struct mru *p = list_entry(pos, struct mru, list);
1835-
if (fill_pack_entry(sha1, e, p->item)) {
1836-
mru_mark(&packed_git_mru, p);
1834+
list_for_each(pos, &packed_git_mru) {
1835+
struct packed_git *p = list_entry(pos, struct packed_git, mru);
1836+
if (fill_pack_entry(sha1, e, p)) {
1837+
list_move(&p->mru, &packed_git_mru);
18371838
return 1;
18381839
}
18391840
}

sha1_file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "bulk-checkin.h"
2525
#include "streaming.h"
2626
#include "dir.h"
27-
#include "mru.h"
2827
#include "list.h"
2928
#include "mergesort.h"
3029
#include "quote.h"

0 commit comments

Comments
 (0)