# # patch "ChangeLog" # from [7dc21d3a46c6ecd94685ab21e67b131b32002f12] # to [234513e3838d423b24d5d6c98f70ce995c8bab6e] # # patch "std_hooks.lua" # from [0408707bb6b97eae7f8da61af7b35364dbd5a189] # to [d7bd0756c48ace573926197709e53eb24dae5f5f] # ======================================================================== --- ChangeLog 7dc21d3a46c6ecd94685ab21e67b131b32002f12 +++ ChangeLog 234513e3838d423b24d5d6c98f70ce995c8bab6e @@ -1,3 +1,7 @@ +2005-08-30 Petr Baudis + + * std_hooks.lua: Simple support for merging using merge(1) and vim. + 2005-08-30 Benoît Dejean * po/fr.po: Updated French translation. ======================================================================== --- std_hooks.lua 0408707bb6b97eae7f8da61af7b35364dbd5a189 +++ std_hooks.lua d7bd0756c48ace573926197709e53eb24dae5f5f @@ -279,14 +279,30 @@ end end -function merge3_vim_cmd(vim, lfile, afile, rfile, outfile) +function merge3_vim_cmd(vim, afile, lfile, rfile, outfile) return function() return execute(vim, "-f", "-d", "-c", string.format("file %s", outfile), - lfile, afile, rfile) + afile, lfile, rfile) end end +function merge3_rcsmerge_vim_cmd(merge, vim, lfile, afile, rfile, outfile) + return + function() + -- XXX: This is tough - should we check if conflict markers stay or not? + -- If so, we should certainly give the user some way to still force + -- the merge to proceed since they can appear in the files (and I saw + -- that). --pasky + if execute(merge, lfile, afile, rfile) == 0 then + copy_text_file(lfile, outfile); + return 0 + end + return execute(vim, "-f", "-c", string.format("file %s", outfile), + lfile) + end +end + function merge2_emacs_cmd(emacs, lfile, rfile, outfile) local elisp = "(ediff-merge-files \"%s\" \"%s\" nil \"%s\")" return @@ -366,6 +382,22 @@ return filename end +function copy_text_file(srcname, destname) + src = io.open(srcname, "r") + if (src == nil) then return nil end + dest = io.open(destname, "w") + if (dest == nil) then return nil end + + while true do + local line = src:read() + if line == nil then break end + dest:write(line, "\n") + end + + io.close(dest) + io.close(src) +end + function read_contents_of_file(filename, mode) tmp = io.open(filename, mode) if (tmp == nil) then @@ -488,7 +520,16 @@ local editor = os.getenv("EDITOR") if editor ~= nil then editor = string.lower(editor) else editor = "" end - if program_exists_in_path("kdiff3") then + local merge = os.getenv("MTMERGE") + -- TODO: Support for rcsmerge_emacs + if merge ~= nil and string.find(editor, "vim") ~= nil then + if os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then + cmd = merge3_rcsmerge_vim_cmd (merge, "gvim", lfile, afile, rfile, outfile) + elseif program_exists_in_path ("vim") then + cmd = merge3_rcsmerge_vim_cmd (merge, "vim", lfile, afile, rfile, outfile) + end + + elseif program_exists_in_path("kdiff3") then cmd = merge3_kdiff3_cmd (left_path, anc_path, right_path, merged_path, lfile, afile, rfile, outfile) elseif program_exists_in_path ("xxdiff") then cmd = merge3_xxdiff_cmd (left_path, anc_path, right_path, merged_path, lfile, afile, rfile, outfile)