[PATCH v3 3/6] cache.h: make the_hash_algo read-only
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- Feb 25, 2018, 11:18 UTC
- Message-ID
- <20180225111840.16421-4-pclouds@gmail.com>
- In-Reply-To
- <20180225111840.16421-1-pclouds@gmail.com>
By returning an R-value in the_hash_algo we make sure people can't accidentally change hash algorithm with
the_hash_algo = &hash_algos[something];
and go with repo_set_hash_algo() instead. Of course they can still do
the_repository->hash_algo = ...
but that is more obvious and easily caught in review.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- cache.h | 2 +- repository.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/cache.h b/cache.h index 6b97138264..55b31e9756 100644 --- a/cache.h +++ b/cache.h @@ -53,7 +53,7 @@ struct object_id { unsigned char hash[GIT_MAX_RAWSZ]; }; -#define the_hash_algo the_repository->hash_algo +#define the_hash_algo repo_get_hash_algo(the_repository) #if defined(DT_UNKNOWN) && !defined(NO_D_TYPE_IN_DIRENT) #define DTYPE(de) ((de)->d_type) diff --git a/repository.h b/repository.h index 0329e40c7f..5092df3700 100644 --- a/repository.h +++ b/repository.h @@ -107,4 +107,10 @@ extern void repo_clear(struct repository *repo); */ extern int repo_read_index(struct repository *repo); +static inline const struct git_hash_algo *repo_get_hash_algo( + const struct repository *repo) +{ + return repo->hash_algo; +} + #endif /* REPOSITORY_H */
-- 2.16.1.435.g8f24da2e1a