threads / patch / 46595

patchsha1_file: make read_info_alternates static

Subject: [PATCH] sha1_file: make read_info_alternates static

## tl;dr

3 messages between Aug 15, 2017 and Aug 15, 2017. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Stefan Beller· Aug 15, 2017, 20:13 UTC · lore
read_info_alternates is not used from outside, so let's make it static.

We have to declare the function before link_alt_odb_entry instead of moving the code around, link_alt_odb_entry calls read_info_alternates, which in turn calls link_alt_odb_entry.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
  This helps in a later refactoring (moving the object
  store to the_repository struct), too.
  
  Thanks,
  Stefan
 cache.h     | 1 -
 sha1_file.c | 3 ++-
 2 files changed, 2 insertions(+), 2 deletions(-)
Show changes to 2 files +2 −2

cache.h, sha1_file.c

diff --git a/cache.h b/cache.h
index 1c69d2a05a..4109efcf24 100644
--- a/cache.h
+++ b/cache.h
@@ -1551,7 +1551,6 @@ extern struct alternate_object_database {
 	char path[FLEX_ARRAY];
 } *alt_odb_list;
 extern void prepare_alt_odb(void);
-extern void read_info_alternates(const char * relative_base, int depth);
 extern char *compute_alternate_path(const char *path, struct strbuf *err);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 extern int foreach_alt_odb(alt_odb_fn, void*);
diff --git a/sha1_file.c b/sha1_file.c
index b60ae15f70..9186e2c6c7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -347,6 +347,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
  * SHA1, an extra slash for the first level indirection, and the
  * terminating NUL.
  */
+static void read_info_alternates(const char * relative_base, int depth);
 static int link_alt_odb_entry(const char *entry, const char *relative_base,
 	int depth, const char *normalized_objdir)
 {
@@ -448,7 +449,7 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
 	strbuf_release(&objdirbuf);
 }
 
-void read_info_alternates(const char * relative_base, int depth)
+static void read_info_alternates(const char * relative_base, int depth)
 {
 	char *map;
 	size_t mapsz;
-- 
2.14.0.rc0.3.g6c2e499285
Brandon Williams· Aug 15, 2017, 21:31 UTC · re: Stefan Beller · lore

Re: [PATCH] sha1_file: make read_info_alternates static

On 08/15, Stefan Beller wrote:
Show 55 quoted lines
> read_info_alternates is not used from outside, so let's make it static.
> 
> We have to declare the function before link_alt_odb_entry instead of
> moving the code around, link_alt_odb_entry calls read_info_alternates,
> which in turn calls link_alt_odb_entry.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> 
>   This helps in a later refactoring (moving the object
>   store to the_repository struct), too.
>   
>   Thanks,
>   Stefan
> 
>  cache.h     | 1 -
>  sha1_file.c | 3 ++-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cache.h b/cache.h
> index 1c69d2a05a..4109efcf24 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -1551,7 +1551,6 @@ extern struct alternate_object_database {
>  	char path[FLEX_ARRAY];
>  } *alt_odb_list;
>  extern void prepare_alt_odb(void);
> -extern void read_info_alternates(const char * relative_base, int depth);
>  extern char *compute_alternate_path(const char *path, struct strbuf *err);
>  typedef int alt_odb_fn(struct alternate_object_database *, void *);
>  extern int foreach_alt_odb(alt_odb_fn, void*);
> diff --git a/sha1_file.c b/sha1_file.c
> index b60ae15f70..9186e2c6c7 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -347,6 +347,7 @@ static int alt_odb_usable(struct strbuf *path, const char *normalized_objdir)
>   * SHA1, an extra slash for the first level indirection, and the
>   * terminating NUL.
>   */
> +static void read_info_alternates(const char * relative_base, int depth);
>  static int link_alt_odb_entry(const char *entry, const char *relative_base,
>  	int depth, const char *normalized_objdir)
>  {
> @@ -448,7 +449,7 @@ static void link_alt_odb_entries(const char *alt, int len, int sep,
>  	strbuf_release(&objdirbuf);
>  }
>  
> -void read_info_alternates(const char * relative_base, int depth)
> +static void read_info_alternates(const char * relative_base, int depth)
>  {
>  	char *map;
>  	size_t mapsz;
> -- 
> 2.14.0.rc0.3.g6c2e499285
> 

Looks good to me. Only nit is I would fix the style to not have a space after the '*' ;)

-- 
Brandon Williams
Jeff King· Aug 15, 2017, 21:34 UTC · re: Stefan Beller · lore

Re: [PATCH] sha1_file: make read_info_alternates static

On Tue, Aug 15, 2017 at 01:13:19PM -0700, Stefan Beller wrote:
Show 7 quoted lines
> read_info_alternates is not used from outside, so let's make it static.
> 
> We have to declare the function before link_alt_odb_entry instead of
> moving the code around, link_alt_odb_entry calls read_info_alternates,
> which in turn calls link_alt_odb_entry.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>

Thanks, this looks good. It should have been part of my series with a5b34d2152 (alternates: provide helper for adding to alternates list, 2016-10-03), which removed the last external call.

-Peff

← back to recent threads