Fix typos
[TortoiseGit.git] / src / Git / GitStatus.h
blob15bead87f6567b8970599ee3ed9c285942c8d974
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018, 2023 - 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 struct CGitFileName;
26 #include "GitHash.h"
28 enum 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
41 struct git_wc_status2_t
43 git_wc_status_kind status = git_wc_status_none;
45 bool assumeValid = false;
46 bool skipWorktree = false;
49 #define MAX_STATUS_STRING_LENGTH 256
51 using FILL_STATUS_CALLBACK = BOOL(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, bool ignoreCase);
83 static bool IsExistIndexLockFile(CString gitdir);
84 static bool ReleasePath(const CString &gitdir);
85 static bool ReleasePathsRecursively(const CString &rootpath);
87 GitStatus();
89 /**
90 * Reads the git status of the working copy entry. No
91 * recurse is done, even if the entry is a directory.
92 * If the status of the text and property part are different
93 * then the more important status is returned.
95 static int GetAllStatus(const CTGitPath& path, bool bIsRecursive, git_wc_status2_t& status);
97 /**
98 * Returns the status which is more "important" of the two statuses specified.
99 * This is used for the "recursive" status functions on folders - i.e. which status
100 * should be returned for a folder which has several files with different statuses
101 * in it.
103 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
105 static void AdjustFolderStatus(git_wc_status_kind& status);
108 * Reads the git text status of the working copy entry. No
109 * recurse is done, even if the entry is a directory.
110 * The result is stored in the public member variable status.
111 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
113 * \param path the pathname of the entry
114 * \param update true if the status should be updated with the repository. Default is false.
115 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
116 * \remark If the return value is -2 then the status could not be obtained.
118 void GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
121 * This member variable hold the status of the last call to GetStatus().
123 git_wc_status2_t* status = nullptr; ///< the status result of GetStatus()
125 private:
126 git_wc_status2_t m_status; // used for GetStatus
129 * Returns a numeric value indicating the importance of a status.
130 * A higher number indicates a more important status.
132 static int GetStatusRanking(git_wc_status_kind status);