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_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
;
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
);
92 * Handles Subversion status of working copies.
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 static int GetHeadHash(const CString
&gitdir
, CGitHash
&hash
);
122 * Reads the Subversion status of the working copy entry. No
123 * recurse is done, even if the entry is a directory.
124 * If the status of the text and property part are different
125 * then the more important status is returned.
127 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
, bool * assumeValid
= NULL
, bool * skipWorktree
= NULL
);
130 * Reads the Subversion status of the working copy entry and all its
131 * subitems. The resulting status is determined by using priorities for
132 * each status. The status with the highest priority is then returned.
133 * If the status of the text and property part are different then
134 * the more important status is returned.
136 static git_wc_status_kind
GetAllStatusRecursive(const CTGitPath
& path
);
139 * Returns the status which is more "important" of the two statuses specified.
140 * This is used for the "recursive" status functions on folders - i.e. which status
141 * should be returned for a folder which has several files with different statuses
144 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
147 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
148 * E.g. a "normal" status is not important, but "modified" is.
149 * \param status the status to check
151 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
154 * Reads the Subversion text status of the working copy entry. No
155 * recurse is done, even if the entry is a directory.
156 * The result is stored in the public member variable status.
157 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
159 * \param path the pathname of the entry
160 * \param update true if the status should be updated with the repository. Default is false.
161 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
162 * \remark If the return value is -2 then the status could not be obtained.
164 void GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
167 * Returns a string representation of a Subversion status.
168 * \param status the status enum
169 * \param string a string representation
171 static void GetStatusString(git_wc_status_kind status
, size_t buflen
, TCHAR
* string
);
172 static void GetStatusString(HINSTANCE hInst
, git_wc_status_kind status
, TCHAR
* string
, int size
, WORD lang
);
175 * This member variable hold the status of the last call to GetStatus().
177 git_wc_status2_t
* status
; ///< the status result of GetStatus()
180 friend class Git
; // So that Git can get to our m_err
182 * Set a list of paths which will be considered when calling GetFirstFileStatus.
183 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
185 void SetFilter(const CTGitPathList
& fileList
);
190 git_wc_status_kind m_allstatus
; ///< used by GetAllStatus and GetAllStatusRecursive
193 git_wc_status2_t m_status
; // used for GetStatus
196 * Returns a numeric value indicating the importance of a status.
197 * A higher number indicates a more important status.
199 static int GetStatusRanking(git_wc_status_kind status
);
201 #pragma warning(push)
202 #pragma warning(disable: 4200)
203 struct STRINGRESOURCEIMAGE
208 #pragma warning(pop) // C4200
210 static int LoadStringEx(HINSTANCE hInstance
, UINT uID
, LPTSTR lpBuffer
, int nBufferMax
, WORD wLanguage
);