Skip to content

Commit db3b313

Browse files
committed
cache.h: hide on-disk index details
The on-disk format of the index file is a detail whose implementation is neatly encapsulated in read-cache.c; there is no need to expose it to the general public that include the cache.h header file. Also add a prominent mark to read-cache.c to delineate the parts that deal with the index file I/O routines from the remainder of the file. Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2c1898 commit db3b313

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

cache.h

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -115,48 +115,6 @@ struct cache_time {
115115
unsigned int nsec;
116116
};
117117

118-
/*
119-
* dev/ino/uid/gid/size are also just tracked to the low 32 bits
120-
* Again - this is just a (very strong in practice) heuristic that
121-
* the inode hasn't changed.
122-
*
123-
* We save the fields in big-endian order to allow using the
124-
* index file over NFS transparently.
125-
*/
126-
struct ondisk_cache_entry {
127-
struct cache_time ctime;
128-
struct cache_time mtime;
129-
unsigned int dev;
130-
unsigned int ino;
131-
unsigned int mode;
132-
unsigned int uid;
133-
unsigned int gid;
134-
unsigned int size;
135-
unsigned char sha1[20];
136-
unsigned short flags;
137-
char name[FLEX_ARRAY]; /* more */
138-
};
139-
140-
/*
141-
* This struct is used when CE_EXTENDED bit is 1
142-
* The struct must match ondisk_cache_entry exactly from
143-
* ctime till flags
144-
*/
145-
struct ondisk_cache_entry_extended {
146-
struct cache_time ctime;
147-
struct cache_time mtime;
148-
unsigned int dev;
149-
unsigned int ino;
150-
unsigned int mode;
151-
unsigned int uid;
152-
unsigned int gid;
153-
unsigned int size;
154-
unsigned char sha1[20];
155-
unsigned short flags;
156-
unsigned short flags2;
157-
char name[FLEX_ARRAY]; /* more */
158-
};
159-
160118
struct cache_entry {
161119
struct cache_time ce_ctime;
162120
struct cache_time ce_mtime;
@@ -253,9 +211,6 @@ static inline size_t ce_namelen(const struct cache_entry *ce)
253211
}
254212

255213
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
256-
#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \
257-
ondisk_cache_entry_extended_size(ce_namelen(ce)) : \
258-
ondisk_cache_entry_size(ce_namelen(ce)))
259214
#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
260215
#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
261216
#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
@@ -306,10 +261,7 @@ static inline unsigned int canon_mode(unsigned int mode)
306261
return S_IFGITLINK;
307262
}
308263

309-
#define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
310264
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
311-
#define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len)
312-
#define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len)
313265

314266
struct index_state {
315267
struct cache_entry **cache;

read-cache.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,60 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
11891189
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
11901190
}
11911191

1192+
1193+
/*****************************************************************
1194+
* Index File I/O
1195+
*****************************************************************/
1196+
1197+
/*
1198+
* dev/ino/uid/gid/size are also just tracked to the low 32 bits
1199+
* Again - this is just a (very strong in practice) heuristic that
1200+
* the inode hasn't changed.
1201+
*
1202+
* We save the fields in big-endian order to allow using the
1203+
* index file over NFS transparently.
1204+
*/
1205+
struct ondisk_cache_entry {
1206+
struct cache_time ctime;
1207+
struct cache_time mtime;
1208+
unsigned int dev;
1209+
unsigned int ino;
1210+
unsigned int mode;
1211+
unsigned int uid;
1212+
unsigned int gid;
1213+
unsigned int size;
1214+
unsigned char sha1[20];
1215+
unsigned short flags;
1216+
char name[FLEX_ARRAY]; /* more */
1217+
};
1218+
1219+
/*
1220+
* This struct is used when CE_EXTENDED bit is 1
1221+
* The struct must match ondisk_cache_entry exactly from
1222+
* ctime till flags
1223+
*/
1224+
struct ondisk_cache_entry_extended {
1225+
struct cache_time ctime;
1226+
struct cache_time mtime;
1227+
unsigned int dev;
1228+
unsigned int ino;
1229+
unsigned int mode;
1230+
unsigned int uid;
1231+
unsigned int gid;
1232+
unsigned int size;
1233+
unsigned char sha1[20];
1234+
unsigned short flags;
1235+
unsigned short flags2;
1236+
char name[FLEX_ARRAY]; /* more */
1237+
};
1238+
1239+
#define align_flex_name(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
1240+
#define ondisk_cache_entry_size(len) align_flex_name(ondisk_cache_entry,len)
1241+
#define ondisk_cache_entry_extended_size(len) align_flex_name(ondisk_cache_entry_extended,len)
1242+
#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \
1243+
ondisk_cache_entry_extended_size(ce_namelen(ce)) : \
1244+
ondisk_cache_entry_size(ce_namelen(ce)))
1245+
11921246
static int verify_hdr(struct cache_header *hdr, unsigned long size)
11931247
{
11941248
git_SHA_CTX c;

0 commit comments

Comments
 (0)