Re: [PATCH v5] mru: Replace mru.[ch] with list.h implementation

2018-01-22 Thread Jeff King
On Mon, Jan 22, 2018 at 07:37:01AM +, Eric Wong wrote:

> > --- a/packfile.c
> > +++ b/packfile.c
> > @@ -859,9 +859,8 @@ static void prepare_packed_git_mru(void)
> >  {
> > struct packed_git *p;
> >  
> > -   mru_clear(_git_mru);
> 
> But the removed mru_clear needs to be replaced with:
> 
> + INIT_LIST_HEAD(_git_mru);
> 
> Otherwise, t3050 never finishes for me.

Good catch. One alternative is to just add any new packs to the end (or
beginning) of the mru list, instead of "resetting" it here. We can do
that because we know that prepare_packed_git() never drops list entries,
but only adds new ones.

I'm OK with it either way, though.

-Peff


Re: [PATCH v5] mru: Replace mru.[ch] with list.h implementation

2018-01-21 Thread Eric Wong
Gargi Sharma  wrote:
>  7 files changed, 15 insertions(+), 86 deletions(-)

Thanks! I like the code reduction and increased use of list.h

Were you able to finish running the test suite?  I wasn't :<

> -void mru_clear(struct mru *head)
> -{
> - struct list_head *pos;
> - struct list_head *tmp;
> -
> - list_for_each_safe(pos, tmp, >list) {
> - free(list_entry(pos, struct mru, list));
> - }
> - INIT_LIST_HEAD(>list);
> -}

OK, the free() calls are no longer necessary...



> --- a/packfile.c
> +++ b/packfile.c
> @@ -859,9 +859,8 @@ static void prepare_packed_git_mru(void)
>  {
>   struct packed_git *p;
>  
> - mru_clear(_git_mru);

But the removed mru_clear needs to be replaced with:

+   INIT_LIST_HEAD(_git_mru);

Otherwise, t3050 never finishes for me.

>   for (p = packed_git; p; p = p->next)
> - mru_append(_git_mru, p);
> + list_add_tail(>mru, _git_mru);
>  }

Everything else looks good to me, I'm still waiting for the test
suite to run but I don't expect further problems.


[PATCH v5] mru: Replace mru.[ch] with list.h implementation

2018-01-21 Thread Gargi Sharma
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 
---
The commit has been built on top of ot/mru-on-list branch.

Changes in v5:
- Remove list_move_to_front() as it is redundant.
Changes in v4:
- Fixing minor style issues.
Changes in v3:
- Make the commit message more descriptive.
- Remove braces after if statement.
Changes in v2:
- Add a move to front function to the list API.
- Remove memory leak.
- Remove redundant remove operations on the list.

A future improvement could be removing/changing the
type of nect pointer or dropping it entirely. See discussion
here:
https://public-inbox.org/git/caoci2dgyqr4jff5oby2buyhnjeaapqkf8tbojn2w0b18eo+...@mail.gmail.com/
---
 Makefile   |  1 -
 builtin/pack-objects.c |  9 -
 cache.h|  8 
 mru.c  | 27 ---
 mru.h  | 40 
 packfile.c | 15 +++
 sha1_file.c|  1 -
 7 files changed, 15 insertions(+), 86 deletions(-)
 delete mode 100644 mru.c
 delete mode 100644 mru.h

diff --git a/Makefile b/Makefile
index ed4ca43..4a79ec5 100644
--- a/Makefile
+++ b/Makefile
@@ -814,7 +814,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
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index ba81234..6a0b8e8 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -24,7 +24,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[] = {
@@ -1012,9 +1012,8 @@ static int want_object_in_pack(const unsigned char *sha1,
return want;
}
 
-   list_for_each(pos, _git_mru.list) {
-   struct mru *entry = list_entry(pos, struct mru, list);
-   struct packed_git *p = entry->item;
+   list_for_each(pos, _git_mru) {
+   struct packed_git *p = list_entry(pos, struct packed_git, mru);
off_t offset;
 
if (p == *found_pack)
@@ -1031,7 +1030,7 @@ static int want_object_in_pack(const unsigned char *sha1,
}
want = want_found_object(exclude, p);
if (!exclude && want > 0)
-   mru_mark(_git_mru, entry);
+   list_move(>mru, _git_mru);
if (want != -1)
return want;
}
diff --git a/cache.h b/cache.h
index 49b083e..cc09e3b 100644
--- 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"
@@ -1566,6 +1566,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;
@@ -1587,10 +1588,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
index 8f3f34c..000
--- 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(>list, >list);
-}
-
-void mru_mark(struct mru *head, struct mru *entry)
-{
-   /* To mark means to put at the front of the list. */
-   list_del(>list);
-   list_add(>list, >list);
-}
-
-void mru_clear(struct mru *head)
-{
-   struct list_head *pos;
-   struct list_head *tmp;
-
-   list_for_each_safe(pos, tmp, >list) {
-   free(list_entry(pos, struct mru, list));
-   }
-   INIT_LIST_HEAD(>list);
-}
diff --git a/mru.h b/mru.h
deleted file mode 100644
index 80a589e..000
--- 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