Improve overlay status for symlinks
[TortoiseGit.git] / src / Git / GitStatus.h
blobd19c1558e788d211248c9cf99b0ebc866c4d8d39
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - 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.
20 #pragma once
21 #include "TGitPath.h"
22 #include "PathUtils.h"
24 class CGitFileName;
26 #include "GitHash.h"
28 typedef enum type_git_wc_status_kind
30 git_wc_status_none,
31 git_wc_status_unversioned,
32 git_wc_status_ignored,
33 git_wc_status_normal,
34 git_wc_status_deleted,
35 git_wc_status_modified,
36 git_wc_status_added,
37 git_wc_status_conflicted,
38 git_wc_status_unknown, // should be last, see TGitCache/CacheInterface.h
39 }git_wc_status_kind;
41 typedef struct git_wc_status2_t
43 git_wc_status_kind status;
45 bool assumeValid;
46 bool skipWorktree;
47 } git_wc_status2;
49 #define MAX_STATUS_STRING_LENGTH 256
51 typedef BOOL (*FILL_STATUS_CALLBACK)(const CString& path, const git_wc_status2_t* status, bool isDir, __int64 lastwritetime, void* baton);
53 static CString CombinePath(const CString& part1, const CString& part2)
55 CString path(part1);
56 path += L'\\';
57 path += part2;
58 return path;
61 static CString CombinePath(const CString& part1, const CString& part2, const CString& part3)
63 CString path(part1);
64 path += L'\\';
65 path += part2;
66 CPathUtils::EnsureTrailingPathDelimiter(path);
67 path += part3;
68 return path;
71 /**
72 * \ingroup Git
73 * Handles git status of working copies.
75 class GitStatus
77 public:
79 static int GetFileStatus(const CString& gitdir, CString path, git_wc_status2_t& status, BOOL IsFull = FALSE, BOOL isIgnore = TRUE, bool update = true);
80 static int GetDirStatus(const CString& gitdir, const CString& path, git_wc_status_kind* status, BOOL IsFull = false, BOOL IsRecursive = false, BOOL isIgnore = true);
81 static int EnumDirStatus(const CString& gitdir, const CString& path, git_wc_status_kind* dirstatus, FILL_STATUS_CALLBACK callback, void* pData);
82 static int GetFileList(const CString& path, std::vector<CGitFileName>& list, bool& isRepoRoot);
83 static bool CheckAndUpdateIgnoreFiles(const CString& gitdir, const CString& subpaths, bool isDir);
84 /** Checks whether a file/directory is ignored - does not reload .ignore files */
85 static bool IsIgnored(const CString &gitdir, const CString &path, bool isDir);
86 static bool IsExistIndexLockFile(CString gitdir);
87 static bool ReleasePath(const CString &gitdir);
88 static bool ReleasePathsRecursively(const CString &rootpath);
90 GitStatus();
92 /**
93 * Reads the git status of the working copy entry. No
94 * recurse is done, even if the entry is a directory.
95 * If the status of the text and property part are different
96 * then the more important status is returned.
98 static int GetAllStatus(const CTGitPath& path, bool bIsRecursive, git_wc_status2_t& status);
101 * Returns the status which is more "important" of the two statuses specified.
102 * This is used for the "recursive" status functions on folders - i.e. which status
103 * should be returned for a folder which has several files with different statuses
104 * in it.
106 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
108 static void AdjustFolderStatus(git_wc_status_kind& status);
111 * Reads the git text status of the working copy entry. No
112 * recurse is done, even if the entry is a directory.
113 * The result is stored in the public member variable status.
114 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
116 * \param path the pathname of the entry
117 * \param update true if the status should be updated with the repository. Default is false.
118 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
119 * \remark If the return value is -2 then the status could not be obtained.
121 void GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
124 * This member variable hold the status of the last call to GetStatus().
126 git_wc_status2_t * status; ///< the status result of GetStatus()
128 private:
129 git_wc_status2_t m_status; // used for GetStatus
132 * Returns a numeric value indicating the importance of a status.
133 * A higher number indicates a more important status.
135 static int GetStatusRanking(git_wc_status_kind status);