MCPcopy Create free account
hub / github.com/WinMerge/winmerge / OnToolsGeneratePatch

Method OnToolsGeneratePatch

Src/DirView.cpp:3191–3232  ·  view source on GitHub ↗

* @brief Generate patch from files selected. * * Creates a patch from selected files in active directory compare, or * active file compare. Files in file compare must be saved before * creating a patch. */

Source from the content-addressed store, hash-verified

3189 * creating a patch.
3190 */
3191void CDirView::OnToolsGeneratePatch()
3192{
3193 CPatchTool patcher;
3194 const CDiffContext& ctxt = GetDiffContext();
3195
3196 // Get selected items from folder compare
3197 bool bValidFiles = true;
3198 for (DirItemIterator it = SelBegin(); bValidFiles && it != SelEnd(); ++it)
3199 {
3200 const DIFFITEM &item = *it;
3201 if (item.diffcode.isBin())
3202 {
3203 I18n::MessageBox(IDS_CANNOT_CREATE_BINARYPATCH, MB_ICONWARNING |
3204 MB_DONT_DISPLAY_AGAIN, IDS_CANNOT_CREATE_BINARYPATCH);
3205 bValidFiles = false;
3206 }
3207
3208 if (bValidFiles)
3209 {
3210 // Format full paths to files (leftFile/rightFile)
3211 String leftFile = item.getFilepath(0, ctxt.GetNormalizedPath(0));
3212 if (!leftFile.empty())
3213 leftFile = paths::ConcatPath(leftFile, item.diffFileInfo[0].filename);
3214 String rightFile = item.getFilepath(1, ctxt.GetNormalizedPath(1));
3215 if (!rightFile.empty())
3216 rightFile = paths::ConcatPath(rightFile, item.diffFileInfo[1].filename);
3217
3218 // Format relative paths to files in folder compare
3219 String leftpatch = item.diffFileInfo[0].path;
3220 if (!leftpatch.empty())
3221 leftpatch += _T("/");
3222 leftpatch += item.diffFileInfo[0].filename;
3223 String rightpatch = item.diffFileInfo[1].path;
3224 if (!rightpatch.empty())
3225 rightpatch += _T("/");
3226 rightpatch += item.diffFileInfo[1].filename;
3227 patcher.AddFiles(leftFile, leftpatch, rightFile, rightpatch);
3228 }
3229 }
3230
3231 patcher.CreatePatch();
3232}
3233
3234/**
3235 * @brief Add special items for non-recursive compare

Callers

nothing calls this directly

Calls 8

ConcatPathFunction · 0.85
getFilepathMethod · 0.80
GetNormalizedPathMethod · 0.80
AddFilesMethod · 0.80
CreatePatchMethod · 0.80
MessageBoxFunction · 0.70
isBinMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected