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