Fix some warnings
[TortoiseGit.git] / src / Git / GitPatch.h
blob3ac514544ec8ef43059ec7604990e1d3f7c36fa9
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2012 - TortoiseGit
4 // Copyright (C) 2010-2012 - 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.
20 #pragma once
22 #include "TGitPath.h"
23 #include "TempFile.h"
24 #include "SysProgressDlg.h"
26 #include "Patch.h"
28 class GitPatch
30 public:
31 GitPatch();
32 ~GitPatch();
34 /**
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);
42 /**
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; }
48 /**
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);
57 /**
58 * Applies the patch for the given \c path, including property changes if necessary.
60 bool PatchPath(const CString& path);
62 /**
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) const;
69 /**
70 * returns the number of files that are affected by the patchfile.
72 int GetNumberOfFiles() const { return (int)m_filePaths.size(); }
74 /**
75 * Returns the path of the affected file
77 CString GetFilePath(int index) const { return m_filePaths[index].path; }
79 /**
80 * Returns the number of failed hunks for the affected file
82 int GetFailedHunks(int index) const { return m_filePaths[index].rejects; }
84 /**
85 * Returns true if there are content modifications for the path
87 bool GetContentMods(int index) const { return m_filePaths[index].content; }
89 /**
90 * Returns true if there are property modifications for the path
92 bool GetPropMods(int index) const { return m_filePaths[index].props; }
94 /**
95 * Returns the path of the affected file, stripped by m_nStrip.
97 CString GetStrippedPath(int nIndex) const;
99 /**
100 * Returns a string containing the last error message.
102 CString GetErrorMessage() const { return m_errorStr; }
105 * Removes the file from version control
107 bool RemoveFile(const CString& path);
109 CString GetPatchRejects(int nIndex) const;
111 private:
112 int CountMatches(const CString& path) const;
113 int CountDirMatches(const CString& path) const;
115 * Strips the filename by removing m_nStrip prefixes.
117 CString Strip(const CString& filename) const;
119 typedef struct PathRejects
121 CString path;
122 int rejects;
123 CString resultPath;
124 CString rejectsPath;
125 bool content;
126 bool props;
128 std::vector<PathRejects> m_filePaths;
129 int m_nStrip;
130 bool m_bSuccessfullyPatched;
131 int m_nRejected;
132 CString m_patchfile;
133 CString m_targetpath;
134 CString m_testPath;
135 CString m_filetopatch;
136 CString m_errorStr;
137 CSysProgressDlg * m_pProgDlg;
139 CPatch m_patch;
140 bool ApplyPatches();
141 bool PatchFile(int nIndex, CString &datapath);