# HG changeset patch # User Matt Mackall # Date 1202088545 21600 # Node ID 3c33032d8906f751ca2b3dd8c0f937dea5a717f4 # Parent 5af5f0f9d7242408055607bd7a50c687eaf1c89c merge: add support for tool EOL fixups specified with merge-tools:.fixeol=True diff -r 5af5f0f9d724 -r 3c33032d8906 mercurial/filemerge.py --- a/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 +++ b/mercurial/filemerge.py Sun Feb 03 19:29:05 2008 -0600 @@ -59,6 +59,29 @@ 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 @@ 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: