OSDN Git Service

Update TortoiseUDiff to version 16491
[tortoisegit/TortoiseGitJp.git] / src / Git / gitindex.h
1 /* Copy from Git cache.h*/\r
2 #define FLEX_ARRAY 4\r
3 \r
4 #pragma pack(push)\r
5 #pragma pack(1)\r
6 //#pragma pack(show) \r
7 #define CACHE_SIGNATURE 0x44495243      /* "DIRC" */\r
8 struct cache_header {\r
9         unsigned int hdr_signature;\r
10         unsigned int hdr_version;\r
11         unsigned int hdr_entries;\r
12 };\r
13 \r
14 /*\r
15  * The "cache_time" is just the low 32 bits of the\r
16  * time. It doesn't matter if it overflows - we only\r
17  * check it for equality in the 32 bits we save.\r
18  */\r
19 struct cache_time {\r
20         UINT32 sec;\r
21         UINT32 nsec;\r
22 };\r
23 \r
24 /*\r
25  * dev/ino/uid/gid/size are also just tracked to the low 32 bits\r
26  * Again - this is just a (very strong in practice) heuristic that\r
27  * the inode hasn't changed.\r
28  *\r
29  * We save the fields in big-endian order to allow using the\r
30  * index file over NFS transparently.\r
31  */\r
32 struct ondisk_cache_entry {\r
33         struct cache_time ctime;\r
34         struct cache_time mtime;\r
35         UINT32 dev;\r
36         UINT32 ino;\r
37         UINT32 mode;\r
38         UINT32 uid;\r
39         UINT32 gid;\r
40         UINT32 size;\r
41         BYTE sha1[20];\r
42         UINT16 flags;\r
43         char name[FLEX_ARRAY]; /* more */\r
44 };\r
45 \r
46 /*\r
47  * This struct is used when CE_EXTENDED bit is 1\r
48  * The struct must match ondisk_cache_entry exactly from\r
49  * ctime till flags\r
50  */\r
51 struct ondisk_cache_entry_extended {\r
52         struct cache_time ctime;\r
53         struct cache_time mtime;\r
54         UINT32 dev;\r
55         UINT32 ino;\r
56         UINT32 mode;\r
57         UINT32 uid;\r
58         UINT32 gid;\r
59         UINT32 size;\r
60         BYTE sha1[20];\r
61         UINT16 flags;\r
62         UINT16 flags2;\r
63         char name[FLEX_ARRAY]; /* more */\r
64 };\r
65 \r
66 #pragma pack(pop)\r
67 \r
68 #define CE_NAMEMASK  (0x0fff)\r
69 #define CE_STAGEMASK (0x3000)\r
70 #define CE_EXTENDED  (0x4000)\r
71 #define CE_VALID     (0x8000)\r
72 #define CE_STAGESHIFT 12\r
73 /*\r
74  * Range 0xFFFF0000 in ce_flags is divided into\r
75  * two parts: in-memory flags and on-disk ones.\r
76  * Flags in CE_EXTENDED_FLAGS will get saved on-disk\r
77  * if you want to save a new flag, add it in\r
78  * CE_EXTENDED_FLAGS\r
79  *\r
80  * In-memory only flags\r
81  */\r
82 #define CE_UPDATE    (0x10000)\r
83 #define CE_REMOVE    (0x20000)\r
84 #define CE_UPTODATE  (0x40000)\r
85 #define CE_ADDED     (0x80000)\r
86 \r
87 #define CE_HASHED    (0x100000)\r
88 #define CE_UNHASHED  (0x200000)\r
89 \r
90 /*\r
91  * Extended on-disk flags\r
92  */\r
93 #define CE_INTENT_TO_ADD 0x20000000\r
94 /* CE_EXTENDED2 is for future extension */\r
95 #define CE_EXTENDED2 0x80000000\r
96 \r
97 #define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD)\r
98 \r
99 /*\r
100  * Safeguard to avoid saving wrong flags:\r
101  *  - CE_EXTENDED2 won't get saved until its semantic is known\r
102  *  - Bits in 0x0000FFFF have been saved in ce_flags already\r
103  *  - Bits in 0x003F0000 are currently in-memory flags\r
104  */\r
105 #if CE_EXTENDED_FLAGS & 0x803FFFFF\r
106 #error "CE_EXTENDED_FLAGS out of range"\r
107 #endif\r
108 \r
109 /*\r
110  * Copy the sha1 and stat state of a cache entry from one to\r
111  * another. But we never change the name, or the hash state!\r
112  */\r
113 #define CE_STATE_MASK (CE_HASHED | CE_UNHASHED)\r
114 \r
115 template<class T> \r
116 T Big2lit(T data)\r
117 {\r
118         T ret;\r
119         BYTE *p1=(BYTE*)&data;\r
120         BYTE *p2=(BYTE*)&ret;\r
121         for(int i=0;i<sizeof(T);i++)\r
122         {\r
123                 p2[sizeof(T)-i-1] = p1[i];\r
124         }\r
125         return ret;\r
126 }\r
127 \r
128 template<class T>\r
129 static inline size_t ce_namelen(T *ce)\r
130 {\r
131         size_t len = Big2lit(ce->flags) & CE_NAMEMASK;\r
132         if (len < CE_NAMEMASK)\r
133                 return len;\r
134         return strlen(ce->name + CE_NAMEMASK) + CE_NAMEMASK;\r
135 }\r
136 \r
137 #define flexible_size(STRUCT,len) ((offsetof(STRUCT,name) + (len) + 8) & ~7)\r
138 \r
139 //#define ondisk_cache_entry_size(len) flexible_size(ondisk_cache_entry,len)\r
140 //#define ondisk_cache_entry_extended_size(len) flexible_size(ondisk_cache_entry_extended,len)\r
141 \r
142 //#define ondisk_ce_size(ce) (((ce)->flags & CE_EXTENDED) ? \\r
143 //                          ondisk_cache_entry_extended_size(ce_namelen(ce)) : \\r
144 //                          ondisk_cache_entry_size(ce_namelen(ce)))\r
145 \r
146 template<class T>\r
147 static inline size_t ondisk_ce_size(T *ce)\r
148 {\r
149         return flexible_size(T,ce_namelen(ce));\r
150 }\r
151 \r
152 class CGitIndex\r
153 {\r
154 public:\r
155         CString    m_FileName;\r
156         __time64_t m_ModifyTime;\r
157         int                m_Flags;\r
158         //int            m_Status;\r
159         \r
160         int FillData(ondisk_cache_entry* entry);\r
161         int FillData(ondisk_cache_entry_extended* entry);\r
162 };\r
163 \r
164 \r
165 typedef void (*FIll_STATUS_CALLBACK)(CString &path,git_wc_status_kind status,void *pdata);\r
166 \r
167 class CGitIndexList:public std::vector<CGitIndex>\r
168 {\r
169 protected:\r
170         \r
171 public:\r
172         std::map<CString,int> m_Map;\r
173         __time64_t m_LastModifyTime;\r
174         CGitIndexList();\r
175         int ReadIndex(CString file);\r
176         int GetStatus(CString &gitdir,CString &path,git_wc_status_kind * status,BOOL IsFull=false, BOOL IsRecursive=false,FIll_STATUS_CALLBACK callback=NULL,void *pData=NULL); \r
177 protected:\r
178         int GetFileStatus(CString &gitdir,CString &path, git_wc_status_kind * status,struct __stat64 &buf,FIll_STATUS_CALLBACK callback=NULL,void *pData=NULL);\r
179 \r
180 };\r
181 \r
182 class CGitIndexFileMap:public std::map<CString,CGitIndexList> \r
183 {\r
184 public:\r
185         int GetFileStatus(CString &gitdir,CString &path,git_wc_status_kind * status,BOOL IsFull=false, BOOL IsRecursive=false,FIll_STATUS_CALLBACK callback=NULL,void *pData=NULL);\r
186 };\r
187 \r