1
// TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2008, 2014 - TortoiseSVN
4 // Copyright (C) 2012-2013, 2018-2019, 2021-2023 - Sven Strickroth <email@cs-ware.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "FileTextLines.h"
24 #define PATCHSTATE_REMOVED 0
25 #define PATCHSTATE_ADDED 1
26 #define PATCHSTATE_CONTEXT 2
29 * \ingroup TortoiseMerge
31 * Handles unified diff files, parses them and also is able to
32 * apply those diff files.
40 BOOL
OpenUnifiedDiffFile(const CString
& filename
);
41 int PatchFile(const int strip
, const int nIndex
, const CString
& sPath
, const CString
& sSavePath
= L
"", const CString
& sBaseFile
= L
"", const bool force
= false);
42 int GetNumberOfFiles() const { return static_cast<int>(m_arFileDiffs
.size()); }
43 CString
GetFilename(int nIndex
);
44 CString
GetRevision(int nIndex
);
45 CString
GetFilename2(int nIndex
);
46 CString
GetRevision2(int nIndex
);
47 CString
GetFullPath(const CString
& sPath
, int nIndex
, int fileno
= 0);
48 CString
GetErrorMessage() const {return m_sErrorMessage
;}
49 CString
CheckPatchPath(const CString
& path
);
53 BOOL
HasExpandedKeyWords(const CString
& line
) const;
54 int CountMatches(const CString
& path
);
55 int CountDirMatches(const CString
& path
);
56 CString
RemoveUnicodeBOM(const CString
& str
) const;
57 bool HasUnicodeBOM(const CString
& str
) const;
59 BOOL
ParsePatchFile(CFileTextLines
&PatchLines
);
62 * Strips the filename by removing m_nStrip prefixes.
64 CString
Strip(const CString
& filename
) const;
67 LONG lRemoveStart
= 0;
68 LONG lRemoveLength
= 0;
72 CStdDWORDArray arLinesStates
;
73 std::vector
<EOL
> arEOLs
;
82 std::vector
<std::unique_ptr
<Chunk
>> chunks
;
87 std::vector
<std::unique_ptr
<Chunks
>> m_arFileDiffs
;
88 CString m_sErrorMessage
;
89 CFileTextLines::UnicodeType m_UnicodeType
= CFileTextLines::UnicodeType::AUTOTYPE
;
92 * Defines how many prefixes are removed from the paths in the
93 * patch file. This allows applying patches which contain absolute
94 * paths or a prefix which differs in the patch and the working copy.
95 * Example: A filename like "/home/ts/my-working-copy/dir/file.txt"
96 * stripped by 4 prefixes is interpreted as "dir/file.txt"
100 #ifdef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
102 const auto& GetChunks(int index
) const { return m_arFileDiffs
[index
]->chunks
; };