# # patch "monotone.texi" # from [7ea1616ac54dcdc917f82a71391509e1a9ab30fc] # to [4fb1363ab96b7475fb37f8a11dae6b43057c3af2] # # patch "std_hooks.lua" # from [075faf23ac29368ff871211f2014add6d4aba1ec] # to [3641b887fd48cb670b792d9ed0ee2f8dda14f836] # --- monotone.texi +++ monotone.texi @@ -5522,6 +5522,7 @@ result is present, future updates will require it. If you want a more lenient behavior you must redefine this hook. address@hidden @item merge2 (@var{left}, @var{right}) Returns a string, which should be the merger of the 2 provided @@ -5532,110 +5533,252 @@ @smallexample @group -function merge2(left, right) - local lfile = nil - local rfile = nil - local outfile = nil - local data = nil - lfile = write_to_temporary_file(left) - rfile = write_to_temporary_file(right) - outfile = write_to_temporary_file("") +function merge2 (left_path, right_path, merged_path, left, right) + local ret = nil + local tbl = @address@hidden - if lfile ~= nil and - rfile ~= nil and - outfile ~= nil + tbl.lfile = nil + tbl.rfile = nil + tbl.outfile = nil + tbl.meld_exists = false + + tbl.lfile = write_to_temporary_file (left) + tbl.rfile = write_to_temporary_file (right) + tbl.outfile = write_to_temporary_file ("") + + if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.outfile ~= nil then - local cmd = nil - if program_exists_in_path("xxdiff") then - cmd = merge2_xxdiff_cmd(lfile, rfile, outfile) - elseif program_exists_in_path("emacs") then - cmd = merge2_emacs_cmd("emacs", lfile, rfile, outfile) - elseif program_exists_in_path("xemacs") then - cmd = merge2_emacs_cmd("xemacs", lfile, rfile, outfile) - end + tbl.left_path = left_path + tbl.right_path = right_path + tbl.merged_path = merged_path - if cmd ~= nil - then - io.write( - string.format("executing external 2-way merge command: %s\n", - cmd)) - os.execute(cmd) - data = read_contents_of_file(outfile) + local cmd = get_preferred_merge2_command (tbl) + + if cmd ~=nil + then + io.write ( + string.format("executing external 2-way merge command\n")) + cmd () + if tbl.meld_exists + then + ret = read_contents_of_file (tbl.lfile) + else + ret = read_contents_of_file (tbl.outfile) + end + if string.len (ret) == 0 + then + ret = nil + end else - io.write("no external 2-way merge command found") + io.write ("no external 2-way merge command found\n") end end + + os.remove (tbl.lfile) + os.remove (tbl.rfile) + os.remove (tbl.outfile) - os.remove(lfile) - os.remove(rfile) - os.remove(outfile) + return ret +end address@hidden group address@hidden smallexample + address@hidden address@hidden get_preferred_merge2_command(@var{tbl}) + +Returns the results of running an external merge on two strings. address@hidden wraps up the various arguments for each merge command and +is always provided by @ref{merge2}. If there is a particular editor +that you would like to use to perform merge2 operations, override +this hook to specify it. + address@hidden address@hidden + +function get_preferred_merge2_command (tbl) + local cmd = nil + local left_path = tbl.left_path + local right_path = tbl.right_path + local merged_path = tbl.merged_path + local lfile = tbl.lfile + local rfile = tbl.rfile + local outfile = tbl.outfile + + local editor = string.lower(os.getenv("EDITOR")) + - return data -end + if program_exists_in_path("kdiff3") then + cmd = merge2_kdiff3_cmd (left_path, right_path, merged_path, + lfile, rfile, outfile) + elseif program_exists_in_path ("meld") then + tbl.meld_exists = true + io.write (string.format( + "\nWARNING: 'meld' was choosen to perform external 2-way merge.\n".. + "You should merge all changes to *LEFT* file due to limitation of program\n".. + "arguments.\n\n")) + cmd = merge2_meld_cmd (lfile, rfile) + elseif program_exists_in_path ("xxdiff") then + cmd = merge2_xxdiff_cmd (left_path, right_path, merged_path, + lfile, rfile, outfile) + else + if string.find(editor, "emacs") ~= nil + or string.find(editor, "gnu") ~= nil + then + if program_exists_in_path ("emacs") then + cmd = merge2_emacs_cmd ("emacs", lfile, rfile, outfile) + elseif program_exists_in_path ("xemacs") then + cmd = merge2_emacs_cmd ("xemacs", lfile, rfile, outfile) + end + else if string.find(editor, "vim") ~= nil then + if os.getenv ("DISPLAY") ~= nil + and program_exists_in_path ("gvim") + then + cmd = merge2_vim_cmd ("gvim", lfile, rfile, outfile) + elseif program_exists_in_path ("vim") then + cmd = merge2_vim_cmd ("vim", lfile, rfile, outfile) + end + end + end + return cmd +end @end group @end smallexample address@hidden @item merge3 (@var{ancestor}, @var{left}, @var{right}) Returns a string, which should be the merger of the 3 provided strings, which are the contents of @var{left} and @var{right} nodes, and least common @var{ancestor}, of a file fork which monotone was -unable to automatically merge. The merge should either call an -intelligent merge program or interact with the user. The default +unable to automatically merge. This hook delegates the actual merge +to the result of @ref{get_preferred_merge3_command}. The default definition of this hook is: @smallexample @group -function merge3(ancestor, left, right) - local afile = nil - local lfile = nil - local rfile = nil - local outfile = nil - local data = nil +function merge3 (anc_path, left_path, right_path, merged_path, + ancestor, left, right) + local ret + local tbl = @address@hidden + + tbl.anc_path = anc_path + tbl.left_path = left_path + tbl.right_path = right_path - lfile = write_to_temporary_file(left) - afile = write_to_temporary_file(ancestor) - rfile = write_to_temporary_file(right) - outfile = write_to_temporary_file("") - - if lfile ~= nil and - rfile ~= nil and - afile ~= nil and - outfile ~= nil + tbl.merged_path = merged_path + tbl.afile = nil + tbl.lfile = nil + tbl.rfile = nil + tbl.outfile = nil + tbl.meld_exists = false + tbl.lfile = write_to_temporary_file (left) + tbl.afile = write_to_temporary_file (ancestor) + tbl.rfile = write_to_temporary_file (right) + tbl.outfile = write_to_temporary_file ("") + + if tbl.lfile ~= nil and tbl.rfile ~= nil + and tbl.afile ~= nil and tbl.outfile ~= nil then - local cmd = nil - if program_exists_in_path("xxdiff") then - cmd = merge3_xxdiff_cmd(lfile, afile, rfile, outfile) - elseif program_exists_in_path("emacs") then - cmd = merge3_emacs_cmd("emacs", lfile, afile, rfile, outfile) - elseif program_exists_in_path("xemacs") then - cmd = merge3_emacs_cmd("xemacs", lfile, afile, rfile, outfile) - end - - if cmd ~= nil - then - io.write( - string.format("executing external 3-way merge command: %s\n", - cmd)) - os.execute(cmd) - data = read_contents_of_file(outfile) + local cmd = get_preferred_merge3_command (tbl) + if cmd ~=nil + then + io.write (string.format( + "executing external 3-way merge command\n")) + cmd () + if tbl.meld_exists + then + ret = read_contents_of_file (tbl.afile) + else + ret = read_contents_of_file (tbl.outfile) + end + if string.len (ret) == 0 + then + ret = nil + end else - io.write("no external 3-way merge command found") + io.write ("no external 3-way merge command found\n") end end - os.remove(lfile) - os.remove(rfile) - os.remove(afile) - os.remove(outfile) + os.remove (tbl.lfile) + os.remove (tbl.rfile) + os.remove (tbl.afile) + os.remove (tbl.outfile) - return data -end + return ret +end @end group @end smallexample address@hidden address@hidden get_preferred_merge3_command(@var{tbl}) +Returns the results of running an external merge on three strings. address@hidden wraps up the various arguments for each merge command and +is always provided by @ref{merge3}. If there is a particular editor +that you would like to use to perform merge3 operations, override +this hook to specify it. + address@hidden address@hidden +function get_preferred_merge3_command (tbl) + local cmd = nil + local left_path = tbl.left_path + local anc_path = tbl.anc_path + local right_path = tbl.right_path + local merged_path = tbl.merged_path + local lfile = tbl.lfile + local afile = tbl.afile + local rfile = tbl.rfile + local outfile = tbl.outfile + + local editor = string.lower(os.getenv("EDITOR")) + + if 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 ("meld") then + tbl.meld_exists = true + io.write (string.format( + "\nWARNING: 'meld' was choosen to perform external 3-way merge.\n".. + "You should merge all changes to *CENTER* file due to limitation of program\n".. + "arguments.\n\n")) + cmd = merge3_meld_cmd (lfile, afile, rfile) + elseif program_exists_in_path ("xxdiff") then + cmd = merge3_xxdiff_cmd (left_path, anc_path, right_path, + merged_path, lfile, afile, rfile, outfile) + else + -- prefer emacs/xemacs + if string.find(editor, "emacs") ~= nil + or string.find(editor, "gnu") ~= nil + then + if program_exists_in_path ("xemacs") then + cmd = merge3_emacs_cmd ("xemacs", lfile, afile, + rfile, outfile) + elseif program_exists_in_path ("emacs") then + cmd = merge3_emacs_cmd ("emacs", lfile, afile, + rfile, outfile) + end + elseif string.find(editor, "vim") ~= nil then -- prefer vim + if os.getenv ("DISPLAY") ~= nil + and program_exists_in_path ("gvim") + then + cmd = merge3_vim_cmd ("gvim", lfile, afile, + rfile, outfile) + elseif program_exists_in_path ("vim") then + cmd = merge3_vim_cmd ("vim", lfile, afile, + rfile, outfile) + end + end + end + + return cmd +end address@hidden group address@hidden smallexample + + @item expand_selector (@var{str}) Attempts to expand @var{str} as a selector. Expansion generally means --- std_hooks.lua +++ std_hooks.lua @@ -296,164 +296,182 @@ end function get_preferred_merge2_command (tbl) - local cmd = nil - local left_path = tbl.left_path - local right_path = tbl.right_path - local merged_path = tbl.merged_path - local lfile = tbl.lfile - local rfile = tbl.rfile - local outfile = tbl.outfile - - if program_exists_in_path("kdiff3") then - cmd = merge2_kdiff3_cmd (left_path, right_path, merged_path, lfile, rfile, outfile) - elseif program_exists_in_path ("meld") then - tbl.meld_exists = true - io.write (string.format("\nWARNING: 'meld' was choosen to perform external 2-way merge.\n".. - "You should merge all changes to *LEFT* file due to limitation of program\n".. - "arguments.\n\n")) - cmd = merge2_meld_cmd (lfile, rfile) - elseif program_exists_in_path ("xxdiff") then - cmd = merge2_xxdiff_cmd (left_path, right_path, merged_path, lfile, rfile, outfile) - elseif program_exists_in_path ("emacs") then - cmd = merge2_emacs_cmd ("emacs", lfile, rfile, outfile) - elseif program_exists_in_path ("xemacs") then - cmd = merge2_emacs_cmd ("xemacs", lfile, rfile, outfile) - elseif os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then - cmd = merge2_vim_cmd ("gvim", lfile, rfile, outfile) - elseif program_exists_in_path ("vim") then - cmd = merge2_vim_cmd ("vim", lfile, rfile, outfile) - end - return cmd + local cmd = nil + local left_path = tbl.left_path + local right_path = tbl.right_path + local merged_path = tbl.merged_path + local lfile = tbl.lfile + local rfile = tbl.rfile + local outfile = tbl.outfile + + local editor = string.lower(os.getenv("EDITOR")) + + + if program_exists_in_path("kdiff3") then + cmd = merge2_kdiff3_cmd (left_path, right_path, merged_path, lfile, rfile, outfile) + elseif program_exists_in_path ("meld") then + tbl.meld_exists = true + io.write (string.format("\nWARNING: 'meld' was choosen to perform external 2-way merge.\n".. + "You should merge all changes to *LEFT* file due to limitation of program\n".. + "arguments.\n\n")) + cmd = merge2_meld_cmd (lfile, rfile) + elseif program_exists_in_path ("xxdiff") then + cmd = merge2_xxdiff_cmd (left_path, right_path, merged_path, lfile, rfile, outfile) + else + if string.find(editor, "emacs") ~= nil or string.find(editor, "gnu") ~= nil then + if program_exists_in_path ("emacs") then + cmd = merge2_emacs_cmd ("emacs", lfile, rfile, outfile) + elseif program_exists_in_path ("xemacs") then + cmd = merge2_emacs_cmd ("xemacs", lfile, rfile, outfile) + end + else if string.find(editor, "vim") ~= nil then + if os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then + cmd = merge2_vim_cmd ("gvim", lfile, rfile, outfile) + elseif program_exists_in_path ("vim") then + cmd = merge2_vim_cmd ("vim", lfile, rfile, outfile) + end + end + end + return cmd end function merge2 (left_path, right_path, merged_path, left, right) - local ret = nil - local tbl = {} + local ret = nil + local tbl = {} - tbl.lfile = nil - tbl.rfile = nil - tbl.outfile = nil - tbl.meld_exists = false + tbl.lfile = nil + tbl.rfile = nil + tbl.outfile = nil + tbl.meld_exists = false - tbl.lfile = write_to_temporary_file (left) - tbl.rfile = write_to_temporary_file (right) - tbl.outfile = write_to_temporary_file ("") + tbl.lfile = write_to_temporary_file (left) + tbl.rfile = write_to_temporary_file (right) + tbl.outfile = write_to_temporary_file ("") - if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.outfile ~= nil - then - tbl.left_path = left_path - tbl.right_path = right_path - tbl.merged_path = merged_path + if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.outfile ~= nil + then + tbl.left_path = left_path + tbl.right_path = right_path + tbl.merged_path = merged_path - local cmd = get_preferred_merge2_command (tbl) + local cmd = get_preferred_merge2_command (tbl) - if cmd ~=nil - then - io.write (string.format("executing external 2-way merge command\n")) - cmd () - if tbl.meld_exists - then - ret = read_contents_of_file (tbl.lfile) - else - ret = read_contents_of_file (tbl.outfile) - end - if string.len (ret) == 0 - then - ret = nil - end - else - io.write ("no external 2-way merge command found\n") - end - end + if cmd ~=nil + then + io.write (string.format("executing external 2-way merge command\n")) + cmd () + if tbl.meld_exists + then + ret = read_contents_of_file (tbl.lfile) + else + ret = read_contents_of_file (tbl.outfile) + end + if string.len (ret) == 0 + then + ret = nil + end + else + io.write ("no external 2-way merge command found\n") + end + end - os.remove (tbl.lfile) - os.remove (tbl.rfile) - os.remove (tbl.outfile) - - return ret + os.remove (tbl.lfile) + os.remove (tbl.rfile) + os.remove (tbl.outfile) + + return ret end function get_preferred_merge3_command (tbl) - local cmd = nil - local left_path = tbl.left_path - local anc_path = tbl.anc_path - local right_path = tbl.right_path - local merged_path = tbl.merged_path - local lfile = tbl.lfile - local afile = tbl.afile - local rfile = tbl.rfile - local outfile = tbl.outfile + local cmd = nil + local left_path = tbl.left_path + local anc_path = tbl.anc_path + local right_path = tbl.right_path + local merged_path = tbl.merged_path + local lfile = tbl.lfile + local afile = tbl.afile + local rfile = tbl.rfile + local outfile = tbl.outfile - if 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 ("meld") then - tbl.meld_exists = true - io.write (string.format("\nWARNING: 'meld' was choosen to perform external 3-way merge.\n".. - "You should merge all changes to *CENTER* file due to limitation of program\n".. - "arguments.\n\n")) - cmd = merge3_meld_cmd (lfile, afile, rfile) - elseif program_exists_in_path ("xxdiff") then - cmd = merge3_xxdiff_cmd (left_path, anc_path, right_path, merged_path, lfile, afile, rfile, outfile) - elseif program_exists_in_path ("emacs") then - cmd = merge3_emacs_cmd ("emacs", lfile, afile, rfile, outfile) - elseif program_exists_in_path ("xemacs") then - cmd = merge3_emacs_cmd ("xemacs", lfile, afile, rfile, outfile) - elseif os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then - cmd = merge3_vim_cmd ("gvim", lfile, afile, rfile, outfile) - elseif program_exists_in_path ("vim") then - cmd = merge3_vim_cmd ("vim", lfile, afile, rfile, outfile) - end - - return cmd + local editor = string.lower(os.getenv("EDITOR")) + + if 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 ("meld") then + tbl.meld_exists = true + io.write (string.format("\nWARNING: 'meld' was choosen to perform external 3-way merge.\n".. + "You should merge all changes to *CENTER* file due to limitation of program\n".. + "arguments.\n\n")) + cmd = merge3_meld_cmd (lfile, afile, rfile) + elseif program_exists_in_path ("xxdiff") then + cmd = merge3_xxdiff_cmd (left_path, anc_path, right_path, merged_path, lfile, afile, rfile, outfile) + else + -- prefer emacs/xemacs + if string.find(editor, "emacs") ~= nil or string.find(editor, "gnu") ~= nil then + if program_exists_in_path ("xemacs") then + cmd = merge3_emacs_cmd ("xemacs", lfile, afile, rfile, outfile) + elseif program_exists_in_path ("emacs") then + cmd = merge3_emacs_cmd ("emacs", lfile, afile, rfile, outfile) + end + elseif string.find(editor, "vim") ~= nil then -- prefer vim + if os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then + cmd = merge3_vim_cmd ("gvim", lfile, afile, rfile, outfile) + elseif program_exists_in_path ("vim") then + cmd = merge3_vim_cmd ("vim", lfile, afile, rfile, outfile) + end + end + end + + return cmd end function merge3 (anc_path, left_path, right_path, merged_path, ancestor, left, right) - local ret - local tbl = {} - - tbl.anc_path = anc_path - tbl.left_path = left_path - tbl.right_path = right_path + local ret + local tbl = {} + + tbl.anc_path = anc_path + tbl.left_path = left_path + tbl.right_path = right_path - tbl.merged_path = merged_path - tbl.afile = nil - tbl.lfile = nil - tbl.rfile = nil - tbl.outfile = nil - tbl.meld_exists = false - tbl.lfile = write_to_temporary_file (left) - tbl.afile = write_to_temporary_file (ancestor) - tbl.rfile = write_to_temporary_file (right) - tbl.outfile = write_to_temporary_file ("") - - if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.afile ~= nil and tbl.outfile ~= nil - then - local cmd = get_preferred_merge3_command (tbl) - if cmd ~=nil - then - io.write (string.format("executing external 3-way merge command\n")) - cmd () - if tbl.meld_exists - then - ret = read_contents_of_file (tbl.afile) - else - ret = read_contents_of_file (tbl.outfile) - end - if string.len (ret) == 0 - then - ret = nil - end - else - io.write ("no external 3-way merge command found\n") - end - end - - os.remove (tbl.lfile) - os.remove (tbl.rfile) - os.remove (tbl.afile) - os.remove (tbl.outfile) - - return ret + tbl.merged_path = merged_path + tbl.afile = nil + tbl.lfile = nil + tbl.rfile = nil + tbl.outfile = nil + tbl.meld_exists = false + tbl.lfile = write_to_temporary_file (left) + tbl.afile = write_to_temporary_file (ancestor) + tbl.rfile = write_to_temporary_file (right) + tbl.outfile = write_to_temporary_file ("") + + if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.afile ~= nil and tbl.outfile ~= nil + then + local cmd = get_preferred_merge3_command (tbl) + if cmd ~=nil + then + io.write (string.format("executing external 3-way merge command\n")) + cmd () + if tbl.meld_exists + then + ret = read_contents_of_file (tbl.afile) + else + ret = read_contents_of_file (tbl.outfile) + end + if string.len (ret) == 0 + then + ret = nil + end + else + io.write ("no external 3-way merge command found\n") + end + end + + os.remove (tbl.lfile) + os.remove (tbl.rfile) + os.remove (tbl.afile) + os.remove (tbl.outfile) + + return ret end -- expansion of values used in selector completion