Fixed issue #2495: "Show Reflog" dialog shows empty action for "push" entries
[TortoiseGit.git] / src / Git / GitPatch.h
blob2f181d3c95d71bbb23a9f859704cd28bff22a24d
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, CString &sBasePath) 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 bool GetHasConflict(int index) const { return !m_filePaths[index].basePath.IsEmpty(); }
86 /**
87 * Returns true if there are content modifications for the path
89 bool GetContentMods(int index) const { return m_filePaths[index].content; }
91 /**
92 * Returns true if there are property modifications for the path
94 bool GetPropMods(int index) const { return m_filePaths[index].props; }
96 /**
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;
113 private:
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;
121 typedef struct PathRejects
123 CString path;
124 int rejects;
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
126 CString resultPath;
127 CString rejectsPath;
128 bool content;
129 bool props;
131 std::vector<PathRejects> m_filePaths;
132 int m_nStrip;
133 bool m_bSuccessfullyPatched;
134 int m_nRejected;
135 CString m_patchfile;
136 CString m_targetpath;
137 CString m_testPath;
138 CString m_filetopatch;
139 CString m_errorStr;
140 CSysProgressDlg * m_pProgDlg;
142 CPatch m_patch;
143 bool ApplyPatches();
144 bool PatchFile(int nIndex, CString &datapath);