Fixed issue #1620: Apply Patch serial can't open file dialog on WinXP
[TortoiseGit.git] / src / Git / GitStatus.h
blobaafd5dd170f945c15cded99b4c0c110a2616c08f
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;
70 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
71 #define GIT_INVALID_REVNUM _T("")
72 typedef CString git_revnum_t;
74 typedef struct git_wc_status2_t
76 /** The status of the entries text. */
77 git_wc_status_kind text_status;
79 /** The status of the entries properties. */
80 git_wc_status_kind prop_status;
82 bool assumeValid;
83 bool skipWorktree;
84 } git_wc_status2;
86 #define MAX_STATUS_STRING_LENGTH 256
88 typedef BOOL (*FIll_STATUS_CALLBACK)(const CString &path, git_wc_status_kind status, bool isDir, void *pdata, bool assumeValid, bool skipWorktree);
90 /**
91 * \ingroup Git
92 * Handles Subversion status of working copies.
94 class GitStatus
96 public:
98 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, bool * assumeValid = NULL, bool * skipWorktree = NULL);
99 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);
100 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);
101 static int GetFileList(const CString &gitdir, const CString &path, std::vector<CGitFileName> &list);
102 static bool HasIgnoreFilesChanged(const CString &gitdir, const CString &subpaths);
103 static int LoadIgnoreFile(const CString &gitdir, const CString &subpaths);
104 static int IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir,bool *isVersion);
105 static int IsIgnore(const CString &gitdir, const CString &path, bool *isIgnore);
106 static __int64 GetIndexFileTime(const CString &gitdir);
107 static bool IsExistIndexLockFile(const CString &gitdir);
109 public:
110 GitStatus();
111 ~GitStatus(void);
115 * Reads the Subversion status of the working copy entry. No
116 * recurse is done, even if the entry is a directory.
117 * If the status of the text and property part are different
118 * then the more important status is returned.
120 static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty, bool * assumeValid = NULL, bool * skipWorktree = NULL);
123 * Reads the Subversion status of the working copy entry and all its
124 * subitems. The resulting status is determined by using priorities for
125 * each status. The status with the highest priority is then returned.
126 * If the status of the text and property part are different then
127 * the more important status is returned.
129 static git_wc_status_kind GetAllStatusRecursive(const CTGitPath& path);
132 * Returns the status which is more "important" of the two statuses specified.
133 * This is used for the "recursive" status functions on folders - i.e. which status
134 * should be returned for a folder which has several files with different statuses
135 * in it.
137 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
140 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
141 * E.g. a "normal" status is not important, but "modified" is.
142 * \param status the status to check
144 static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}
147 * Reads the Subversion text status of the working copy entry. No
148 * recurse is done, even if the entry is a directory.
149 * The result is stored in the public member variable status.
150 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
152 * \param path the pathname of the entry
153 * \param update true if the status should be updated with the repository. Default is false.
154 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
155 * \remark If the return value is -2 then the status could not be obtained.
157 void GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
160 * Returns a string representation of a Subversion status.
161 * \param status the status enum
162 * \param string a string representation
164 static void GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string);
165 static void GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang);
168 * This member variable hold the status of the last call to GetStatus().
170 git_wc_status2_t * status; ///< the status result of GetStatus()
172 #ifdef _MFC_VER
173 friend class Git; // So that Git can get to our m_err
175 * Set a list of paths which will be considered when calling GetFirstFileStatus.
176 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
178 void SetFilter(const CTGitPathList& fileList);
179 void ClearFilter();
180 #endif
182 private:
183 git_wc_status_kind m_allstatus; ///< used by GetAllStatus and GetAllStatusRecursive
184 int m_err;
186 git_wc_status2_t m_status; // used for GetStatus
189 * Returns a numeric value indicating the importance of a status.
190 * A higher number indicates a more important status.
192 static int GetStatusRanking(git_wc_status_kind status);
194 #pragma warning(push)
195 #pragma warning(disable: 4200)
196 struct STRINGRESOURCEIMAGE
198 WORD nLength;
199 WCHAR achString[];
201 #pragma warning(pop) // C4200
203 static int LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage);