drop unneeded method
[TortoiseGit.git] / src / Git / GitStatus.h
bloba6db9931b63bfd871c2af90812bc2d5d2f0a701b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 #ifdef _MFC_VER
23 //# include "SVNPrompt.h"
24 #endif
25 #include "TGitPath.h"
27 class CGitFileName;
29 #pragma warning (push,1)
30 typedef std::basic_string<wchar_t> wide_string;
31 #ifdef UNICODE
32 # define stdstring wide_string
33 #else
34 # define stdstring std::string
35 #endif
36 #pragma warning (pop)
38 #include "TGitPath.h"
39 #include "GitHash.h"
41 typedef enum type_git_wc_status_kind
43 git_wc_status_none,
44 git_wc_status_unversioned,
45 git_wc_status_ignored,
46 git_wc_status_normal,
47 git_wc_status_external,
48 git_wc_status_incomplete,
49 git_wc_status_missing,
50 git_wc_status_deleted,
51 git_wc_status_replaced,
52 git_wc_status_modified,
53 git_wc_status_merged,
54 git_wc_status_added,
55 git_wc_status_conflicted,
56 git_wc_status_obstructed,
57 git_wc_status_unknown,
59 }git_wc_status_kind;
61 typedef enum
63 git_depth_empty,
64 git_depth_infinity,
65 git_depth_unknown,
66 git_depth_files,
67 git_depth_immediates,
68 }git_depth_t;
71 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
72 #define GIT_INVALID_REVNUM _T("")
73 typedef CString git_revnum_t;
74 typedef int tgit_error_t;
76 typedef struct git_wc_entry_t
78 // url in repository
79 const char *url;
81 TCHAR cmt_rev[41];
82 } git_wc_entry_t;
85 typedef struct git_wc_status2_t
87 /** The status of the entries text. */
88 git_wc_status_kind text_status;
90 /** The status of the entries properties. */
91 git_wc_status_kind prop_status;
93 //git_wc_entry_t *entry;
94 } git_wc_status2;
96 #define MAX_STATUS_STRING_LENGTH 256
99 /////////////////////////////////////////////////////////////////////
100 // WINGIT API (replaced by commandline tool, but defs and data types kept so old code still works)
102 // Flags for wgEnumFiles
103 enum WGENUMFILEFLAGS
105 WGEFF_NoRecurse = (1<<0), // only enumerate files directly in the specified path
106 WGEFF_FullPath = (1<<1), // enumerated filenames are specified with full path (instead of relative to proj root)
107 WGEFF_DirStatusDelta= (1<<2), // include directories, in enumeration, that have a recursive status != WGFS_Normal (may have a slightly better performance than WGEFF_DirStatusAll)
108 WGEFF_DirStatusAll = (1<<3), // include directories, in enumeration, with recursive status
109 WGEFF_EmptyAsNormal = (1<<4), // report sub-directories, with no versioned files, as WGFS_Normal instead of WGFS_Empty
110 WGEFF_SingleFile = (1<<5) // indicates that the status of a single file or dir, specified by pszSubPath, is wanted
113 // File status
114 enum WGFILESTATUS
116 WGFS_Normal,
117 WGFS_Modified,
118 WGFS_Staged,
119 WGFS_Added,
120 WGFS_Conflicted,
121 WGFS_Deleted,
123 WGFS_Ignored = -1,
124 WGFS_Unversioned = -2,
125 WGFS_Empty = -3,
126 WGFS_Unknown = -4
129 // File flags
130 enum WGFILEFLAGS
132 WGFF_Directory = (1<<0) // enumerated file is a directory
135 struct wgFile_s
137 LPCTSTR sFileName; // filename or directory relative to project root (using forward slashes)
138 int nStatus; // the WGFILESTATUS of the file
139 int nFlags; // a combination of WGFILEFLAGS
141 const BYTE* sha1; // points to the BYTE[20] sha1 (NULL for directories, WGFF_Directory)
144 // Application-defined callback function for wgEnumFiles, returns TRUE to abort enumeration
145 // NOTE: do NOT store the pFile pointer or any pointers in wgFile_s for later use, the data is only valid for a single callback call
146 typedef BOOL (__cdecl WGENUMFILECB)(const struct wgFile_s *pFile, void *pUserData);
149 /////////////////////////////////////////////////////////////////////
152 // convert wingit.dll status to git_wc_status_kind
153 inline static git_wc_status_kind GitStatusFromWingit(int nStatus)
155 switch (nStatus)
157 case WGFS_Normal: return git_wc_status_normal;
158 case WGFS_Modified: return git_wc_status_modified;
159 case WGFS_Staged: return git_wc_status_merged;
160 case WGFS_Added: return git_wc_status_added;
161 case WGFS_Conflicted: return git_wc_status_conflicted;
162 case WGFS_Deleted: return git_wc_status_deleted;
164 case WGFS_Ignored: return git_wc_status_ignored;
165 case WGFS_Unversioned: return git_wc_status_unversioned;
166 case WGFS_Empty: return git_wc_status_unversioned;
169 return git_wc_status_none;
172 // convert 20 byte sha1 hash to the git_revnum_t type
173 inline static git_revnum_t ConvertHashToRevnum(const BYTE *sha1)
175 if (!sha1)
176 return GIT_INVALID_REVNUM;
178 char s[41];
179 char *p = s;
180 for (int i=0; i<20; i++)
182 #pragma warning(push)
183 #pragma warning(disable: 4996)
184 sprintf(p, "%02x", (UINT)*sha1);
185 #pragma warning(pop)
186 p += 2;
187 sha1++;
190 return CString(s);
193 typedef BOOL (*FIll_STATUS_CALLBACK)(const CString &path,git_wc_status_kind status,bool isDir, void *pdata);
196 * \ingroup Git
197 * Handles Subversion status of working copies.
199 class GitStatus
201 public:
203 #define GIT_MODE_INDEX 0x1
204 #define GIT_MODE_HEAD 0x2
205 #define GIT_MODE_IGNORE 0x4
206 #define GIT_MODE_ALL (GIT_MODE_INDEX|GIT_MODE_HEAD|GIT_MODE_IGNORE)
208 static int GetFileStatus(const CString &gitdir,const CString &path,git_wc_status_kind * status,BOOL IsFull=false, BOOL IsRecursive=false, BOOL isIgnore=true, FIll_STATUS_CALLBACK callback=NULL,void *pData=NULL);
209 static int GetDirStatus(const CString &gitdir,const CString &path,git_wc_status_kind * status,BOOL IsFull=false, BOOL IsRecursive=false, BOOL isIgnore=true, FIll_STATUS_CALLBACK callback=NULL, void *pData=NULL);
210 static int EnumDirStatus(const CString &gitdir,const CString &path,git_wc_status_kind * status,BOOL IsFull=false, BOOL IsRecursive=false, BOOL isIgnore=true, FIll_STATUS_CALLBACK callback=NULL, void *pData=NULL);
211 static int GetFileList(const CString &gitdir, const CString &path, std::vector<CGitFileName> &list);
212 static bool IsGitReposChanged(const CString &gitdir, const CString &subpaths, int mode=GIT_MODE_ALL);
213 static int LoadIgnoreFile(const CString &gitdir, const CString &subpaths);
214 static int IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir,bool *isVersion);
215 static int IsIgnore(const CString &gitdir, const CString &path, bool *isIgnore);
216 static __int64 GetIndexFileTime(const CString &gitdir);
217 static bool IsExistIndexLockFile(const CString &gitdir);
219 static int GetHeadHash(const CString &gitdir, CGitHash &hash);
221 public:
222 GitStatus(bool * pbCanceled = NULL);
223 ~GitStatus(void);
227 * Reads the Subversion status of the working copy entry. No
228 * recurse is done, even if the entry is a directory.
229 * If the status of the text and property part are different
230 * then the more important status is returned.
232 static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty);
235 * Reads the Subversion status of the working copy entry and all its
236 * subitems. The resulting status is determined by using priorities for
237 * each status. The status with the highest priority is then returned.
238 * If the status of the text and property part are different then
239 * the more important status is returned.
241 static git_wc_status_kind GetAllStatusRecursive(const CTGitPath& path);
244 * Returns the status which is more "important" of the two statuses specified.
245 * This is used for the "recursive" status functions on folders - i.e. which status
246 * should be returned for a folder which has several files with different statuses
247 * in it.
249 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
252 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
253 * E.g. a "normal" status is not important, but "modified" is.
254 * \param status the status to check
256 static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}
259 * Reads the Subversion text status of the working copy entry. No
260 * recurse is done, even if the entry is a directory.
261 * The result is stored in the public member variable status.
262 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
264 * \param path the pathname of the entry
265 * \param update true if the status should be updated with the repository. Default is false.
266 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
267 * \remark If the return value is -2 then the status could not be obtained.
269 git_revnum_t GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
272 * Returns a string representation of a Subversion status.
273 * \param status the status enum
274 * \param string a string representation
276 static void GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string);
277 static void GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang);
280 * Returns the string representation of a depth.
282 #ifdef _MFC_VER
283 static CString GetDepthString(git_depth_t depth);
284 #endif
285 static void GetDepthString(HINSTANCE hInst, git_depth_t depth, TCHAR * string, int size, WORD lang);
288 * Returns the status of the first file of the given path. Use GetNextFileStatus() to obtain
289 * the status of the next file in the list.
290 * \param path the path of the folder from where the status list should be obtained
291 * \param retPath the path of the file for which the status was returned
292 * \param update set this to true if you want the status to be updated with the repository (needs network access)
293 * \param recurse true to fetch the status recursively
294 * \param bNoIgnore true to not fetch the ignored files
295 * \param bNoExternals true to not fetch the status of included Git:externals
296 * \return the status
298 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);
299 unsigned int GetFileCount() const {return /*apr_hash_count(m_statushash);*/0;}
300 unsigned int GetVersionedCount() const;
302 * Returns the status of the next file in the file list. If no more files are in the list then NULL is returned.
303 * See GetFirstFileStatus() for details.
305 git_wc_status2_t * GetNextFileStatus(CTGitPath& retPath);
307 * Checks if a path is an external folder.
308 * This is necessary since Subversion returns two entries for external folders: one with the status Git_wc_status_external
309 * and one with the 'real' status of that folder. GetFirstFileStatus() and GetNextFileStatus() only return the 'real'
310 * status, so with this method it's possible to check if the status also is Git_wc_status_external.
312 bool IsExternal(const CTGitPath& path) const;
314 * Checks if a path is in an external folder.
316 bool IsInExternal(const CTGitPath& path) const;
319 * Clears the memory pool.
321 void ClearPool();
324 * This member variable hold the status of the last call to GetStatus().
326 git_wc_status2_t * status; ///< the status result of GetStatus()
328 git_revnum_t headrev; ///< the head revision fetched with GetFirstStatus()
330 bool * m_pbCanceled;
331 #ifdef _MFC_VER
332 friend class Git; // So that Git can get to our m_err
334 * Returns the last error message as a CString object.
336 CString GetLastErrorMsg() const;
339 * Set a list of paths which will be considered when calling GetFirstFileStatus.
340 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
342 void SetFilter(const CTGitPathList& fileList);
343 void ClearFilter();
345 #else
347 * Returns the last error message as a CString object.
349 stdstring GetLastErrorMsg() const;
350 #endif
353 protected:
354 // apr_pool_t * m_pool; ///< the memory pool
355 private:
356 typedef struct sort_item
358 const void *key;
359 // apr_ssize_t klen;
360 void *value;
361 } sort_item;
363 typedef struct hashbaton_t
365 GitStatus* pThis;
366 // apr_hash_t * hash;
367 // apr_hash_t * exthash;
368 } hash_baton_t;
370 // git_client_ctx_t * ctx;
371 git_wc_status_kind m_allstatus; ///< used by GetAllStatus and GetAllStatusRecursive
372 // git_error_t * m_err; ///< Subversion error baton
373 tgit_error_t m_err;
375 git_wc_status2_t m_status; // used for GetStatus
377 #ifdef _MFC_VER
378 // GitPrompt m_prompt;
379 #endif
382 * Returns a numeric value indicating the importance of a status.
383 * A higher number indicates a more important status.
385 static int GetStatusRanking(git_wc_status_kind status);
388 * Callback function which collects the raw status from a Git_client_status() function call
390 //static git_error_t * getallstatus (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
391 static BOOL getallstatus(const struct wgFile_s *pFile, void *pUserData);
392 static BOOL getstatus(const struct wgFile_s *pFile, void *pUserData);
395 * Callback function which stores the raw status from a Git_client_status() function call
396 * in a hash table.
398 // static git_error_t * getstatushash (void *baton, const char *path, git_wc_status2_t *status, apr_pool_t *pool);
401 * helper function to sort a hash to an array
403 // static apr_array_header_t * sort_hash (apr_hash_t *ht, int (*comparison_func) (const sort_item *,
404 // const sort_item *), apr_pool_t *pool);
407 * Callback function used by qsort() which does the comparison of two elements
409 static int __cdecl sort_compare_items_as_paths (const sort_item *a, const sort_item *b);
411 //for GetFirstFileStatus and GetNextFileStatus
412 // apr_hash_t * m_statushash;
413 // apr_array_header_t * m_statusarray;
414 unsigned int m_statushashindex;
415 // apr_hash_t * m_externalhash;
417 #pragma warning(push)
418 #pragma warning(disable: 4200)
419 struct STRINGRESOURCEIMAGE
421 WORD nLength;
422 WCHAR achString[];
424 #pragma warning(pop) // C4200
426 static int LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage);
427 static tgit_error_t* cancel(void *baton);
429 // A sorted list of filenames (in Git format, in lowercase)
430 // when this list is set, we only pick-up files during a GetStatus which are found in this list
431 typedef std::vector<std::string> StdStrAVector;
432 StdStrAVector m_filterFileList;