[PATCH 22/27] sha1_file: allow sha1_file_name to handle arbitrary repositories
From: Stefan BellerSigned-off-by: Stefan Beller Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano Signed-off-by: Nguyễn Thái Ngọc Duy --- object-store.h | 3 +-- sha1_file.c| 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/object-store.h b/object-store.h index 03671745f4..d9cc875153 100644 --- a/object-store.h +++ b/object-store.h @@ -125,8 +125,7 @@ void raw_object_store_clear(struct raw_object_store *o); * Put in `buf` the name of the file in the local object database that * would be used to store a loose object with the specified sha1. */ -#define sha1_file_name(r, b, s) sha1_file_name_##r(b, s) -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1); +void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1); #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz) void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size); diff --git a/sha1_file.c b/sha1_file.c index 74c68ea776..aed9a558c5 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -323,9 +323,9 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1) } } -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1) +void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1) { - strbuf_addstr(buf, get_object_directory()); + strbuf_addstr(buf, r->objects->objectdir); strbuf_addch(buf, '/'); fill_sha1_path(buf, sha1); } -- 2.17.0.rc0.348.gd5a49e0b6f
Re: [PATCH 22/27] sha1_file: allow sha1_file_name to handle arbitrary repositories
On Wed, Feb 21, 2018 at 4:44 PM, Jonathan Tanwrote: > On Tue, 20 Feb 2018 17:54:25 -0800 > Stefan Beller wrote: > >> Signed-off-by: Stefan Beller >> Signed-off-by: Jonathan Nieder > > Reviewed-by: Jonathan Tan > >> -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char >> *sha1) >> +void sha1_file_name(struct repository *r, struct strbuf *buf, const >> unsigned char *sha1) >> { >> - strbuf_addstr(buf, get_object_directory()); >> + strbuf_addstr(buf, r->objects.objectdir); >> strbuf_addch(buf, '/'); >> fill_sha1_path(buf, sha1); >> } > > In the future, we should probably have: > - a function to get the object store out of a repo (so that it can >lazily initialize the object store struct if necessary) > - when the object store is obtained, its objectdir field is guaranteed >to be populated > - sha1_file_name should take the object store struct, not the repo >struct We had that in v2, but I reverted it as the consensus seemed that we prefer the_repository to be passed around. > > but this is outside the scope of this patch.
Re: [PATCH 22/27] sha1_file: allow sha1_file_name to handle arbitrary repositories
On Tue, 20 Feb 2018 17:54:25 -0800 Stefan Bellerwrote: > Signed-off-by: Stefan Beller > Signed-off-by: Jonathan Nieder Reviewed-by: Jonathan Tan > -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char > *sha1) > +void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned > char *sha1) > { > - strbuf_addstr(buf, get_object_directory()); > + strbuf_addstr(buf, r->objects.objectdir); > strbuf_addch(buf, '/'); > fill_sha1_path(buf, sha1); > } In the future, we should probably have: - a function to get the object store out of a repo (so that it can lazily initialize the object store struct if necessary) - when the object store is obtained, its objectdir field is guaranteed to be populated - sha1_file_name should take the object store struct, not the repo struct but this is outside the scope of this patch.
[PATCH 22/27] sha1_file: allow sha1_file_name to handle arbitrary repositories
Signed-off-by: Stefan BellerSigned-off-by: Jonathan Nieder --- object-store.h | 3 +-- sha1_file.c| 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/object-store.h b/object-store.h index a37d74a0c5..146358fe33 100644 --- a/object-store.h +++ b/object-store.h @@ -127,8 +127,7 @@ void raw_object_store_clear(struct raw_object_store *o); * Put in `buf` the name of the file in the local object database that * would be used to store a loose object with the specified sha1. */ -#define sha1_file_name(r, b, s) sha1_file_name_##r(b, s) -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1); +void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1); #define map_sha1_file(r, s, sz) map_sha1_file_##r(s, sz) void *map_sha1_file_the_repository(const unsigned char *sha1, unsigned long *size); diff --git a/sha1_file.c b/sha1_file.c index d1f77a4c80..8fad523d85 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -323,9 +323,9 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1) } } -void sha1_file_name_the_repository(struct strbuf *buf, const unsigned char *sha1) +void sha1_file_name(struct repository *r, struct strbuf *buf, const unsigned char *sha1) { - strbuf_addstr(buf, get_object_directory()); + strbuf_addstr(buf, r->objects.objectdir); strbuf_addch(buf, '/'); fill_sha1_path(buf, sha1); } -- 2.16.1.291.g4437f3f132-goog