Merge branch 'gs/retire-mru' into next
authorJunio C Hamano <gitster@pobox.com>
Wed, 7 Feb 2018 22:55:50 +0000 (14:55 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Feb 2018 22:55:50 +0000 (14:55 -0800)
Retire mru API as it does not give enough abstraction over
underlying list API to be worth it.

* gs/retire-mru:
mru: Replace mru.[ch] with list.h implementation

Makefile
builtin/pack-objects.c
cache.h
mru.c [deleted file]
mru.h [deleted file]
packfile.c
sha1_file.c
index eb74e6cf3c4b25ee639c192cefcddf8f235ffc0d..5bcd83ddf32707f8b98f650fd08d8eac5edf14af 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -831,7 +831,6 @@ LIB_OBJS += merge.o
 LIB_OBJS += merge-blobs.o
 LIB_OBJS += merge-recursive.o
 LIB_OBJS += mergesort.o
-LIB_OBJS += mru.o
 LIB_OBJS += name-hash.o
 LIB_OBJS += notes.o
 LIB_OBJS += notes-cache.o
index 0c3d03de487e1645a11d379dc5966cd9b2be81dd..83dcbc97731d2b0feeb72289f0ffa4c623952dec 100644 (file)
@@ -26,7 +26,7 @@
 #include "reachable.h"
 #include "sha1-array.h"
 #include "argv-array.h"
-#include "mru.h"
+#include "list.h"
 #include "packfile.h"
 
 static const char *pack_usage[] = {
@@ -1026,9 +1026,8 @@ static int want_object_in_pack(const struct object_id *oid,
                        return want;
        }
 
-       list_for_each(pos, &packed_git_mru.list) {
-               struct mru *entry = list_entry(pos, struct mru, list);
-               struct packed_git *p = entry->item;
+       list_for_each(pos, &packed_git_mru) {
+               struct packed_git *p = list_entry(pos, struct packed_git, mru);
                off_t offset;
 
                if (p == *found_pack)
@@ -1045,7 +1044,7 @@ static int want_object_in_pack(const struct object_id *oid,
                        }
                        want = want_found_object(exclude, p);
                        if (!exclude && want > 0)
-                               mru_mark(&packed_git_mru, entry);
+                               list_move(&p->mru, &packed_git_mru);
                        if (want != -1)
                                return want;
                }
diff --git a/cache.h b/cache.h
index 666d307043f528ef88d3ee24d66f0d7d12f1c80e..7414eb47b7e0489849ba92086d9f8f7311defc7d 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -4,7 +4,7 @@
 #include "git-compat-util.h"
 #include "strbuf.h"
 #include "hashmap.h"
-#include "mru.h"
+#include "list.h"
 #include "advice.h"
 #include "gettext.h"
 #include "convert.h"
@@ -1638,6 +1638,7 @@ struct pack_window {
 
 extern struct packed_git {
        struct packed_git *next;
+       struct list_head mru;
        struct pack_window *windows;
        off_t pack_size;
        const void *index_data;
@@ -1660,10 +1661,9 @@ extern struct packed_git {
 } *packed_git;
 
 /*
- * A most-recently-used ordered version of the packed_git list, which can
- * be iterated instead of packed_git (and marked via mru_mark).
+ * A most-recently-used ordered version of the packed_git list.
  */
-extern struct mru packed_git_mru;
+extern struct list_head packed_git_mru;
 
 struct pack_entry {
        off_t offset;
diff --git a/mru.c b/mru.c
deleted file mode 100644 (file)
index 8f3f34c..0000000
--- a/mru.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "cache.h"
-#include "mru.h"
-
-void mru_append(struct mru *head, void *item)
-{
-       struct mru *cur = xmalloc(sizeof(*cur));
-       cur->item = item;
-       list_add_tail(&cur->list, &head->list);
-}
-
-void mru_mark(struct mru *head, struct mru *entry)
-{
-       /* To mark means to put at the front of the list. */
-       list_del(&entry->list);
-       list_add(&entry->list, &head->list);
-}
-
-void mru_clear(struct mru *head)
-{
-       struct list_head *pos;
-       struct list_head *tmp;
-
-       list_for_each_safe(pos, tmp, &head->list) {
-               free(list_entry(pos, struct mru, list));
-       }
-       INIT_LIST_HEAD(&head->list);
-}
diff --git a/mru.h b/mru.h
deleted file mode 100644 (file)
index 80a589e..0000000
--- a/mru.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef MRU_H
-#define MRU_H
-
-#include "list.h"
-
-/**
- * A simple most-recently-used cache, backed by a doubly-linked list.
- *
- * Usage is roughly:
- *
- *   // Create a list.  Zero-initialization is required.
- *   static struct mru cache;
- *   INIT_LIST_HEAD(&cache.list);
- *
- *   // Add new item to the end of the list.
- *   void *item;
- *   ...
- *   mru_append(&cache, item);
- *
- *   // Mark an item as used, moving it to the front of the list.
- *   mru_mark(&cache, item);
- *
- *   // Reset the list to empty, cleaning up all resources.
- *   mru_clear(&cache);
- *
- * Note that you SHOULD NOT call mru_mark() and then continue traversing the
- * list; it reorders the marked item to the front of the list, and therefore
- * you will begin traversing the whole list again.
- */
-
-struct mru {
-       struct list_head list;
-       void *item;
-};
-
-void mru_append(struct mru *head, void *item);
-void mru_mark(struct mru *head, struct mru *entry);
-void mru_clear(struct mru *head);
-
-#endif /* MRU_H */
index f4dc4a242bdf8eb4e063adfdd56eb921c11ef5c0..2d5774dbc0901895b4dfc0d66cc03d3c253a3e95 100644 (file)
@@ -1,5 +1,5 @@
 #include "cache.h"
-#include "mru.h"
+#include "list.h"
 #include "pack.h"
 #include "dir.h"
 #include "mergesort.h"
@@ -45,7 +45,7 @@ static unsigned int pack_max_fds;
 static size_t peak_pack_mapped;
 static size_t pack_mapped;
 struct packed_git *packed_git;
-struct mru packed_git_mru = {{&packed_git_mru.list, &packed_git_mru.list}};
+LIST_HEAD(packed_git_mru);
 
 #define SZ_FMT PRIuMAX
 static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -876,9 +876,10 @@ static void prepare_packed_git_mru(void)
 {
        struct packed_git *p;
 
-       mru_clear(&packed_git_mru);
+       INIT_LIST_HEAD(&packed_git_mru);
+
        for (p = packed_git; p; p = p->next)
-               mru_append(&packed_git_mru, p);
+               list_add_tail(&p->mru, &packed_git_mru);
 }
 
 static int prepare_packed_git_run_once = 0;
@@ -1847,10 +1848,10 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
        if (!packed_git)
                return 0;
 
-       list_for_each(pos, &packed_git_mru.list) {
-               struct mru *p = list_entry(pos, struct mru, list);
-               if (fill_pack_entry(sha1, e, p->item)) {
-                       mru_mark(&packed_git_mru, p);
+       list_for_each(pos, &packed_git_mru) {
+               struct packed_git *p = list_entry(pos, struct packed_git, mru);
+               if (fill_pack_entry(sha1, e, p)) {
+                       list_move(&p->mru, &packed_git_mru);
                        return 1;
                }
        }
index 2e58f5560a63426ab1b9848434ea0e1ac3ba1fba..90998bb596e79dc3dccef9046f87c40bac347af5 100644 (file)
@@ -24,7 +24,6 @@
 #include "bulk-checkin.h"
 #include "streaming.h"
 #include "dir.h"
-#include "mru.h"
 #include "list.h"
 #include "mergesort.h"
 #include "quote.h"