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 <gitster@pobox.com>
Junio C Hamano committed
Apr 3, 2012 at 15:53 UTC
db3b313c84522d89ac358187a7f6928dfcfb1e7d
2 files changed
+54
-48
cache.h
-48
@@ -115,48 +115,6 @@ struct cache_time {
115
unsigned int nsec;
116
};
117
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
-
118
struct cache_entry {
119
struct cache_time ce_ctime;
120
struct cache_time ce_mtime;
@@ -253,9 +211,6 @@ static inline size_t ce_namelen(const struct cache_entry *ce)
211
}
212
213
#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)))
214
#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
215
#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
216
#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
@@ -306,10 +261,7 @@ static inline unsigned int canon_mode(unsigned int mode)
261
return S_IFGITLINK;
262
}
263
309
-#define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
264
#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)
265
266
struct index_state {
267
struct cache_entry **cache;
read-cache.c
+54
@@ -1189,6 +1189,60 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
1189
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
1190
}
1191
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
+
1246
static int verify_hdr(struct cache_header *hdr, unsigned long size)
1247
{
1248
git_SHA_CTX c;