1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012,2014 - 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.
26 #pragma warning (push,1)
27 typedef std::basic_string
<wchar_t> wide_string
;
29 # define stdstring wide_string
31 # define stdstring std::string
38 typedef enum type_git_wc_status_kind
41 git_wc_status_unversioned
,
42 git_wc_status_ignored
,
44 git_wc_status_external
,
45 git_wc_status_incomplete
,
46 git_wc_status_missing
,
47 git_wc_status_deleted
,
48 git_wc_status_replaced
,
49 git_wc_status_modified
,
52 git_wc_status_conflicted
,
53 git_wc_status_obstructed
,
54 git_wc_status_unknown
,
67 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
68 #define GIT_INVALID_REVNUM _T("")
69 typedef CString git_revnum_t
;
71 typedef struct git_wc_status2_t
73 /** The status of the entries text. */
74 git_wc_status_kind text_status
;
76 /** The status of the entries properties. */
77 git_wc_status_kind prop_status
;
83 #define MAX_STATUS_STRING_LENGTH 256
85 typedef BOOL (*FILL_STATUS_CALLBACK
)(const CString
&path
, git_wc_status_kind status
, bool isDir
, void *pdata
, bool assumeValid
, bool skipWorktree
);
89 * Handles git status of working copies.
95 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
= nullptr, void *pData
= nullptr, bool * assumeValid
= nullptr, bool * skipWorktree
= nullptr);
96 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
= nullptr, void *pData
= nullptr);
97 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
= nullptr, void *pData
= nullptr);
98 static int GetFileList(const CString
&gitdir
, const CString
&path
, std::vector
<CGitFileName
> &list
);
99 static bool HasIgnoreFilesChanged(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
100 static int LoadIgnoreFile(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
101 static int IsUnderVersionControl(const CString
&gitdir
, const CString
&path
, bool isDir
,bool *isVersion
);
102 static int IsIgnore(const CString
&gitdir
, const CString
&path
, bool *isIgnore
, bool isDir
);
103 static __int64
GetIndexFileTime(const CString
&gitdir
);
104 static bool IsExistIndexLockFile(const CString
&gitdir
);
105 static bool ReleasePath(const CString
&gitdir
);
106 static bool ReleasePathsRecursively(const CString
&rootpath
);
114 * Reads the git status of the working copy entry. No
115 * recurse is done, even if the entry is a directory.
116 * If the status of the text and property part are different
117 * then the more important status is returned.
119 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
, bool * assumeValid
= NULL
, bool * skipWorktree
= NULL
);
122 * Reads the git status of the working copy entry and all its
123 * subitems. The resulting status is determined by using priorities for
124 * each status. The status with the highest priority is then returned.
125 * If the status of the text and property part are different then
126 * the more important status is returned.
128 static git_wc_status_kind
GetAllStatusRecursive(const CTGitPath
& path
);
131 * Returns the status which is more "important" of the two statuses specified.
132 * This is used for the "recursive" status functions on folders - i.e. which status
133 * should be returned for a folder which has several files with different statuses
136 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
139 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
140 * E.g. a "normal" status is not important, but "modified" is.
141 * \param status the status to check
143 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
146 * Reads the git text status of the working copy entry. No
147 * recurse is done, even if the entry is a directory.
148 * The result is stored in the public member variable status.
149 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
151 * \param path the pathname of the entry
152 * \param update true if the status should be updated with the repository. Default is false.
153 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
154 * \remark If the return value is -2 then the status could not be obtained.
156 void GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
159 * Returns a string representation of a git status.
160 * \param status the status enum
161 * \param string a string representation
163 static void GetStatusString(git_wc_status_kind status
, size_t buflen
, TCHAR
* string
);
164 static void GetStatusString(HINSTANCE hInst
, git_wc_status_kind status
, TCHAR
* string
, int size
, WORD lang
);
167 * This member variable hold the status of the last call to GetStatus().
169 git_wc_status2_t
* status
; ///< the status result of GetStatus()
172 friend class Git
; // So that Git can get to our m_err
174 * Set a list of paths which will be considered when calling GetFirstFileStatus.
175 * If a filter is set, then GetFirstFileStatus/GetNextFileStatus will only return items which are in the filter list
177 void SetFilter(const CTGitPathList
& fileList
);
182 git_wc_status_kind m_allstatus
; ///< used by GetAllStatus and GetAllStatusRecursive
184 git_wc_status2_t m_status
; // used for GetStatus
187 * Returns a numeric value indicating the importance of a status.
188 * A higher number indicates a more important status.
190 static int GetStatusRanking(git_wc_status_kind status
);
192 #pragma warning(push)
193 #pragma warning(disable: 4200)
194 struct STRINGRESOURCEIMAGE
199 #pragma warning(pop) // C4200
201 static int LoadStringEx(HINSTANCE hInstance
, UINT uID
, LPTSTR lpBuffer
, int nBufferMax
, WORD wLanguage
);