Skip to content

Commit 8876ea8

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Acked-by: Calvin Wan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6fdc44 commit 8876ea8

File tree

2 files changed

+44
-42
lines changed

2 files changed

+44
-42
lines changed

cache.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@
2828
#define DTYPE(de) DT_UNKNOWN
2929
#endif
3030

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-
4331
/*
4432
* Some mode bits are also used internally for computations.
4533
*
@@ -155,8 +143,6 @@ struct cache_entry {
155143
#error "CE_EXTENDED_FLAGS out of range"
156144
#endif
157145

158-
#define S_ISSPARSEDIR(m) ((m) == S_IFDIR)
159-
160146
/* Forward structure decls */
161147
struct pathspec;
162148
struct child_process;
@@ -197,17 +183,6 @@ static inline unsigned create_ce_flags(unsigned stage)
197183
#define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
198184
#define ce_intent_to_add(ce) ((ce)->ce_flags & CE_INTENT_TO_ADD)
199185

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-
}
211186
static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
212187
unsigned int mode)
213188
{
@@ -234,16 +209,6 @@ static inline int ce_to_dtype(const struct cache_entry *ce)
234209
else
235210
return DT_UNKNOWN;
236211
}
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-
}
247212

248213
static inline int ce_path_match(struct index_state *istate,
249214
const struct cache_entry *ce,
@@ -414,13 +379,6 @@ void prefetch_cache_entries(const struct index_state *istate,
414379
extern struct index_state the_index;
415380
#endif
416381

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-
424382
#define INIT_DB_QUIET 0x0001
425383
#define INIT_DB_EXIST_OK 0x0002
426384

object.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,50 @@ enum object_type {
101101
OBJ_MAX
102102
};
103103

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+
104148
/*
105149
* The object type is stored in 3 bits.
106150
*/

0 commit comments

Comments
 (0)