# HG changeset patch # User Matt Mackall # Date 2008-02-04 01:29:05 # Node ID 3c33032d8906f751ca2b3dd8c0f937dea5a717f4 # Parent 5af5f0f9d7242408055607bd7a50c687eaf1c89c merge: add support for tool EOL fixups specified with merge-tools:.fixeol=True diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -59,6 +59,29 @@ def _picktool(repo, ui, path, binary, sy if _findtool(ui, t) and check(t, None, symlink, binary): return t +def _eoltype(data): + "Guess the EOL type of a file" + if '\0' in data: # binary + return None + if '\r\n' in data: # Windows + return '\r\n' + if '\r' in data: # Old Mac + return '\r' + if '\n' in data: # UNIX + return '\n' + return None # unknown + +def _matcheol(file, origfile): + "Convert EOL markers in a file to match origfile" + tostyle = _eoltype(open(origfile, "rb").read()) + if tostyle: + data = open(file, "rb").read() + style = _eoltype(data) + if style: + newdata = data.replace(style, tostyle) + if newdata != data: + open(file, "wb").write(newdata) + def filemerge(repo, fw, fd, fo, wctx, mctx): """perform a 3-way merge in the working directory @@ -158,6 +181,9 @@ def filemerge(repo, fw, fd, fo, wctx, mc if re.match("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcm.data()): r = 1 + if _toolbool(ui, tool, "fixeol"): + _matcheol(repo.join(fd), back) + if r: repo.ui.warn(_("merging %s failed!\n") % fd) else: