1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012,2014,2016 - 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.
28 typedef enum type_git_wc_status_kind
31 git_wc_status_unversioned
,
32 git_wc_status_ignored
,
34 git_wc_status_external
,
35 git_wc_status_incomplete
,
36 git_wc_status_missing
,
37 git_wc_status_deleted
,
38 git_wc_status_replaced
,
39 git_wc_status_modified
,
42 git_wc_status_conflicted
,
43 git_wc_status_obstructed
,
44 git_wc_status_unknown
,
56 #define GIT_REV_ZERO _T("0000000000000000000000000000000000000000")
57 #define GIT_INVALID_REVNUM _T("")
58 typedef CString git_revnum_t
;
60 typedef struct git_wc_status2_t
62 /** The status of the entries text. */
63 git_wc_status_kind text_status
;
65 /** The status of the entries properties. */
66 git_wc_status_kind prop_status
;
72 #define MAX_STATUS_STRING_LENGTH 256
74 typedef BOOL (*FILL_STATUS_CALLBACK
)(const CString
&path
, git_wc_status_kind status
, bool isDir
, void *pdata
, bool assumeValid
, bool skipWorktree
);
76 static CString
CombinePath(const CString
& part1
, const CString
& part2
)
86 * Handles git status of working copies.
92 static int GetFileStatus(const CString
& gitdir
, 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);
93 static int GetDirStatus(const CString
& gitdir
, const CString
& path
, git_wc_status_kind
* status
, BOOL IsFull
= false, BOOL IsRecursive
= false, BOOL isIgnore
= true);
94 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);
95 static int GetFileList(CString path
, std::vector
<CGitFileName
> &list
);
96 static bool HasIgnoreFilesChanged(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
97 static int LoadIgnoreFile(const CString
&gitdir
, const CString
&subpaths
, bool isDir
);
98 static int IsUnderVersionControl(const CString
&gitdir
, const CString
&path
, bool isDir
,bool *isVersion
);
99 static int IsIgnore(const CString
&gitdir
, const CString
&path
, bool *isIgnore
, bool isDir
);
100 static bool IsExistIndexLockFile(CString gitdir
);
101 static bool ReleasePath(const CString
&gitdir
);
102 static bool ReleasePathsRecursively(const CString
&rootpath
);
110 * Reads the git status of the working copy entry. No
111 * recurse is done, even if the entry is a directory.
112 * If the status of the text and property part are different
113 * then the more important status is returned.
115 static git_wc_status_kind
GetAllStatus(const CTGitPath
& path
, git_depth_t depth
= git_depth_empty
, bool* assumeValid
= nullptr, bool* skipWorktree
= nullptr);
118 * Returns the status which is more "important" of the two statuses specified.
119 * This is used for the "recursive" status functions on folders - i.e. which status
120 * should be returned for a folder which has several files with different statuses
123 static git_wc_status_kind
GetMoreImportant(git_wc_status_kind status1
, git_wc_status_kind status2
);
126 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
127 * E.g. a "normal" status is not important, but "modified" is.
128 * \param status the status to check
130 static BOOL
IsImportant(git_wc_status_kind status
) {return (GetMoreImportant(git_wc_status_added
, status
)==status
);}
133 * Reads the git text status of the working copy entry. No
134 * recurse is done, even if the entry is a directory.
135 * The result is stored in the public member variable status.
136 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
138 * \param path the pathname of the entry
139 * \param update true if the status should be updated with the repository. Default is false.
140 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
141 * \remark If the return value is -2 then the status could not be obtained.
143 void GetStatus(const CTGitPath
& path
, bool update
= false, bool noignore
= false, bool noexternals
= false);
146 * This member variable hold the status of the last call to GetStatus().
148 git_wc_status2_t
* status
; ///< the status result of GetStatus()
151 git_wc_status2_t m_status
; // used for GetStatus
154 * Returns a numeric value indicating the importance of a status.
155 * A higher number indicates a more important status.
157 static int GetStatusRanking(git_wc_status_kind status
);