OSDN Git Service

Fix 'Explore To' in context menu in Commit Dialog
[tortoisegit/TortoiseGitJp.git] / src / Git / GitStatus.h
1 #pragma once\r
2 \r
3 #ifdef _MFC_VER\r
4 //#     include "SVNPrompt.h"\r
5 #endif\r
6 #include "TGitPath.h"\r
7 \r
8 #pragma warning (push,1)\r
9 typedef std::basic_string<wchar_t> wide_string;\r
10 #ifdef UNICODE\r
11 #       define stdstring wide_string\r
12 #else\r
13 #       define stdstring std::string\r
14 #endif\r
15 #pragma warning (pop)\r
16 \r
17 #include "TGitPath.h"\r
18 #include "../../ext/wingit/wingit.h"\r
19 \r
20 typedef enum type_git_wc_status_kind\r
21 {\r
22         git_wc_status_none,\r
23         git_wc_status_unversioned,\r
24         git_wc_status_ignored,\r
25         git_wc_status_normal,\r
26         git_wc_status_external,\r
27         git_wc_status_incomplete,\r
28         git_wc_status_missing,\r
29         git_wc_status_deleted,\r
30         git_wc_status_replaced,\r
31         git_wc_status_modified,\r
32         git_wc_status_merged,\r
33         git_wc_status_added,\r
34         git_wc_status_conflicted,\r
35         git_wc_status_obstructed,\r
36 \r
37 }git_wc_status_kind;\r
38 \r
39 typedef enum\r
40 {\r
41         git_depth_empty,\r
42         git_depth_infinity,\r
43         git_depth_unknown,\r
44         git_depth_files,\r
45         git_depth_immediates,\r
46 }git_depth_t;\r
47 \r
48 \r
49 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")\r
50 #define GIT_INVALID_REVNUM _T("")\r
51 typedef CString git_revnum_t;\r
52 typedef int git_error_t;\r
53 \r
54 typedef struct git_wc_status2_t\r
55\r
56   /** The status of the entries text. */\r
57   git_wc_status_kind text_status;\r
58 \r
59   /** The status of the entries properties. */\r
60   git_wc_status_kind prop_status;\r
61 }git_wc_status2;\r
62 \r
63 #define MAX_STATUS_STRING_LENGTH                256\r
64 \r
65 \r
66 // convert wingit.dll status to git_wc_status_kind\r
67 inline static git_wc_status_kind GitStatusFromWingit(int nStatus)\r
68 {\r
69         switch (nStatus)\r
70         {\r
71         case WGFS_Normal: return git_wc_status_normal;\r
72         case WGFS_Modified: return git_wc_status_modified;\r
73         //case WGFS_Staged: return git_wc_status_modified;\r
74         //case WGFS_Added: return git_wc_status_added;\r
75         case WGFS_Conflicted: return git_wc_status_conflicted;\r
76         case WGFS_Deleted: return git_wc_status_deleted;\r
77 \r
78         case WGFS_Empty: return git_wc_status_unversioned;\r
79         }\r
80 \r
81         return git_wc_status_none;\r
82 }\r
83 \r
84 // convert 20 byte sha1 hash to the git_revnum_t type\r
85 inline static git_revnum_t ConvertHashToRevnum(const BYTE *sha1)\r
86 {\r
87         if (!sha1)\r
88                 return GIT_INVALID_REVNUM;\r
89 \r
90         char s[41];\r
91         char *p = s;\r
92         for (int i=0; i<20; i++)\r
93         {\r
94 #pragma warning(push)\r
95 #pragma warning(disable: 4996)\r
96                 sprintf(p, "%02x", (UINT)*sha1);\r
97 #pragma warning(pop)\r
98                 p += 2;\r
99                 sha1++;\r
100         }\r
101 \r
102         return CString(s);\r
103 }\r
104 \r
105 \r
106 /**\r
107  * \ingroup Git\r
108  * Handles Subversion status of working copies.\r
109  */\r
110 class GitStatus\r
111 {\r
112 public:\r
113         GitStatus(bool * pbCanceled = NULL);\r
114         ~GitStatus(void);\r
115 \r
116 \r
117         /**\r
118          * Reads the Subversion status of the working copy entry. No\r
119          * recurse is done, even if the entry is a directory.\r
120          * If the status of the text and property part are different\r
121          * then the more important status is returned.\r
122          */\r
123         static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty);\r
124 \r
125         /**\r
126          * Reads the Subversion status of the working copy entry and all its\r
127          * subitems. The resulting status is determined by using priorities for\r
128          * each status. The status with the highest priority is then returned.\r
129          * If the status of the text and property part are different then\r
130          * the more important status is returned.\r
131          */\r
132         static git_wc_status_kind GetAllStatusRecursive(const CTGitPath& path);\r
133 \r
134         /**\r
135          * Returns the status which is more "important" of the two statuses specified.\r
136          * This is used for the "recursive" status functions on folders - i.e. which status\r
137          * should be returned for a folder which has several files with different statuses\r
138          * in it.\r
139          */                                     \r
140         static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);\r
141         \r
142         /**\r
143          * Checks if a status is "important", i.e. if the status indicates that the user should know about it.\r
144          * E.g. a "normal" status is not important, but "modified" is.\r
145          * \param status the status to check\r
146          */\r
147         static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}\r
148 \r
149         /**\r
150          * Reads the Subversion text status of the working copy entry. No\r
151          * recurse is done, even if the entry is a directory.\r
152          * The result is stored in the public member variable status.\r
153          * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").\r
154          * \r
155          * \param path the pathname of the entry\r
156          * \param update true if the status should be updated with the repository. Default is false.\r
157          * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.\r
158          * \remark If the return value is -2 then the status could not be obtained.\r
159          */\r
160         git_revnum_t GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);\r
161 \r
162         /**\r
163          * Returns a string representation of a Subversion status.\r
164          * \param status the status enum\r
165          * \param string a string representation\r
166          */\r
167         static void GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string);\r
168         static void GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang);\r
169 \r
170         /**\r
171          * Returns the string representation of a depth.\r
172          */\r
173 #ifdef _MFC_VER\r
174         static CString GetDepthString(git_depth_t depth);\r
175 #endif\r
176         static void GetDepthString(HINSTANCE hInst, git_depth_t depth, TCHAR * string, int size, WORD lang);\r
177 \r
178         /**\r
179          * Returns the status of the first file of the given path. Use GetNextFileStatus() to obtain\r
180          * the status of the next file in the list.\r
181          * \param path the path of the folder from where the status list should be obtained\r
182          * \param retPath the path of the file for which the status was returned\r
183          * \param update set this to true if you want the status to be updated with the repository (needs network access)\r
184          * \param recurse true to fetch the status recursively\r
185          * \param bNoIgnore true to not fetch the ignored files\r
186          * \param bNoExternals true to not fetch the status of included Git:externals\r
187          * \return the status\r
188          */\r
189         git_wc_status2_t * GetFirstFileStatus(const CTGitPath& path, CTGitPath& retPath, bool update = false, git_depth_t depth = git_depth_infinity, bool bNoIgnore = true, bool bNoExternals = false);\r
190         unsigned int GetFileCount() const {return /*apr_hash_count(m_statushash);*/0;}\r
191         unsigned int GetVersionedCount() const;\r
192         /**\r
193          * Returns the status of the next file in the file list. If no more files are in the list then NULL is returned.\r
194          * See GetFirstFileStatus() for details.\r
195          */\r
196         git_wc_status2_t * GetNextFileStatus(CTGitPath& retPath);\r
197         /**\r
198          * Checks if a path is an external folder.\r
199          * This is necessary since Subversion returns two entries for external folders: one with the status Git_wc_status_external\r
200          * and one with the 'real' status of that folder. GetFirstFileStatus() and GetNextFileStatus() only return the 'real'\r
201          * status, so with this method it's possible to check if the status also is Git_wc_status_external.\r
202          */\r
203         bool IsExternal(const CTGitPath& path) const;\r
204         /**\r
205          * Checks if a path is in an external folder.\r
206          */\r
207         bool IsInExternal(const CTGitPath& path) const;\r
208 \r
209         /**\r
210          * Clears the memory pool.\r
211          */\r
212         void ClearPool();\r
213 \r
214         /**\r
215          * This member variable hold the status of the last call to GetStatus().\r
216          */\r
217         git_wc_status2_t *                      status;                         ///< the status result of GetStatus()\r
218 \r
219         git_revnum_t                            headrev;                        ///< the head revision fetched with GetFirstStatus()\r
220 \r
221         bool *                                          m_pbCanceled;\r
222 #ifdef _MFC_VER\r
223 friend class Git;       // So that Git can get to our m_err\r
224         /**\r
225          * Returns the last error message as a CString object.\r
226          */\r
227         CString GetLastErrorMsg() const;\r
228 \r
229         /** \r
230          * Set a list of paths which will be considered when calling GetFirstFileStatus.\r
231          * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list\r
232          */\r
233         void SetFilter(const CTGitPathList& fileList);\r
234         void ClearFilter();\r
235 \r
236 #else\r
237         /**\r
238          * Returns the last error message as a CString object.\r
239          */\r
240         stdstring GetLastErrorMsg() const;\r
241 #endif\r
242 \r
243 \r
244 protected:\r
245 //      apr_pool_t *                            m_pool;                 ///< the memory pool\r
246 private:\r
247         typedef struct sort_item\r
248         {\r
249                 const void *key;\r
250 //              apr_ssize_t klen;\r
251                 void *value;\r
252         } sort_item;\r
253 \r
254         typedef struct hashbaton_t\r
255         {\r
256                 GitStatus*              pThis;\r
257 //              apr_hash_t *    hash;\r
258 //              apr_hash_t *    exthash;\r
259         } hash_baton_t;\r
260 \r
261 //      git_client_ctx_t *                      ctx;\r
262         git_wc_status_kind                      m_allstatus;    ///< used by GetAllStatus and GetAllStatusRecursive\r
263 //      git_error_t *                           m_err;                  ///< Subversion error baton\r
264         BOOL                                            m_err;\r
265 \r
266         git_wc_status2_t                        m_status;               // used for GetStatus\r
267 \r
268 #ifdef _MFC_VER\r
269 //      GitPrompt                                       m_prompt;\r
270 #endif\r
271 \r
272         /**\r
273          * Returns a numeric value indicating the importance of a status. \r
274          * A higher number indicates a more important status.\r
275          */\r
276         static int GetStatusRanking(git_wc_status_kind status);\r
277 \r
278         /**\r
279          * Callback function which collects the raw status from a Git_client_status() function call\r
280          */\r
281         //static git_error_t * getallstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
282         static BOOL getallstatus(const struct wgFile_s *pFile, void *pUserData);\r
283         static BOOL getstatus(const struct wgFile_s *pFile, void *pUserData);\r
284 \r
285         /**\r
286          * Callback function which stores the raw status from a Git_client_status() function call\r
287          * in a hash table.\r
288          */\r
289 //      static git_error_t * getstatushash (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);\r
290 \r
291         /**\r
292          * helper function to sort a hash to an array\r
293          */\r
294 //      static apr_array_header_t * sort_hash (apr_hash_t *ht, int (*comparison_func) (const sort_item *,\r
295 //                                                                              const sort_item *), apr_pool_t *pool);\r
296 \r
297         /**\r
298          * Callback function used by qsort() which does the comparison of two elements\r
299          */\r
300         static int __cdecl sort_compare_items_as_paths (const sort_item *a, const sort_item *b);\r
301 \r
302         //for GetFirstFileStatus and GetNextFileStatus\r
303 //      apr_hash_t *                            m_statushash;\r
304 //      apr_array_header_t *            m_statusarray;\r
305         unsigned int                            m_statushashindex;\r
306 //      apr_hash_t *                            m_externalhash;\r
307 \r
308 #pragma warning(push)\r
309 #pragma warning(disable: 4200)\r
310         struct STRINGRESOURCEIMAGE\r
311         {\r
312                 WORD nLength;\r
313                 WCHAR achString[];\r
314         };\r
315 #pragma warning(pop)    // C4200\r
316 \r
317         static int LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage);\r
318         static git_error_t* cancel(void *baton);\r
319 \r
320         // A sorted list of filenames (in Git format, in lowercase) \r
321         // when this list is set, we only pick-up files during a GetStatus which are found in this list\r
322         typedef std::vector<std::string> StdStrAVector;\r
323         StdStrAVector m_filterFileList;\r
324 };\r
325 \r
326 \r
327