OSDN Git Service

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