Merge branch 'scintilla-372'
[TortoiseGit.git] / src / Git / GitStatus.h
blobf16f89bbae1218b8ea1d43561f99bf1cde46f71d
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.
20 #pragma once
21 #include "TGitPath.h"
23 class CGitFileName;
25 #include "TGitPath.h"
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_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,
40 git_wc_status_merged,
41 git_wc_status_added,
42 git_wc_status_conflicted,
43 git_wc_status_obstructed,
44 git_wc_status_unknown,
45 }git_wc_status_kind;
47 typedef enum
49 git_depth_empty,
50 git_depth_infinity,
51 git_depth_unknown,
52 git_depth_files,
53 git_depth_immediates,
54 }git_depth_t;
56 #define GIT_REV_ZERO L"0000000000000000000000000000000000000000"
57 #define GIT_INVALID_REVNUM L""
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;
68 bool assumeValid;
69 bool skipWorktree;
70 } git_wc_status2;
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)
78 CString path(part1);
79 path += L'\\';
80 path += part2;
81 return path;
84 /**
85 * \ingroup Git
86 * Handles git status of working copies.
88 class GitStatus
90 public:
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 CheckAndUpdateIgnoreFiles(const CString& gitdir, const CString& subpaths, bool isDir);
97 static int IsUnderVersionControl(const CString &gitdir, const CString &path, bool isDir,bool *isVersion);
98 /** Checks whether a file/directory is ignored - does not reload .ignore files */
99 static bool IsIgnored(const CString &gitdir, const CString &path, bool isDir);
100 static bool IsExistIndexLockFile(CString gitdir);
101 static bool ReleasePath(const CString &gitdir);
102 static bool ReleasePathsRecursively(const CString &rootpath);
104 public:
105 GitStatus();
108 * Reads the git status of the working copy entry. No
109 * recurse is done, even if the entry is a directory.
110 * If the status of the text and property part are different
111 * then the more important status is returned.
113 static git_wc_status_kind GetAllStatus(const CTGitPath& path, git_depth_t depth = git_depth_empty, bool* assumeValid = nullptr, bool* skipWorktree = nullptr);
116 * Returns the status which is more "important" of the two statuses specified.
117 * This is used for the "recursive" status functions on folders - i.e. which status
118 * should be returned for a folder which has several files with different statuses
119 * in it.
121 static git_wc_status_kind GetMoreImportant(git_wc_status_kind status1, git_wc_status_kind status2);
124 * Checks if a status is "important", i.e. if the status indicates that the user should know about it.
125 * E.g. a "normal" status is not important, but "modified" is.
126 * \param status the status to check
128 static BOOL IsImportant(git_wc_status_kind status) {return (GetMoreImportant(git_wc_status_added, status)==status);}
131 * Reads the git text status of the working copy entry. No
132 * recurse is done, even if the entry is a directory.
133 * The result is stored in the public member variable status.
134 * Use this method if you need detailed information about a file/folder, not just the raw status (like "normal", "modified").
136 * \param path the pathname of the entry
137 * \param update true if the status should be updated with the repository. Default is false.
138 * \return If update is set to true the HEAD revision of the repository is returned. If update is false then -1 is returned.
139 * \remark If the return value is -2 then the status could not be obtained.
141 void GetStatus(const CTGitPath& path, bool update = false, bool noignore = false, bool noexternals = false);
144 * This member variable hold the status of the last call to GetStatus().
146 git_wc_status2_t * status; ///< the status result of GetStatus()
148 private:
149 git_wc_status2_t m_status; // used for GetStatus
152 * Returns a numeric value indicating the importance of a status.
153 * A higher number indicates a more important status.
155 static int GetStatusRanking(git_wc_status_kind status);