OSDN Git Service

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