# # # patch "std_hooks.lua" # from [fc9105dfa61de34c02ce6453f6ac616f581d03f5] # to [6ca29b67a6913342668b4cfa2464a37654615280] # ============================================================ --- std_hooks.lua fc9105dfa61de34c02ce6453f6ac616f581d03f5 +++ std_hooks.lua 6ca29b67a6913342668b4cfa2464a37654615280 @@ -476,49 +476,90 @@ mergers.rcsmerge = { wanted = function () return os.getenv("MTN_RCSMERGE") ~= nil end } -mergers.diffutils = { - cmd = function (tbl) - local ret = execute( - "diff3", - "--merge", - "--label", string.format("%s [left]", tbl.left_path ), - "--label", string.format("%s [ancestor]", tbl.anc_path ), - "--label", string.format("%s [right]", tbl.right_path), - tbl.lfile, - tbl.afile, - tbl.rfile - ) - if (ret == 2) then - io.write(gettext("Error running GNU diffutils 3-way difference tool 'diff3'\n")) - return false - end - local ret = execute( - "sdiff", - "--diff-program=diff", - "--suppress-common-lines", - "--minimal", - "--output", tbl.outfile, - tbl.lfile, - tbl.rfile - ) - if (ret == 2) then - io.write(gettext("Error running GNU diffutils 2-two merging tool 'sdiff'\n")) - return false - end - return tbl.outfile - end, - available = - function () - return program_exists_in_path("diff3") and - program_exists_in_path("sdiff") and - program_exists_in_path("diff"); - end, - wanted = - function () - return true - end -} +-- GNU diffutils based merging +mergers.diffutils_new = { + -- merge procedure execution + cmd = function (tbl) + if os.getenv("MTN_MERGE_DIFFUTILS") == "partial" then + -- partial batch/non-modal 3-way merge "resolution": + -- simply merge content with help of conflict markers + io.write("performing 3-way merge, adding conflict markers\n") + local ret = execute( + "sh", "-c", + "diff3 " .. + "--merge " .. + "--show-overlap " .. + "--label '" .. string.format("%s [left]", tbl.left_path ) .. "' " .. + "--label '" .. string.format("%s [ancestor]", tbl.anc_path ) .. "' " .. + "--label '" .. string.format("%s [right]", tbl.right_path) .. "' " .. + string.gsub(tbl.lfile, "\\", "/") .. " " .. + string.gsub(tbl.afile, "\\", "/") .. " " .. + string.gsub(tbl.rfile, "\\", "/") .. " " .. + ">" .. string.gsub(tbl.outfile, "\\", "/") + ) + if ret == 2 then + io.write(gettext("Error running GNU diffutils 3-way difference/merge tool 'diff3'\n")) + return false + end + return tbl.outfile + else + -- real interactive/modal 3/2-way merge resolution: + -- display 3-way merge conflict and perform 2-way merge resolution + -- display 3-way merge conflict (batch) + io.write("\n") + io.write("---- CONFLICT SUMMARY ------------------------------------------------\n") + local ret = execute( + "diff3", + "--merge", + "--show-overlap", + "--label", string.format("%s [left]", tbl.left_path ), + "--label", string.format("%s [ancestor]", tbl.anc_path ), + "--label", string.format("%s [right]", tbl.right_path), + string.gsub(tbl.lfile, "\\", "/") .. "", + string.gsub(tbl.afile, "\\", "/") .. "", + string.gsub(tbl.rfile, "\\", "/") .. "" + ) + if ret == 2 then + io.write(gettext("Error running GNU diffutils 3-way difference/merge tool 'diff3'\n")) + return false + end + + -- perform 2-way merge resolution (interactive) + io.write("\n") + io.write("---- CONFLICT RESOLUTION ---------------------------------------------\n") + local ret = execute( + "sdiff", + "--diff-program=diff", + "--suppress-common-lines", + "--minimal", + "--output", string.gsub(tbl.outfile, "\\", "/"), + string.gsub(tbl.lfile, "\\", "/") .. "", + string.gsub(tbl.rfile, "\\", "/") .. "" + ) + if ret == 2 then + io.write(gettext("Error running GNU diffutils 2-way merging tool 'sdiff'\n")) + return false + end + return tbl.outfile + end + end, + + -- merge procedure availability check + available = function () + -- make sure the GNU diffutils tools are available + return program_exists_in_path("diff3") and + program_exists_in_path("sdiff") and + program_exists_in_path("diff"); + end, + + -- merge procedure request check + wanted = function () + -- assume it is requested (if it is available at all) + return true + end +} + mergers.emacs = { cmd = function (tbl) local emacs