[PATCH 15/27] sha1_file: allow prepare_alt_odb to handle arbitrary repositories

2018-03-23 Thread Nguyễn Thái Ngọc Duy
From: Stefan Beller 

Signed-off-by: Stefan Beller 
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 object-store.h |  3 +--
 sha1_file.c| 13 +
 2 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/object-store.h b/object-store.h
index 3fc461a463..f54bc0b951 100644
--- a/object-store.h
+++ b/object-store.h
@@ -24,8 +24,7 @@ struct alternate_object_database {
 */
char path[FLEX_ARRAY];
 };
-#define prepare_alt_odb(r) prepare_alt_odb_##r()
-void prepare_alt_odb_the_repository(void);
+void prepare_alt_odb(struct repository *r);
 char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 int foreach_alt_odb(alt_odb_fn, void*);
diff --git a/sha1_file.c b/sha1_file.c
index d38f5cdb0e..04118f331c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -673,18 +673,15 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
 }
 
-void prepare_alt_odb_the_repository(void)
+void prepare_alt_odb(struct repository *r)
 {
-   if (the_repository->objects->alt_odb_tail)
+   if (r->objects->alt_odb_tail)
return;
 
-   the_repository->objects->alt_odb_tail =
-   _repository->objects->alt_odb_list;
-   link_alt_odb_entries(the_repository,
-the_repository->objects->alternate_db,
-PATH_SEP, NULL, 0);
+   r->objects->alt_odb_tail = >objects->alt_odb_list;
+   link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);
 
-   read_info_alternates(the_repository, get_object_directory(), 0);
+   read_info_alternates(r, r->objects->objectdir, 0);
 }
 
 /* Returns 1 if we have successfully freshened the file, 0 otherwise. */
-- 
2.17.0.rc0.348.gd5a49e0b6f



Re: [PATCH 15/27] sha1_file: allow prepare_alt_odb to handle arbitrary repositories

2018-02-23 Thread Stefan Beller
On Wed, Feb 21, 2018 at 4:35 PM, Jonathan Tan  wrote:
> On Tue, 20 Feb 2018 17:54:18 -0800
> Stefan Beller  wrote:
>
>> -void prepare_alt_odb_the_repository(void)
>> +void prepare_alt_odb(struct repository *r)
>>  {
>> - const char *alt;
>> -
>> - if (the_repository->objects.alt_odb_tail)
>> + if (r->objects.alt_odb_tail)
>>   return;
>>
>> - alt = getenv(ALTERNATE_DB_ENVIRONMENT);
>> + r->objects.alt_odb_tail = >objects.alt_odb_list;
>> +
>> + if (!r->ignore_env) {
>> + const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);
>> + if (!alt)
>> + alt = "";
>
> alt can be NULL, just like in the existing code, so these 2 lines are
> unnecessary. (link_alt_odb_entries() will just do nothing in either
> case.)
>
> (I also think that the check of absence of alt should be done by the
> caller of link_alt_odb_entries(), not by link_alt_odb_entries() itself,
> but that is much beyond the scope of this patch set.)
>

reverted to a literal translation of s/the_repository/r/, I forget
why I implemented this change in the first place. dropped for now.

Thanks,
Stefan


Re: [PATCH 15/27] sha1_file: allow prepare_alt_odb to handle arbitrary repositories

2018-02-21 Thread Jonathan Tan
On Tue, 20 Feb 2018 17:54:18 -0800
Stefan Beller  wrote:

> -void prepare_alt_odb_the_repository(void)
> +void prepare_alt_odb(struct repository *r)
>  {
> - const char *alt;
> -
> - if (the_repository->objects.alt_odb_tail)
> + if (r->objects.alt_odb_tail)
>   return;
>  
> - alt = getenv(ALTERNATE_DB_ENVIRONMENT);
> + r->objects.alt_odb_tail = >objects.alt_odb_list;
> +
> + if (!r->ignore_env) {
> + const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);
> + if (!alt)
> + alt = "";

alt can be NULL, just like in the existing code, so these 2 lines are
unnecessary. (link_alt_odb_entries() will just do nothing in either
case.)

(I also think that the check of absence of alt should be done by the
caller of link_alt_odb_entries(), not by link_alt_odb_entries() itself,
but that is much beyond the scope of this patch set.)

>  
> - the_repository->objects.alt_odb_tail =
> - _repository->objects.alt_odb_list;
> - link_alt_odb_entries(the_repository, alt,
> -  PATH_SEP, NULL, 0);
> + link_alt_odb_entries(r, alt, PATH_SEP, NULL, 0);
> + }
>  
> - read_info_alternates(the_repository, get_object_directory(), 0);
> + read_info_alternates(r, r->objects.objectdir, 0);
>  }


[PATCH 15/27] sha1_file: allow prepare_alt_odb to handle arbitrary repositories

2018-02-20 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 object-store.h |  3 +--
 sha1_file.c| 21 +++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/object-store.h b/object-store.h
index f283fbdba9..873b341774 100644
--- a/object-store.h
+++ b/object-store.h
@@ -24,8 +24,7 @@ struct alternate_object_database {
 */
char path[FLEX_ARRAY];
 };
-#define prepare_alt_odb(r) prepare_alt_odb_##r()
-void prepare_alt_odb_the_repository(void);
+void prepare_alt_odb(struct repository *r);
 char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 int foreach_alt_odb(alt_odb_fn, void*);
diff --git a/sha1_file.c b/sha1_file.c
index 6e5105a252..9cf3fffbeb 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -673,21 +673,22 @@ int foreach_alt_odb(alt_odb_fn fn, void *cb)
return r;
 }
 
-void prepare_alt_odb_the_repository(void)
+void prepare_alt_odb(struct repository *r)
 {
-   const char *alt;
-
-   if (the_repository->objects.alt_odb_tail)
+   if (r->objects.alt_odb_tail)
return;
 
-   alt = getenv(ALTERNATE_DB_ENVIRONMENT);
+   r->objects.alt_odb_tail = >objects.alt_odb_list;
+
+   if (!r->ignore_env) {
+   const char *alt = getenv(ALTERNATE_DB_ENVIRONMENT);
+   if (!alt)
+   alt = "";
 
-   the_repository->objects.alt_odb_tail =
-   _repository->objects.alt_odb_list;
-   link_alt_odb_entries(the_repository, alt,
-PATH_SEP, NULL, 0);
+   link_alt_odb_entries(r, alt, PATH_SEP, NULL, 0);
+   }
 
-   read_info_alternates(the_repository, get_object_directory(), 0);
+   read_info_alternates(r, r->objects.objectdir, 0);
 }
 
 /* Returns 1 if we have successfully freshened the file, 0 otherwise. */
-- 
2.16.1.291.g4437f3f132-goog