1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2012 - TortoiseGit
4 // Copyright (C) 2010-2012, 2015 - TortoiseSVN
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.
24 #include "SysProgressDlg.h"
35 * Does a dry run of the patching, fills in all the arrays.
36 * Call this function first.
37 * The progress dialog is used to show progress info if the initialization takes a long time.
38 * \return the number of files affected by the patchfile, 0 in case of an error
40 int Init(const CString
& patchfile
, const CString
& targetpath
, CSysProgressDlg
*pPprogDlg
);
43 * Sets the target path. Use this after getting a new path from CheckPatchPath()
45 void SetTargetPath(const CString
& targetpath
) { m_targetpath
= targetpath
; m_targetpath
.Replace('\\', '/'); }
46 CString
GetTargetPath() { return m_targetpath
; }
49 * Finds the best path to apply the patch file. Starting from the targetpath
50 * specified in Init() first upwards, then downwards.
51 * \remark this function shows a progress dialog and also shows a dialog asking
52 * the user to accept a possible better target path.
53 * \return the best path to apply the patch to.
55 CString
CheckPatchPath(const CString
& path
);
58 * Applies the patch for the given \c path, including property changes if necessary.
60 bool PatchPath(const CString
& path
);
63 * Returns the paths of the patch result for the \c sPath.
64 * The patch is applied in the Init() method.
65 * \return the number of failed hunks, 0 if everything was applied successfully, -1 on error
67 int GetPatchResult(const CString
& sPath
, CString
& sSavePath
, CString
& sRejectPath
, CString
&sBasePath
) const;
70 * returns the number of files that are affected by the patchfile.
72 int GetNumberOfFiles() const { return (int)m_filePaths
.size(); }
75 * Returns the path of the affected file
77 CString
GetFilePath(int index
) const { return m_filePaths
[index
].path
; }
80 * Returns the number of failed hunks for the affected file
82 int GetFailedHunks(int index
) const { return m_filePaths
[index
].rejects
; }
84 bool GetHasConflict(int index
) const { return !m_filePaths
[index
].basePath
.IsEmpty(); }
87 * Returns true if there are content modifications for the path
89 bool GetContentMods(int index
) const { return m_filePaths
[index
].content
; }
92 * Returns true if there are property modifications for the path
94 bool GetPropMods(int index
) const { return m_filePaths
[index
].props
; }
97 * Returns the path of the affected file, stripped by m_nStrip.
99 CString
GetStrippedPath(int nIndex
) const;
102 * Returns a string containing the last error message.
104 CString
GetErrorMessage() const { return m_errorStr
; }
107 * Removes the file from version control
109 bool RemoveFile(const CString
& path
);
111 CString
GetPatchRejects(int nIndex
) const;
114 int CountMatches(const CString
& path
) const;
115 int CountDirMatches(const CString
& path
) const;
117 * Strips the filename by removing m_nStrip prefixes.
119 CString
Strip(const CString
& filename
) const;
125 CString basePath
; // empty if patch applies cleany to local file; path to tempfile of base-version if patch only applies cleanly to base-version
131 std::vector
<PathRejects
> m_filePaths
;
133 bool m_bSuccessfullyPatched
;
136 CString m_targetpath
;
138 CString m_filetopatch
;
140 CSysProgressDlg
* m_pProgDlg
;
144 bool PatchFile(int nIndex
, CString
&datapath
);