Thread (103 messages) flat view 103 messages, 6 authors, 2018-02-28
STALE3113d

Revision v3 of 2 in this series.

Revisions (2)
  1. v2 [diff vs current]
  2. v3 current

[PATCH v3 3/6] cache.h: make the_hash_algo read-only

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2018-02-25 11:19:12
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help