monotone-devel
[Top][All Lists]
Advanced

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

[Monotone-devel] Re: How to 3-way merge with kdiff3 and Cygwin?


From: Steven E. Harris
Subject: [Monotone-devel] Re: How to 3-way merge with kdiff3 and Cygwin?
Date: Wed, 21 Feb 2007 13:23:48 -0800
User-agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.13 (cygwin32)

Graydon Hoare <address@hidden> writes:

> function cygpath(p)
>       p = string.gsub(p, "/", "\\")
>       p = string.gsub(p, "\\cygdrive\\c", "C:")
>       return p
> end

I hadn't thought of even trying to do this in Lua without being able
to call on the Cygwin cygpath program, and, at the time I looked into
it, there was no easy way to catch the output from a process started
by Lua -- at least the Lua provided by monotone.

My solution moved the calls to cygpath into Emacs, as I was interested
in using Emacs rather than something like kdiff3:

,----
| function translate_slashes(path)
|    return string.gsub(path, "\\", "/")
| end
| 
| 
| function merge3_emacs_cmd(emacs, lfile, afile, rfile, outfile)
|    local elisp = "(merge-translated-paths \"%s\" \"%s\" \"%s\" nil \"%s\")"
|    return
|    function()
|       return execute(emacs,
|                      -- NB: Specifying this file path like this is brittle.
|                      "-l", "U:\\temp\\merge-translated.el",
|                      "--eval",
|                      string.format(elisp,
|                                    translate_slashes(lfile),
|                                    translate_slashes(rfile),
|                                    translate_slashes(afile),
|                                    translate_slashes(outfile)))
|    end
| end
`----

The referenced "merge-translated.el" follows:

,----
| (defvar running-on-cygwin-p (memq system-type '(cygwin cygwin32)))
| (defvar running-on-mswindows-p (memq system-type
|                                      '(windows-nt ms-windows cygwin 
cygwin32)))
| 
| (defun translate-path-canonical (path)
|   (if (not running-on-mswindows-p)
|       path
|     (if running-on-cygwin-p
|       (substring (shell-command-to-string (concat "cygpath -u '" path "'")) 0 
-1)
|       (subst-char-in-string ?\\ ?/ path))))
| 
| (defun translate-path-native (path)
|   (if (not running-on-mswindows-p)
|       path
|     (if running-on-cygwin-p
|       (substring (shell-command-to-string (concat "cygpath -w " path)) 0 -1)
|       (subst-char-in-string ?/ ?\\ path))))
| 
| 
| (defun merge-translated-paths (file-A file-B file-ancestor &optional
|                                startup-hooks merge-buffer-file)
|   (ediff-merge-files-with-ancestor (translate-path-canonical file-A)
|                                    (translate-path-canonical file-B)
|                                    (translate-path-canonical file-ancestor)
|                                    startup-hooks
|                                    (translate-path-canonical 
merge-buffer-file)))
`----

Looking at the current set of default hooks, it doesn't look like
there's any way my merge3_emacs_cmd will get found; it's clearly in
need of some updating. Here's an attempt, untested as of yet:

,----
| mergers.emacs.cmd =
|    function (tbl)
|       local emacs
|       if program_exists_in_path("xemacs") then
|          emacs = "xemacs"
|       else
|          emacs = "emacs"
|       end
|       local elisp = "(merge-translated-paths \"%s\" \"%s\" \"%s\" nil \"%s\")"
|       local ret = execute(emacs,
|                           -- NB: Specifying this file path like this is 
brittle.
|                           "-l", "U:\\temp\\merge-translated.el",
|                           "--eval",
|                           string.format(elisp,
|                                         tbl.lfile,
|                                         tbl.rfile,
|                                         tbl.afile,
|                                         tbl.outfile))
|       if (ret ~= 0) then
|          io.write(string.format(gettext("Error running merger '%s'\n"), 
emacs))
|          return false
|       end
|       return tbl.outfile
|    end
`----

Using gnuserv instead of xemacs might also make sense.

-- 
Steven E. Harris





reply via email to

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