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.
23 //# include "SVNPrompt.h"
29 #pragma warning (push,1)
30 typedef std::basic_string
<wchar_t> wide_string
;
32 # define stdstring wide_string
34 # define stdstring std::string
41 typedef enum type_git_wc_status_kind
44 git_wc_status_unversioned
,
45 git_wc_status_ignored
,
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
,
55 git_wc_status_conflicted
,
56 git_wc_status_obstructed
,
57 git_wc_status_unknown
,
70 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
71 #define GIT_INVALID_REVNUM _T("")
72 typedef CString git_revnum_t
;
74 typedef struct git_wc_entry_t
83 typedef struct git_wc_status2_t
85 /** The status of the entries text. */
86 git_wc_status_kind text_status
;
88 /** The status of the entries properties. */
89 git_wc_status_kind prop_status
;
92 #define MAX_STATUS_STRING_LENGTH 256
94 typedef BOOL (*FIll_STATUS_CALLBACK
)(const CString
&path
,git_wc_status_kind status
,bool isDir
, void *pdata
);
98 * Handles Subversion status of working copies.
104 #define GIT_MODE_INDEX 0x1
105 #define GIT_MODE_HEAD 0x2
106 #define GIT_MODE_IGNORE 0x4
107 #define GIT_MODE_ALL (GIT_MODE_INDEX|GIT_MODE_HEAD|GIT_MODE_IGNORE)
109 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
);
110 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
);
111 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
);
112 static int GetFileList(const CString
&gitdir
, const CString
&path
, std::vector
<CGitFileName
> &list
);
113 static bool IsGitReposChanged(const CString
&gitdir
, const CString
&subpaths
, int mode
=GIT_MODE_ALL
);
114 static int LoadIgnoreFile(const CString
&gitdir
, const CString
&subpaths
);
115 static int IsUnderVersionControl(const CString
&gitdir
, const CString
&path
, bool isDir
,bool *isVersion
);
116 static int IsIgnore(const CString
&gitdir
, const CString
&path
, bool *isIgnore
);
117 static __int64
GetIndexFileTime(const CString
&gitdir
);
118 static bool IsExistIndexLockFile(const CString
&gitdir
);
120 static int GetHeadHash(const CString
&gitdir
, CGitHash
&hash
);
128 * Reads the Subversion status of the working copy entry. No
129 * recurse is done, even if the entry is a directory.
130 * If the status of the text and property part are different
131 * then the more important status is returned.
133 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
);
136 * Reads the Subversion status of the working copy entry and all its
137 * subitems. The resulting status is determined by using priorities for
138 * each status. The status with the highest priority is then returned.
139 * If the status of the text and property part are different then
140 * the more important status is returned.
142 static git_wc_status_kind
GetAllStatusRecursive(const CTGitPath
& path
);
145 * Returns the status which is more "important" of the two statuses specified.
146 * This is used for the "recursive" status functions on folders - i.e. which status
147 * should be returned for a folder which has several files with different statuses
150 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
153 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
154 * E.g. a "normal" status is not important, but "modified" is.
155 * \param status the status to check
157 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
160 * Reads the Subversion text status of the working copy entry. No
161 * recurse is done, even if the entry is a directory.
162 * The result is stored in the public member variable status.
163 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
165 * \param path the pathname of the entry
166 * \param update true if the status should be updated with the repository. Default is false.
167 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
168 * \remark If the return value is -2 then the status could not be obtained.
170 void GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
173 * Returns a string representation of a Subversion status.
174 * \param status the status enum
175 * \param string a string representation
177 static void GetStatusString(git_wc_status_kind status
, size_t buflen
, TCHAR
* string
);
178 static void GetStatusString(HINSTANCE hInst
, git_wc_status_kind status
, TCHAR
* string
, int size
, WORD lang
);
181 * This member variable hold the status of the last call to GetStatus().
183 git_wc_status2_t
* status
; ///< the status result of GetStatus()
186 friend class Git
; // So that Git can get to our m_err
188 * Set a list of paths which will be considered when calling GetFirstFileStatus.
189 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
191 void SetFilter(const CTGitPathList
& fileList
);
196 git_wc_status_kind m_allstatus
; ///< used by GetAllStatus and GetAllStatusRecursive
199 git_wc_status2_t m_status
; // used for GetStatus
202 * Returns a numeric value indicating the importance of a status.
203 * A higher number indicates a more important status.
205 static int GetStatusRanking(git_wc_status_kind status
);
207 #pragma warning(push)
208 #pragma warning(disable: 4200)
209 struct STRINGRESOURCEIMAGE
214 #pragma warning(pop) // C4200
216 static int LoadStringEx(HINSTANCE hInstance
, UINT uID
, LPTSTR lpBuffer
, int nBufferMax
, WORD wLanguage
);