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>
Gargi Sharma committed
Jan 23, 2018 at 18:46 UTC
ec2dd32c705f43ef133a54cee99426c44eb3ab88
7 files changed
+17
-86
Makefile
-1
@@ -814,7 +814,6 @@ LIB_OBJS += merge.o
814
LIB_OBJS += merge-blobs.o
815
LIB_OBJS += merge-recursive.o
816
LIB_OBJS += mergesort.o
817
-LIB_OBJS += mru.o
817
LIB_OBJS += name-hash.o
818
LIB_OBJS += notes.o
819
LIB_OBJS += notes-cache.o
builtin/pack-objects.c
+4
-5
@@ -24,7 +24,7 @@
24
#include "reachable.h"
25
#include "sha1-array.h"
26
#include "argv-array.h"
27
-#include "mru.h"
27
+#include "list.h"
28
#include "packfile.h"
29
30
static const char *pack_usage[] = {
@@ -1012,9 +1012,8 @@ static int want_object_in_pack(const unsigned char *sha1,
1012
return want;
1013
}
1014
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);
1017
off_t offset;
1018
1019
if (p == *found_pack)
@@ -1031,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)
1034
- mru_mark(&packed_git_mru, entry);
1033
+ list_move(&p->mru, &packed_git_mru);
1034
if (want != -1)
1035
return want;
1036
}
cache.h
+4
-4
@@ -4,7 +4,7 @@
4
#include "git-compat-util.h"
5
#include "strbuf.h"
6
#include "hashmap.h"
7
-#include "mru.h"
7
+#include "list.h"
8
#include "advice.h"
9
#include "gettext.h"
10
#include "convert.h"
@@ -1566,6 +1566,7 @@ struct pack_window {
1566
1567
extern struct packed_git {
1568
struct packed_git *next;
1569
+ struct list_head mru;
1570
struct pack_window *windows;
1571
off_t pack_size;
1572
const void *index_data;
@@ -1587,10 +1588,9 @@ extern struct packed_git {
1588
} *packed_git;
1589
1590
/*
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.
1592
*/
1593
-extern struct mru packed_git_mru;
1593
+extern struct list_head packed_git_mru;
1594
1595
struct pack_entry {
1596
off_t offset;
mru.c
deleted
-27
@@ -1,27 +0,0 @@
1
-#include "cache.h"
2
-#include "mru.h"
3
-
4
-void mru_append(struct mru *head, void *item)
5
-{
6
- struct mru *cur = xmalloc(sizeof(*cur));
7
- cur->item = item;
8
- list_add_tail(&cur->list, &head->list);
9
-}
10
-
11
-void mru_mark(struct mru *head, struct mru *entry)
12
-{
13
- /* To mark means to put at the front of the list. */
14
- list_del(&entry->list);
15
- list_add(&entry->list, &head->list);
16
-}
17
-
18
-void mru_clear(struct mru *head)
19
-{
20
- struct list_head *pos;
21
- struct list_head *tmp;
22
-
23
- list_for_each_safe(pos, tmp, &head->list) {
24
- free(list_entry(pos, struct mru, list));
25
- }
26
- INIT_LIST_HEAD(&head->list);
27
-}
mru.h
deleted
-40
@@ -1,40 +0,0 @@
1
-#ifndef MRU_H
2
-#define MRU_H
3
-
4
-#include "list.h"
5
-
6
-/**
7
- * A simple most-recently-used cache, backed by a doubly-linked list.
8
- *
9
- * Usage is roughly:
10
- *
11
- * // Create a list. Zero-initialization is required.
12
- * static struct mru cache;
13
- * INIT_LIST_HEAD(&cache.list);
14
- *
15
- * // Add new item to the end of the list.
16
- * void *item;
17
- * ...
18
- * mru_append(&cache, item);
19
- *
20
- * // Mark an item as used, moving it to the front of the list.
21
- * mru_mark(&cache, item);
22
- *
23
- * // Reset the list to empty, cleaning up all resources.
24
- * mru_clear(&cache);
25
- *
26
- * Note that you SHOULD NOT call mru_mark() and then continue traversing the
27
- * list; it reorders the marked item to the front of the list, and therefore
28
- * you will begin traversing the whole list again.
29
- */
30
-
31
-struct mru {
32
- struct list_head list;
33
- void *item;
34
-};
35
-
36
-void mru_append(struct mru *head, void *item);
37
-void mru_mark(struct mru *head, struct mru *entry);
38
-void mru_clear(struct mru *head);
39
-
40
-#endif /* MRU_H */
packfile.c
+9
-8
@@ -1,5 +1,5 @@
1
#include "cache.h"
2
-#include "mru.h"
2
+#include "list.h"
3
#include "pack.h"
4
#include "dir.h"
5
#include "mergesort.h"
@@ -40,7 +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
-struct mru packed_git_mru = {{&packed_git_mru.list, &packed_git_mru.list}};
43
+LIST_HEAD(packed_git_mru);
44
45
#define SZ_FMT PRIuMAX
46
static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -859,9 +859,10 @@ static void prepare_packed_git_mru(void)
859
{
860
struct packed_git *p;
861
862
- mru_clear(&packed_git_mru);
862
+ INIT_LIST_HEAD(&packed_git_mru);
863
+
864
for (p = packed_git; p; p = p->next)
864
- mru_append(&packed_git_mru, p);
865
+ list_add_tail(&p->mru, &packed_git_mru);
866
}
867
868
static int prepare_packed_git_run_once = 0;
@@ -1830,10 +1831,10 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
1831
if (!packed_git)
1832
return 0;
1833
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);
1838
return 1;
1839
}
1840
}
sha1_file.c
-1
@@ -24,7 +24,6 @@
24
#include "bulk-checkin.h"
25
#include "streaming.h"
26
#include "dir.h"
27
-#include "mru.h"
27
#include "list.h"
28
#include "mergesort.h"
29
#include "quote.h"