monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] Improved Vim Merger


From: Matthew Nicholson
Subject: [Monotone-devel] Improved Vim Merger
Date: Wed, 27 Feb 2008 21:46:48 -0600
User-agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080109)

Greetings,

I have attached an improved vim merger which uses diff3 to merge non conflict changes before passing the files on to vim. If there are no objections to these changes, I will go ahead and commit them.

Further information:

In short, vim's merger sucks. In fact, it is not a merger at all, it is really a diff tool that will show you the differences between files and allow you to copy those differences between files. To compensate for that, this new merger hook calls diff3 to merge the left and right files so that you only see non conflict changes in vim. This makes using vim to merge files much more pleasant because you now, don't have to sort through all of the non conflicting changes when merging large files.

P.S. I am not sure if anyone other then me is using vim to merge, it seems like a lot of you use real merge tools (e.g., kdiff3, xxdiff, ...).
--
Matthew Nicholson
matt-land.com
mergers.vim = {
   cmd = function (tbl)
      function execute_diff3(mine, yours, out)
         local diff3_args = {
            "diff3",
            "--merge",
            "--easy-only",
         }
         table.insert(diff3_args, string.gsub(mine, "\\", "/") .. "")
         table.insert(diff3_args, string.gsub(tbl.afile, "\\", "/") .. "")
         table.insert(diff3_args, string.gsub(yours, "\\", "/") .. "")
      
         return execute_redirected("", string.gsub(out, "\\", "/"), "", 
unpack(diff3_args))
      end

      io.write (string.format("\nWARNING: 'vim' was choosen to perform external 
3-way merge.\n"..
          "You should merge all changes to *LEFT* file due to limitation of 
program\n"..
          "arguments.\n\n"))
      
      local vim
      if os.getenv ("DISPLAY") ~= nil and program_exists_in_path ("gvim") then
         vim = "gvim"
      else
         vim = "vim"
      end

      local lfile_merged = tbl.lfile .. ".merged"
      local rfile_merged = tbl.rfile .. ".merged"

      -- first merge lfile using diff3
      local ret = execute_diff3(tbl.lfile, tbl.rfile, lfile_merged)
      if ret == 2 then
         io.write(string.format(gettext("Error running diff3 for merger 
'%s'\n"), vim))
         return false
      end

      -- now merge rfile using diff3
      ret = execute_diff3(tbl.rfile, tbl.lfile, rfile_merged)
      if ret == 2 then
         io.write(string.format(gettext("Error running diff3 for merger 
'%s'\n"), vim))
         return false
      end
      
      os.rename(lfile_merged, tbl.lfile)
      os.rename(rfile_merged, tbl.rfile)
      
      local ret = execute(vim, "-f", "-d", "-c", string.format("file %s", 
tbl.outfile),
                          tbl.lfile, tbl.rfile)
      if (ret ~= 0) then
         io.write(string.format(gettext("Error running merger '%s'\n"), vim))
         return false
      end
      return tbl.outfile
   end ,
   available =
      function ()
         return program_exists_in_path("diff3") and
            (program_exists_in_path("vim") or
            program_exists_in_path("gvim"))
      end ,
   wanted =
      function ()
         local editor = os.getenv("EDITOR")
         if editor and
            not (string.find(editor, "vim") or
                 string.find(editor, "gvim")) then
            return false
         end
         return true
      end
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]