mirror of
https://github.com/git/git.git
synced 2025-03-13 20:15:19 +00:00
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>
This commit is contained in:
parent
d2c1898571
commit
db3b313c84
48
cache.h
48
cache.h
@ -115,48 +115,6 @@ struct cache_time {
|
|||||||
unsigned int nsec;
|
unsigned int nsec;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* dev/ino/uid/gid/size are also just tracked to the low 32 bits
|
|
||||||
* Again - this is just a (very strong in practice) heuristic that
|
|
||||||
* the inode hasn't changed.
|
|
||||||
*
|
|
||||||
* We save the fields in big-endian order to allow using the
|
|
||||||
* index file over NFS transparently.
|
|
||||||
*/
|
|
||||||
struct ondisk_cache_entry {
|
|
||||||
struct cache_time ctime;
|
|
||||||
struct cache_time mtime;
|
|
||||||
unsigned int dev;
|
|
||||||
unsigned int ino;
|
|
||||||
unsigned int mode;
|
|
||||||
unsigned int uid;
|
|
||||||
unsigned int gid;
|
|
||||||
unsigned int size;
|
|
||||||
unsigned char sha1[20];
|
|
||||||
unsigned short flags;
|
|
||||||
char name[FLEX_ARRAY]; /* more */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This struct is used when CE_EXTENDED bit is 1
|
|
||||||
* The struct must match ondisk_cache_entry exactly from
|
|
||||||
* ctime till flags
|
|
||||||
*/
|
|
||||||
struct ondisk_cache_entry_extended {
|
|
||||||
struct cache_time ctime;
|
|
||||||
struct cache_time mtime;
|
|
||||||
unsigned int dev;
|
|
||||||
unsigned int ino;
|
|
||||||
unsigned int mode;
|
|
||||||
unsigned int uid;
|
|
||||||
unsigned int gid;
|
|
||||||
unsigned int size;
|
|
||||||
unsigned char sha1[20];
|
|
||||||
unsigned short flags;
|
|
||||||
unsigned short flags2;
|
|
||||||
char name[FLEX_ARRAY]; /* more */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cache_entry {
|
struct cache_entry {
|
||||||
struct cache_time ce_ctime;
|
struct cache_time ce_ctime;
|
||||||
struct cache_time ce_mtime;
|
struct cache_time ce_mtime;
|
||||||
@ -253,9 +211,6 @@ static inline size_t ce_namelen(const struct cache_entry *ce)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
|
#define ce_size(ce) cache_entry_size(ce_namelen(ce))
|
||||||
#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \
|
|
||||||
ondisk_cache_entry_extended_size(ce_namelen(ce)) : \
|
|
||||||
ondisk_cache_entry_size(ce_namelen(ce)))
|
|
||||||
#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
|
#define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
|
||||||
#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
|
#define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
|
||||||
#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
|
#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
|
||||||
@ -306,10 +261,7 @@ static inline unsigned int canon_mode(unsigned int mode)
|
|||||||
return S_IFGITLINK;
|
return S_IFGITLINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
|
|
||||||
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
|
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
|
||||||
#define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len)
|
|
||||||
#define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len)
|
|
||||||
|
|
||||||
struct index_state {
|
struct index_state {
|
||||||
struct cache_entry **cache;
|
struct cache_entry **cache;
|
||||||
|
54
read-cache.c
54
read-cache.c
@ -1189,6 +1189,60 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
|
|||||||
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
|
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
* Index File I/O
|
||||||
|
*****************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dev/ino/uid/gid/size are also just tracked to the low 32 bits
|
||||||
|
* Again - this is just a (very strong in practice) heuristic that
|
||||||
|
* the inode hasn't changed.
|
||||||
|
*
|
||||||
|
* We save the fields in big-endian order to allow using the
|
||||||
|
* index file over NFS transparently.
|
||||||
|
*/
|
||||||
|
struct ondisk_cache_entry {
|
||||||
|
struct cache_time ctime;
|
||||||
|
struct cache_time mtime;
|
||||||
|
unsigned int dev;
|
||||||
|
unsigned int ino;
|
||||||
|
unsigned int mode;
|
||||||
|
unsigned int uid;
|
||||||
|
unsigned int gid;
|
||||||
|
unsigned int size;
|
||||||
|
unsigned char sha1[20];
|
||||||
|
unsigned short flags;
|
||||||
|
char name[FLEX_ARRAY]; /* more */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This struct is used when CE_EXTENDED bit is 1
|
||||||
|
* The struct must match ondisk_cache_entry exactly from
|
||||||
|
* ctime till flags
|
||||||
|
*/
|
||||||
|
struct ondisk_cache_entry_extended {
|
||||||
|
struct cache_time ctime;
|
||||||
|
struct cache_time mtime;
|
||||||
|
unsigned int dev;
|
||||||
|
unsigned int ino;
|
||||||
|
unsigned int mode;
|
||||||
|
unsigned int uid;
|
||||||
|
unsigned int gid;
|
||||||
|
unsigned int size;
|
||||||
|
unsigned char sha1[20];
|
||||||
|
unsigned short flags;
|
||||||
|
unsigned short flags2;
|
||||||
|
char name[FLEX_ARRAY]; /* more */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define align_flex_name(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
|
||||||
|
#define ondisk_cache_entry_size(len) align_flex_name(ondisk_cache_entry,len)
|
||||||
|
#define ondisk_cache_entry_extended_size(len) align_flex_name(ondisk_cache_entry_extended,len)
|
||||||
|
#define ondisk_ce_size(ce) (((ce)->ce_flags & CE_EXTENDED) ? \
|
||||||
|
ondisk_cache_entry_extended_size(ce_namelen(ce)) : \
|
||||||
|
ondisk_cache_entry_size(ce_namelen(ce)))
|
||||||
|
|
||||||
static int verify_hdr(struct cache_header *hdr, unsigned long size)
|
static int verify_hdr(struct cache_header *hdr, unsigned long size)
|
||||||
{
|
{
|
||||||
git_SHA_CTX c;
|
git_SHA_CTX c;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user