Drop unnecessary code
[TortoiseGit.git] / src / Git / GitStatus.h
blob735040501be37470892873cdc2f4529b35e527b8
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 #define GIT_MODE_INDEX 0x1
99 #define GIT_MODE_HEAD 0x2
100 #define GIT_MODE_IGNORE 0x4
101 #define GIT_MODE_ALL (GIT_MODE_INDEX|GIT_MODE_HEAD|GIT_MODE_IGNORE)
103 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);
104 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);
105 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);
106 static int GetFileList(const CString &gitdir, const CString &path, std::vector<CGitFileName> &list);
107 static bool IsGitReposChanged(const CString &gitdir, const CString &subpaths, int mode=GIT_MODE_ALL);
108 static int LoadIgnoreFile(const CString &gitdir, const CString &subpaths);
109 static int IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir,bool *isVersion);
110 static int IsIgnore(const CString &gitdir, const CString &path, bool *isIgnore);
111 static __int64 GetIndexFileTime(const CString &gitdir);
112 static bool IsExistIndexLockFile(const CString &gitdir);
114 public:
115 GitStatus();
116 ~GitStatus(void);
120 * Reads the Subversion status of the working copy entry. No
121 * recurse is done, even if the entry is a directory.
122 * If the status of the text and property part are different
123 * then the more important status is returned.
125 static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty, bool * assumeValid = NULL, bool * skipWorktree = NULL);
128 * Reads the Subversion status of the working copy entry and all its
129 * subitems. The resulting status is determined by using priorities for
130 * each status. The status with the highest priority is then returned.
131 * If the status of the text and property part are different then
132 * the more important status is returned.
134 static git_wc_status_kind GetAllStatusRecursive(const CTGitPath& path);
137 * Returns the status which is more "important" of the two statuses specified.
138 * This is used for the "recursive" status functions on folders - i.e. which status
139 * should be returned for a folder which has several files with different statuses
140 * in it.
142 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
145 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
146 * E.g. a "normal" status is not important, but "modified" is.
147 * \param status the status to check
149 static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}
152 * Reads the Subversion text status of the working copy entry. No
153 * recurse is done, even if the entry is a directory.
154 * The result is stored in the public member variable status.
155 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
157 * \param path the pathname of the entry
158 * \param update true if the status should be updated with the repository. Default is false.
159 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
160 * \remark If the return value is -2 then the status could not be obtained.
162 void GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
165 * Returns a string representation of a Subversion status.
166 * \param status the status enum
167 * \param string a string representation
169 static void GetStatusString(git_wc_status_kind status, size_t buflen, TCHAR * string);
170 static void GetStatusString(HINSTANCE hInst, git_wc_status_kind status, TCHAR * string, int size, WORD lang);
173 * This member variable hold the status of the last call to GetStatus().
175 git_wc_status2_t * status; ///< the status result of GetStatus()
177 #ifdef _MFC_VER
178 friend class Git; // So that Git can get to our m_err
180 * Set a list of paths which will be considered when calling GetFirstFileStatus.
181 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
183 void SetFilter(const CTGitPathList& fileList);
184 void ClearFilter();
185 #endif
187 private:
188 git_wc_status_kind m_allstatus; ///< used by GetAllStatus and GetAllStatusRecursive
189 int m_err;
191 git_wc_status2_t m_status; // used for GetStatus
194 * Returns a numeric value indicating the importance of a status.
195 * A higher number indicates a more important status.
197 static int GetStatusRanking(git_wc_status_kind status);
199 #pragma warning(push)
200 #pragma warning(disable: 4200)
201 struct STRINGRESOURCEIMAGE
203 WORD nLength;
204 WCHAR achString[];
206 #pragma warning(pop) // C4200
208 static int LoadStringEx(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax, WORD wLanguage);