object.h: move some inline functions and defines from cache.h

The object_type() inline function is very tied to the enum object_type declaration within object.h, and just seemed to make more sense to live there. That makes S_ISGITLINK and some other defines make sense to go with it, as well as the create_ce_mode() and canon_mode() inline functions. Move all these inline functions and defines from cache.h to object.h. Signed-off-by: Elijah Newren <newren@gmail.com> Acked-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 11, 2023 at 00:41 UTC 8876ea83a74b45046c3dabdd5f55f07852bb98ae
2 files changed +44 -42
cache.h
-42
@@ -28,18 +28,6 @@
28 #define DTYPE(de) DT_UNKNOWN
29 #endif
30
31 -/* unknown mode (impossible combination S_IFIFO|S_IFCHR) */
32 -#define S_IFINVALID 0030000
33 -
34 -/*
35 - * A "directory link" is a link to another git directory.
36 - *
37 - * The value 0160000 is not normally a valid mode, and
38 - * also just happens to be S_IFDIR + S_IFLNK
39 - */
40 -#define S_IFGITLINK 0160000
41 -#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
42 -
31 /*
32 * Some mode bits are also used internally for computations.
33 *
@@ -155,8 +143,6 @@ struct cache_entry {
143 #error "CE_EXTENDED_FLAGS out of range"
144 #endif
145
158 -#define S_ISSPARSEDIR(m) ((m) == S_IFDIR)
159 -
146 /* Forward structure decls */
147 struct pathspec;
148 struct child_process;
@@ -197,17 +183,6 @@ static inline unsigned create_ce_flags(unsigned stage)
183 #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
184 #define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
185
200 -#define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
201 -static inline unsigned int create_ce_mode(unsigned int mode)
202 -{
203 - if (S_ISLNK(mode))
204 - return S_IFLNK;
205 - if (S_ISSPARSEDIR(mode))
206 - return S_IFDIR;
207 - if (S_ISDIR(mode) || S_ISGITLINK(mode))
208 - return S_IFGITLINK;
209 - return S_IFREG | ce_permissions(mode);
210 -}
186 static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
187 unsigned int mode)
188 {
@@ -234,16 +209,6 @@ static inline int ce_to_dtype(const struct cache_entry *ce)
209 else
210 return DT_UNKNOWN;
211 }
237 -static inline unsigned int canon_mode(unsigned int mode)
238 -{
239 - if (S_ISREG(mode))
240 - return S_IFREG | ce_permissions(mode);
241 - if (S_ISLNK(mode))
242 - return S_IFLNK;
243 - if (S_ISDIR(mode))
244 - return S_IFDIR;
245 - return S_IFGITLINK;
246 -}
212
213 static inline int ce_path_match(struct index_state *istate,
214 const struct cache_entry *ce,
@@ -414,13 +379,6 @@ void prefetch_cache_entries(const struct index_state *istate,
379 extern struct index_state the_index;
380 #endif
381
417 -static inline enum object_type object_type(unsigned int mode)
418 -{
419 - return S_ISDIR(mode) ? OBJ_TREE :
420 - S_ISGITLINK(mode) ? OBJ_COMMIT :
421 - OBJ_BLOB;
422 -}
423 -
382 #define INIT_DB_QUIET 0x0001
383 #define INIT_DB_EXIST_OK 0x0002
384
object.h
+44
@@ -101,6 +101,50 @@ enum object_type {
101 OBJ_MAX
102 };
103
104 +/* unknown mode (impossible combination S_IFIFO|S_IFCHR) */
105 +#define S_IFINVALID 0030000
106 +
107 +/*
108 + * A "directory link" is a link to another git directory.
109 + *
110 + * The value 0160000 is not normally a valid mode, and
111 + * also just happens to be S_IFDIR + S_IFLNK
112 + */
113 +#define S_IFGITLINK 0160000
114 +#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
115 +
116 +#define S_ISSPARSEDIR(m) ((m) == S_IFDIR)
117 +
118 +static inline enum object_type object_type(unsigned int mode)
119 +{
120 + return S_ISDIR(mode) ? OBJ_TREE :
121 + S_ISGITLINK(mode) ? OBJ_COMMIT :
122 + OBJ_BLOB;
123 +}
124 +
125 +#define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
126 +static inline unsigned int create_ce_mode(unsigned int mode)
127 +{
128 + if (S_ISLNK(mode))
129 + return S_IFLNK;
130 + if (S_ISSPARSEDIR(mode))
131 + return S_IFDIR;
132 + if (S_ISDIR(mode) || S_ISGITLINK(mode))
133 + return S_IFGITLINK;
134 + return S_IFREG | ce_permissions(mode);
135 +}
136 +
137 +static inline unsigned int canon_mode(unsigned int mode)
138 +{
139 + if (S_ISREG(mode))
140 + return S_IFREG | ce_permissions(mode);
141 + if (S_ISLNK(mode))
142 + return S_IFLNK;
143 + if (S_ISDIR(mode))
144 + return S_IFDIR;
145 + return S_IFGITLINK;
146 +}
147 +
148 /*
149 * The object type is stored in 3 bits.
150 */