OSDN Git Service

Git Blame Can Show Log
[tortoisegit/TortoiseGitJp.git] / src / Git / TGitPath.h
1 #pragma once\r
2 \r
3 class CTGitPath\r
4 {\r
5 public:\r
6         CTGitPath(void);\r
7         ~CTGitPath(void);\r
8  CTGitPath(const CString& sUnknownPath);\r
9 public:\r
10         enum\r
11         {       \r
12                 LOGACTIONS_ADDED        = 0x00000001,\r
13                 LOGACTIONS_MODIFIED     = 0x00000002,\r
14                 LOGACTIONS_REPLACED     = 0x00000004,\r
15                 LOGACTIONS_DELETED      = 0x00000008,\r
16                 LOGACTIONS_UNVER        = 0x80000000,\r
17                 LOGACTIONS_IGNORE       = 0x40000000,\r
18                 LOGACTIONS_CONFLICT = 0x20000000,\r
19         };\r
20 \r
21         CString m_StatAdd;\r
22         CString m_StatDel;\r
23         int             m_Action;\r
24         bool    m_Checked;\r
25         int     ParserAction(CString action);\r
26         CString GetActionName();\r
27         /**\r
28          * Set the path as an UTF8 string with forward slashes\r
29          */\r
30         void SetFromGit(const char* pPath);\r
31         void SetFromGit(const char* pPath, bool bIsDirectory);\r
32         void SetFromGit(const CString& sPath);\r
33         /**\r
34          * Set the path as UNICODE with backslashes\r
35          */\r
36         void SetFromWin(LPCTSTR pPath);\r
37         void SetFromWin(const CString& sPath);\r
38         void SetFromWin(const CString& sPath, bool bIsDirectory);\r
39         /**\r
40          * Set the path from an unknown source.\r
41          */\r
42         void SetFromUnknown(const CString& sPath);\r
43         /**\r
44          * Returns the path in Windows format, i.e. with backslashes\r
45          */\r
46         LPCTSTR GetWinPath() const;\r
47         /**\r
48          * Returns the path in Windows format, i.e. with backslashes\r
49          */\r
50         const CString& GetWinPathString() const;\r
51         /**\r
52          * Returns the path with forward slashes.\r
53          */\r
54         const CString& GetGitPathString() const;\r
55         /**\r
56          * Returns the path completely prepared to be fed the the Git APIs\r
57          * It will be in UTF8, with URLs escaped, if necessary\r
58          */\r
59 //      const char* GetGitApiPath(apr_pool_t *pool) const;\r
60         /**\r
61          * Returns the path for showing in an UI.\r
62          *\r
63          * URL's are returned with forward slashes, unescaped if necessary\r
64          * Paths are returned with backward slashes\r
65          */\r
66         const CString& GetUIPathString() const;\r
67         /**\r
68          * Checks if the path is an URL.\r
69          */\r
70         bool IsUrl() const;\r
71         /**\r
72          * Returns true if the path points to a directory\r
73          */\r
74         bool IsDirectory() const;\r
75         /**\r
76          * Returns the directory. If the path points to a directory, then the path\r
77          * is returned unchanged. If the path points to a file, the path to the \r
78          * parent directory is returned.\r
79          */\r
80         CTGitPath GetDirectory() const;\r
81         /**\r
82         * Returns the the directory which contains the item the path refers to.\r
83         * If the path is a directory, then this returns the directory above it.\r
84         * If the path is to a file, then this returns the directory which contains the path\r
85         * parent directory is returned.\r
86         */\r
87         CTGitPath GetContainingDirectory() const;\r
88         /**\r
89          * Get the 'root path' (e.g. "c:\") - Used to pass to GetDriveType \r
90          */\r
91         CString GetRootPathString() const;\r
92         /**\r
93          * Returns the filename part of the full path.\r
94          * \remark don't call this for directories.\r
95          */\r
96         CString GetFilename() const;\r
97         CString GetBaseFilename() const;\r
98         /**\r
99          * Returns the item's name without the full path.\r
100          */\r
101         CString GetFileOrDirectoryName() const;\r
102         /**\r
103          * Returns the item's name without the full path, unescaped if necessary.\r
104          */\r
105         CString GetUIFileOrDirectoryName() const;\r
106         /**\r
107          * Returns the file extension, including the dot.\r
108          * \remark Returns an empty string for directories\r
109          */\r
110         CString GetFileExtension() const;\r
111 \r
112         bool IsEmpty() const;\r
113         void Reset();\r
114         /**\r
115          * Checks if two paths are equal. The slashes are taken care of.\r
116          */\r
117         bool IsEquivalentTo(const CTGitPath& rhs) const;\r
118         bool IsEquivalentToWithoutCase(const CTGitPath& rhs) const;\r
119         bool operator==(const CTGitPath& x) const {return IsEquivalentTo(x);}\r
120         \r
121         /**\r
122          * Checks if \c possibleDescendant is a child of this path.\r
123          */\r
124         bool IsAncestorOf(const CTGitPath& possibleDescendant) const;\r
125         /**\r
126          * Get a string representing the file path, optionally with a base \r
127          * section stripped off the front\r
128          * Returns a string with fwdslash paths \r
129          */\r
130         CString GetDisplayString(const CTGitPath* pOptionalBasePath = NULL) const;\r
131         /**\r
132          * Compares two paths. Slash format is irrelevant.\r
133          */\r
134         static int Compare(const CTGitPath& left, const CTGitPath& right);\r
135 \r
136         /** As PredLeftLessThanRight, but for checking if paths are equivalent \r
137          */\r
138         static bool PredLeftEquivalentToRight(const CTGitPath& left, const CTGitPath& right);\r
139 \r
140         /** Checks if the left path is pointing to the same working copy path as the right.\r
141          * The same wc path means the paths are equivalent once all the admin dir path parts\r
142          * are removed. This is used in the TGitCache crawler to filter out all the 'duplicate'\r
143          * paths to crawl.\r
144          */\r
145         static bool PredLeftSameWCPathAsRight(const CTGitPath& left, const CTGitPath& right);\r
146         \r
147         static bool CheckChild(const CTGitPath &parent, const CTGitPath& child);\r
148 \r
149         /**\r
150          * appends a string to this path. \r
151          *\remark - missing slashes are not added - this is just a string concatenation, but with\r
152          * preservation of the proper caching behavior.\r
153          * If you want to join a file- or directory-name onto the path, you should use AppendPathString\r
154          */\r
155         void AppendRawString(const CString& sAppend);\r
156 \r
157         /**\r
158         * appends a part of a path to this path. \r
159         *\remark - missing slashes are dealt with properly. Don't use this to append a file extension, for example\r
160         * \r
161         */\r
162         void AppendPathString(const CString& sAppend);\r
163 \r
164         /**\r
165          * Get the file modification time - returns zero for files which don't exist\r
166          * Returns a FILETIME structure cast to an __int64, for easy comparisons\r
167          */\r
168         __int64 GetLastWriteTime() const;\r
169         \r
170         bool IsReadOnly() const;\r
171         \r
172         /**\r
173          * Checks if the path really exists.\r
174          */\r
175         bool Exists() const;\r
176         \r
177         /**\r
178          * Deletes the file/folder\r
179          * \param bTrash if true, uses the Windows trash bin when deleting.\r
180          */\r
181         bool Delete(bool bTrash) const;\r
182 \r
183         /**\r
184          * Checks if a Subversion admin directory is present. For files, the check\r
185          * is done in the same directory. For folders, it checks if the folder itself\r
186          * contains an admin directory.\r
187          */\r
188         bool HasAdminDir() const;\r
189         \r
190         /**\r
191          * Checks if the path point to or below a Subversion admin directory (.Git).\r
192          */\r
193         bool IsAdminDir() const;\r
194 \r
195         void SetCustomData(LPARAM lp) {m_customData = lp;}\r
196         LPARAM GetCustomData() {return m_customData;}\r
197 \r
198         /**\r
199          * Checks if the path or URL is valid on Windows.\r
200          * A path is valid if conforms to the specs in the windows API.\r
201          * An URL is valid if the path checked out from it is valid\r
202          * on windows. That means an URL which is valid according to the WWW specs\r
203          * isn't necessarily valid as a windows path (e.g. http://myserver.com/repos/file:name \r
204          * is a valid URL, but the path is illegal on windows ("file:name" is illegal), so\r
205          * this function would return \c false for that URL).\r
206          */\r
207         bool IsValidOnWindows() const;\r
208 \r
209         /**\r
210          * Checks to see if the path or URL represents one of the special directories\r
211          * (branches, tags, or trunk).\r
212          */\r
213         bool IsSpecialDirectory() const;\r
214 private:\r
215         // All these functions are const, and all the data\r
216         // is mutable, in order that the hidden caching operations\r
217         // can be carried out on a const CTGitPath object, which is what's \r
218         // likely to be passed between functions\r
219         // The public 'SetFromxxx' functions are not const, and so the proper \r
220         // const-correctness semantics are preserved\r
221         void SetFwdslashPath(const CString& sPath) const;\r
222         void SetBackslashPath(const CString& sPath) const;\r
223         void SetUTF8FwdslashPath(const CString& sPath) const;\r
224         void EnsureBackslashPathSet() const;\r
225         void EnsureFwdslashPathSet() const;\r
226         /**\r
227          * Checks if two path strings are equal. No conversion of slashes is done!\r
228          * \remark for slash-independent comparison, use IsEquivalentTo()\r
229          */\r
230         static bool ArePathStringsEqual(const CString& sP1, const CString& sP2);\r
231         static bool ArePathStringsEqualWithCase(const CString& sP1, const CString& sP2);\r
232         \r
233         /**\r
234          * Adds the required trailing slash to local root paths such as 'C:'\r
235          */\r
236         void SanitizeRootPath(CString& sPath, bool bIsForwardPath) const;\r
237 \r
238         void UpdateAttributes() const;\r
239         \r
240 \r
241 \r
242 private:\r
243         mutable CString m_sBackslashPath;\r
244         mutable CString m_sFwdslashPath;\r
245         mutable CString m_sUIPath;\r
246         mutable CStringA m_sUTF8FwdslashPath;\r
247         mutable CStringA m_sUTF8FwdslashPathEscaped;\r
248         // Have we yet determined if this is a directory or not?\r
249         mutable bool m_bDirectoryKnown;\r
250         mutable bool m_bIsDirectory;\r
251         mutable bool m_bLastWriteTimeKnown;\r
252         mutable bool m_bURLKnown;\r
253         mutable bool m_bIsURL;\r
254         mutable __int64 m_lastWriteTime;\r
255         mutable bool m_bIsReadOnly;\r
256         mutable bool m_bHasAdminDirKnown;\r
257         mutable bool m_bHasAdminDir;\r
258         mutable bool m_bIsValidOnWindowsKnown;\r
259         mutable bool m_bIsValidOnWindows;\r
260         mutable bool m_bIsAdminDirKnown;\r
261         mutable bool m_bIsAdminDir;\r
262         mutable bool m_bExists;\r
263         mutable bool m_bExistsKnown;\r
264         mutable LPARAM m_customData;\r
265         mutable bool m_bIsSpecialDirectoryKnown;\r
266         mutable bool m_bIsSpecialDirectory;\r
267 \r
268         friend bool operator<(const CTGitPath& left, const CTGitPath& right);\r
269 };\r
270 /**\r
271  * Compares two paths and return true if left is earlier in sort order than right\r
272  * (Uses CTGitPath::Compare logic, but is suitable for std::sort and similar)\r
273  */\r
274  bool operator<(const CTGitPath& left, const CTGitPath& right);\r
275 \r
276 \r
277 //////////////////////////////////////////////////////////////////////////\r
278 \r
279 /**\r
280  * \ingroup Utils\r
281  * This class represents a list of paths\r
282  */\r
283 class CTGitPathList \r
284 {\r
285 public:\r
286         CTGitPathList();\r
287         // A constructor which allows a path list to be easily built with one initial entry in\r
288         explicit CTGitPathList(const CTGitPath& firstEntry);\r
289         int m_Action;\r
290 public:\r
291         void AddPath(const CTGitPath& newPath);\r
292         bool LoadFromFile(const CTGitPath& filename);\r
293         bool WriteToFile(const CString& sFilename, bool bANSI = false) const;\r
294         CTGitPath * LookForGitPath(CString path);\r
295         int     ParserFromLog(CString &log);\r
296         int FillUnRev(int Action,CTGitPathList *list=NULL);\r
297         int GetAction();\r
298         /**\r
299          * Load from the path argument string, when the 'path' parameter is used\r
300          * This is a list of paths, with '*' between them\r
301          */\r
302         void LoadFromAsteriskSeparatedString(const CString& sPathString);\r
303         CString CreateAsteriskSeparatedString() const;\r
304 \r
305         int GetCount() const;\r
306         void Clear();\r
307         const CTGitPath& operator[](INT_PTR index) const;\r
308         bool AreAllPathsFiles() const;\r
309         bool AreAllPathsFilesInOneDirectory() const;\r
310         CTGitPath GetCommonDirectory() const;\r
311         CTGitPath GetCommonRoot() const;\r
312         void SortByPathname(bool bReverse = false);\r
313         /** \r
314          * Delete all the files in the list, then clear the list.\r
315          * \param bTrash if true, the items are deleted using the Windows trash bin\r
316          */\r
317         void DeleteAllFiles(bool bTrash);\r
318         /** Remove duplicate entries from the list (sorts the list as a side-effect */\r
319         void RemoveDuplicates();\r
320         /** Removes all paths which are on or in a Subversion admin directory */\r
321         void RemoveAdminPaths();\r
322         void RemovePath(const CTGitPath& path);\r
323         void RemoveItem(CTGitPath &path);\r
324         /** \r
325          * Removes all child items and leaves only the top folders. Useful if you\r
326          * create the list to remove them (i.e. if you remove a parent folder, the\r
327          * child files and folders don't have to be deleted anymore)\r
328          */\r
329         void RemoveChildren();\r
330 \r
331         /** Checks if two CTGitPathLists are the same */\r
332         bool IsEqual(const CTGitPathList& list);\r
333 \r
334         /** Convert into the Git API parameter format */\r
335 //      apr_array_header_t * MakePathArray (apr_pool_t *pool) const;\r
336 \r
337 private:\r
338         typedef std::vector<CTGitPath> PathVector;\r
339         PathVector m_paths;\r
340         // If the list contains just files in one directory, then\r
341         // this contains the directory name\r
342         mutable CTGitPath m_commonBaseDirectory;\r
343 };\r