OSDN Git Service

Modify Git Clone Control Tab order
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / Patch.h
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "FileTextLines.h"\r
21 \r
22 \r
23 #define PATCHSTATE_REMOVED      0\r
24 #define PATCHSTATE_ADDED        1\r
25 #define PATCHSTATE_CONTEXT      2\r
26 \r
27 /**\r
28  * \ingroup TortoiseMerge\r
29  *\r
30  * Handles unified diff files, parses them and also is able to\r
31  * apply those diff files.\r
32  */\r
33 class CPatch\r
34 {\r
35 public:\r
36         CPatch(void);\r
37         ~CPatch(void);\r
38 \r
39         BOOL            OpenUnifiedDiffFile(const CString& filename);\r
40         BOOL            PatchFile(const CString& sPath, const CString& sSavePath = _T(""), const CString& sBaseFile = _T(""));\r
41         int                     GetNumberOfFiles() const  {return m_arFileDiffs.GetCount();}\r
42         CString         GetFilename(int nIndex);\r
43         CString         GetRevision(int nIndex);\r
44         CString         GetFilename2(int nIndex);\r
45         CString         GetRevision2(int nIndex);\r
46         CString         GetErrorMessage() const  {return m_sErrorMessage;}\r
47         CString         CheckPatchPath(const CString& path);\r
48 \r
49         /**\r
50          * Returns TRUE if stripping prefixes from the paths in the patch file\r
51          * allows the patch file to being applied. The variable m_nStrip is then set appropriately.\r
52          * Returns FALSE if stripping prefixes doesn't help. The variable m_nStrip is set to 0.\r
53          */\r
54         BOOL            StripPrefixes(const CString& path);\r
55 protected:\r
56         void            FreeMemory();\r
57         BOOL            HasExpandedKeyWords(const CString& line);\r
58         int                     CountMatches(const CString& path);\r
59         int                     CountDirMatches(const CString& path);\r
60         CString         RemoveUnicodeBOM(const CString& str);\r
61 \r
62         /**\r
63          * Strips the filename by removing m_nStrip prefixes.\r
64          */\r
65         CString         Strip(const CString& filename);\r
66         struct Chunk\r
67         {\r
68                 LONG                                    lRemoveStart;\r
69                 LONG                                    lRemoveLength;\r
70                 LONG                                    lAddStart;\r
71                 LONG                                    lAddLength;\r
72                 CStdCStringArray                arLines;\r
73                 CStdDWORDArray                  arLinesStates;\r
74                 std::vector<EOL>                arEOLs;\r
75         };\r
76 \r
77         struct Chunks\r
78         {\r
79                 CString                                 sFilePath;\r
80                 CString                                 sRevision;\r
81                 CString                                 sFilePath2;\r
82                 CString                                 sRevision2;\r
83                 CStdArray<Chunk*>               chunks;\r
84         };\r
85 \r
86         CStdArray<Chunks*>                      m_arFileDiffs;\r
87         CString                                         m_sErrorMessage;\r
88         CFileTextLines::UnicodeType m_UnicodeType;\r
89 \r
90         /**\r
91          * Defines how many prefixes are removed from the paths in the\r
92          * patch file. This allows applying patches which contain absolute\r
93          * paths or a prefix which differs in the patch and the working copy.\r
94          * Example: A filename like "/home/ts/my-working-copy/dir/file.txt"\r
95          * stripped by 4 prefixes is interpreted as "dir/file.txt"\r
96          */\r
97         int                                                     m_nStrip;\r
98         bool                                            m_IsGitPatch;\r
99 };\r