-- special monotonerc file to be installed in bugs/_MTN/
-- force the merge to use our magic merge system

function merge3 (anc_path, left_path, right_path, merged_path, ancestor, left, right)
   local result = nil
   local lfile = write_to_temporary_file (left, "left")
   local afile = write_to_temporary_file (ancestor, "ancestor")
   local rfile = write_to_temporary_file (right, "right")
   local outfile = write_to_temporary_file ("", "merged")

   local path = "disTractMerger"
   if (program_exists_in_path (path)) then
      local returnCode = execute(path,
                                 anc_path,
                                 left_path,
                                 right_path,
                                 merged_path,
                                 afile,
                                 lfile,
                                 rfile,
                                 outfile)
      if (returnCode == 0) then
         result = read_contents_of_file (outfile, "r")
      end
   end

   if (result == nil) then
      io.write (string.format(gettext("Error executing disTractMerger: '%s'\n"), path))
   end

   os.remove (lfile)
   os.remove (rfile)
   os.remove (afile)
   os.remove (outfile)

   return result
end
