Subject: Re: [PATCH 14/23] hash.h, repository.h: reverse the order of these dependencies

From: Derrick Stolee <[email-masked]>
Date: Mon, 17 Apr 2023 16:59:42 -0400

On 4/15/2023 11:03 PM, Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <[email-masked]>
> 
> Previously, hash.h depended upon and included repository.h, due to
> the definition and use of the_hash_algo (defined as
> the_repository->hash_algo).  Move this #define, and the associated
> inline functions that depend upon it, from hash.h to repository.h.
> Due to that movement, reverse the dependencies so repository.h includes
> hash.h.
> 
> This allows hash.h and object.h to be fairly small, minimal headers.  It
> also exposes a lot of hidden dependencies on both path.h (which was
> brought in by repository.h) and repository.h (which was previously
> implicitly brought in by object.h).

This is the first patch in the series where I don't immediately agree
with the patch. This is a big list of methods that don't seem like
they fit in repository.h:

> diff --git a/repository.h b/repository.h
> +static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
> +static inline int oidcmp(const struct object_id *oid1, const struct object_id *oid2)
> +static inline int hasheq(const unsigned char *sha1, const unsigned char *sha2)
> +static inline int oideq(const struct object_id *oid1, const struct object_id *oid2)
> +static inline int is_null_oid(const struct object_id *oid)
> +static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
> +static inline void oidcpy_with_padding(struct object_id *dst,
> +				       const struct object_id *src)
> +static inline void hashclr(unsigned char *hash)
> +static inline void oidclr(struct object_id *oid)
> +static inline void oidread(struct object_id *oid, const unsigned char *hash)
> +static inline int is_empty_blob_sha1(const unsigned char *sha1)
> +static inline int is_empty_blob_oid(const struct object_id *oid)
> +static inline int is_empty_tree_sha1(const unsigned char *sha1)
> +static inline int is_empty_tree_oid(const struct object_id *oid)

The goal to remove repository.h from hash.h and object.h makes sense
as a goal, but is there another way to do it? Can we redefine
'extern struct repository *the_repository;' in hash.h so we have
access to that pointer?

Thanks,
-Stolee