# [PATCH] pack: make packed_git_mru global a value instead of a pointer

4 messages from 2017-09-17 to 2017-09-18. Participants: phionah bugosi, Christian Couder, Stefan Beller.
Thread: https://gitlist.dev/t/46774

## phionah bugosi, 2017-09-17 20:17

Subject: [PATCH] pack: make packed_git_mru global a value instead of a pointer
Message-ID: <1505679467-20720-1-git-send-email-bugosip@gmail.com>
URL: https://gitlist.dev/e/1505679467-20720-1-git-send-email-bugosip%40gmail.com

```
Signed-off-by: phionah bugosi <bugosip@gmail.com>
---
 builtin/pack-objects.c |  5 +++--
 cache.h                |  7 -------
 list.h                 |  6 ++++++
 packfile.c             | 12 ++++++------
 4 files changed, 15 insertions(+), 15 deletions(-)

This patch makes packed_git_mru global a value instead of a pointer and
makes use of list.h

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a57b4f0..189123f 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1,5 +1,6 @@
 #include "builtin.h"
 #include "cache.h"
+#include "list.h"
 #include "config.h"
 #include "attr.h"
 #include "object.h"
@@ -1012,7 +1013,7 @@ static int want_object_in_pack(const unsigned char *sha1,
 			return want;
 	}
 
-	for (entry = packed_git_mru->head; entry; entry = entry->next) {
+	for (entry = packed_git_mru.head; entry; entry = entry->next) {
 		struct packed_git *p = entry->item;
 		off_t offset;
 
@@ -1030,7 +1031,7 @@ static int want_object_in_pack(const unsigned char *sha1,
 			}
 			want = want_found_object(exclude, p);
 			if (!exclude && want > 0)
-				mru_mark(packed_git_mru, entry);
+				mru_mark(&packed_git_mru, entry);
 			if (want != -1)
 				return want;
 		}
diff --git a/cache.h b/cache.h
index a916bc7..c8d7086 100644
--- a/cache.h
+++ b/cache.h
@@ -1585,13 +1585,6 @@ extern struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 } *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).
- */
-struct mru;
-extern struct mru *packed_git_mru;
-
 struct pack_entry {
 	off_t offset;
 	unsigned char sha1[20];
diff --git a/list.h b/list.h
index a226a87..525703b 100644
--- a/list.h
+++ b/list.h
@@ -26,6 +26,12 @@
 #define LIST_H	1
 
 /*
+ * A most-recently-used ordered version of the packed_git list, which can
+ * be iterated instead of packed_git (and marked via mru_mark).
+ */
+extern struct mru packed_git_mru
+
+/*
  * The definitions of this file are adopted from those which can be
  * found in the Linux kernel headers to enable people familiar with the
  * latter find their way in these sources as well.
diff --git a/packfile.c b/packfile.c
index f86fa05..61a61aa 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "list.h"
 #include "mru.h"
 #include "pack.h"
 #include "dir.h"
@@ -41,8 +42,7 @@ static size_t peak_pack_mapped;
 static size_t pack_mapped;
 struct packed_git *packed_git;
 
-static struct mru packed_git_mru_storage;
-struct mru *packed_git_mru = &packed_git_mru_storage;
+struct mru packed_git_mru;
 
 #define SZ_FMT PRIuMAX
 static inline uintmax_t sz_fmt(size_t s) { return s; }
@@ -861,9 +861,9 @@ static void prepare_packed_git_mru(void)
 {
 	struct packed_git *p;
 
-	mru_clear(packed_git_mru);
+	mru_clear(&packed_git_mru);
 	for (p = packed_git; p; p = p->next)
-		mru_append(packed_git_mru, p);
+		mru_append(&packed_git_mru, p);
 }
 
 static int prepare_packed_git_run_once = 0;
@@ -1832,9 +1832,9 @@ int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
 	if (!packed_git)
 		return 0;
 
-	for (p = packed_git_mru->head; p; p = p->next) {
+	for (p = packed_git_mru.head; p; p = p->next) {
 		if (fill_pack_entry(sha1, e, p->item)) {
-			mru_mark(packed_git_mru, p);
+			mru_mark(&packed_git_mru, p);
 			return 1;
 		}
 	}
-- 
2.7.4


```

## Christian Couder, 2017-09-17 20:42

Subject: Re: [PATCH] pack: make packed_git_mru global a value instead of a pointer
Message-ID: <CAP8UFD2f3jXkRHb_S_dK7TDfhBwXQ+O63cBn0J7iQQA-5ysVMQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD2f3jXkRHb_S_dK7TDfhBwXQ%2BO63cBn0J7iQQA-5ysVMQ%40mail.gmail.com
In-Reply-To: <1505679467-20720-1-git-send-email-bugosip@gmail.com>

```
On Sun, Sep 17, 2017 at 10:17 PM, phionah bugosi <bugosip@gmail.com> wrote:
> Signed-off-by: phionah bugosi <bugosip@gmail.com>
> ---
>  builtin/pack-objects.c |  5 +++--
>  cache.h                |  7 -------
>  list.h                 |  6 ++++++
>  packfile.c             | 12 ++++++------
>  4 files changed, 15 insertions(+), 15 deletions(-)
>
> This patch makes packed_git_mru global a value instead of a pointer and
> makes use of list.h

Please explain _why_ you are doing that (why is the resulting code better).

You may also add [Outreachy] in the patch subject to tell people that
you are applying for the Outreachy round 15 program
(https://git.github.io/Outreachy-15/).

Thanks!

```

## Christian Couder, 2017-09-17 20:44

Subject: Re: [PATCH] pack: make packed_git_mru global a value instead of a pointer
Message-ID: <CAP8UFD2d7y9COGj=bRLk_d+F_M=c7nv802AjBf=R9NnJQB7ohA@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD2d7y9COGj%3DbRLk_d%2BF_M%3Dc7nv802AjBf%3DR9NnJQB7ohA%40mail.gmail.com
In-Reply-To: <CAP8UFD2f3jXkRHb_S_dK7TDfhBwXQ+O63cBn0J7iQQA-5ysVMQ@mail.gmail.com>

```
On Sun, Sep 17, 2017 at 10:42 PM, Christian Couder
<christian.couder@gmail.com> wrote:
> On Sun, Sep 17, 2017 at 10:17 PM, phionah bugosi <bugosip@gmail.com> wrote:
>> Signed-off-by: phionah bugosi <bugosip@gmail.com>
>> ---
>>  builtin/pack-objects.c |  5 +++--
>>  cache.h                |  7 -------
>>  list.h                 |  6 ++++++
>>  packfile.c             | 12 ++++++------
>>  4 files changed, 15 insertions(+), 15 deletions(-)
>>
>> This patch makes packed_git_mru global a value instead of a pointer and
>> makes use of list.h
>
> Please explain _why_ you are doing that (why is the resulting code better).

Also the explanations should be in the commit message, that is above
your "Signed-off-by: ..." line.

```

## Stefan Beller, 2017-09-18 17:26

Subject: Re: [PATCH] pack: make packed_git_mru global a value instead of a pointer
Message-ID: <CAGZ79kZwt5zM1N1=418FHMLZPjMJV55kKbJoat6GT157dxZObA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kZwt5zM1N1%3D418FHMLZPjMJV55kKbJoat6GT157dxZObA%40mail.gmail.com
In-Reply-To: <CAP8UFD2d7y9COGj=bRLk_d+F_M=c7nv802AjBf=R9NnJQB7ohA@mail.gmail.com>

```
On Sun, Sep 17, 2017 at 1:44 PM, Christian Couder
<christian.couder@gmail.com> wrote:
> On Sun, Sep 17, 2017 at 10:42 PM, Christian Couder
> <christian.couder@gmail.com> wrote:
>> On Sun, Sep 17, 2017 at 10:17 PM, phionah bugosi <bugosip@gmail.com> wrote:
>>> Signed-off-by: phionah bugosi <bugosip@gmail.com>
>>> ---
>>>  builtin/pack-objects.c |  5 +++--
>>>  cache.h                |  7 -------
>>>  list.h                 |  6 ++++++
>>>  packfile.c             | 12 ++++++------
>>>  4 files changed, 15 insertions(+), 15 deletions(-)
>>>
>>> This patch makes packed_git_mru global a value instead of a pointer and
>>> makes use of list.h
>>
>> Please explain _why_ you are doing that (why is the resulting code better).
>
> Also the explanations should be in the commit message, that is above
> your "Signed-off-by: ..." line.

A similar patch exists at origin/jn/per-repo-object-store-fixes^^
(I haven't checked if there are differences and if so which
patch is better, all I am noting here, is that there has been
work very similar to this one a couple days prior)

```
