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
);
87 static CString
CombinePath(const CString
& part1
, const CString
& part2
)
97 * Handles git status of working copies.
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
= nullptr, void *pData
= nullptr, bool * assumeValid
= nullptr, bool * skipWorktree
= nullptr);
104 static int GetDirStatus(const CString
& gitdir
, const CString
& path
, git_wc_status_kind
* status
, BOOL IsFull
= false, BOOL IsRecursive
= false, BOOL isIgnore
= true);
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
= nullptr, void *pData
= nullptr);
106 static int GetFileList(CString path
, std::vector
<CGitFileName
> &list
);
107 static bool HasIgnoreFilesChanged(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
108 static int LoadIgnoreFile(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
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
, bool isDir
);
111 static bool IsExistIndexLockFile(const CString
&gitdir
);
112 static bool ReleasePath(const CString
&gitdir
);
113 static bool ReleasePathsRecursively(const CString
&rootpath
);
121 * Reads the git status of the working copy entry. No
122 * recurse is done, even if the entry is a directory.
123 * If the status of the text and property part are different
124 * then the more important status is returned.
126 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
, bool * assumeValid
= NULL
, bool * skipWorktree
= NULL
);
129 * Reads the git status of the working copy entry and all its
130 * subitems. The resulting status is determined by using priorities for
131 * each status. The status with the highest priority is then returned.
132 * If the status of the text and property part are different then
133 * the more important status is returned.
135 static git_wc_status_kind
GetAllStatusRecursive(const CTGitPath
& path
);
138 * Returns the status which is more "important" of the two statuses specified.
139 * This is used for the "recursive" status functions on folders - i.e. which status
140 * should be returned for a folder which has several files with different statuses
143 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
146 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
147 * E.g. a "normal" status is not important, but "modified" is.
148 * \param status the status to check
150 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
153 * Reads the git text status of the working copy entry. No
154 * recurse is done, even if the entry is a directory.
155 * The result is stored in the public member variable status.
156 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
158 * \param path the pathname of the entry
159 * \param update true if the status should be updated with the repository. Default is false.
160 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
161 * \remark If the return value is -2 then the status could not be obtained.
163 void GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
166 * This member variable hold the status of the last call to GetStatus().
168 git_wc_status2_t
* status
; ///< the status result of GetStatus()
171 git_wc_status_kind m_allstatus
; ///< used by GetAllStatus and GetAllStatusRecursive
173 git_wc_status2_t m_status
; // used for GetStatus
176 * Returns a numeric value indicating the importance of a status.
177 * A higher number indicates a more important status.
179 static int GetStatusRanking(git_wc_status_kind status
);