Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 6005:3c33032d8906
merge: add support for tool EOL fixups
specified with merge-tools:<tool>.fixeol=True
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 03 Feb 2008 19:29:05 -0600 |
parents | 5af5f0f9d724 |
children | 3c9dbb743d20 |
comparison
equal
deleted
inserted
replaced
6004:5af5f0f9d724 | 6005:3c33032d8906 |
---|---|
56 tools.append((None, "hgmerge")) # the old default, if found | 56 tools.append((None, "hgmerge")) # the old default, if found |
57 tools.append((None, "internal:merge")) # internal merge as last resort | 57 tools.append((None, "internal:merge")) # internal merge as last resort |
58 for p,t in tools: | 58 for p,t in tools: |
59 if _findtool(ui, t) and check(t, None, symlink, binary): | 59 if _findtool(ui, t) and check(t, None, symlink, binary): |
60 return t | 60 return t |
61 | |
62 def _eoltype(data): | |
63 "Guess the EOL type of a file" | |
64 if '\0' in data: # binary | |
65 return None | |
66 if '\r\n' in data: # Windows | |
67 return '\r\n' | |
68 if '\r' in data: # Old Mac | |
69 return '\r' | |
70 if '\n' in data: # UNIX | |
71 return '\n' | |
72 return None # unknown | |
73 | |
74 def _matcheol(file, origfile): | |
75 "Convert EOL markers in a file to match origfile" | |
76 tostyle = _eoltype(open(origfile, "rb").read()) | |
77 if tostyle: | |
78 data = open(file, "rb").read() | |
79 style = _eoltype(data) | |
80 if style: | |
81 newdata = data.replace(style, tostyle) | |
82 if newdata != data: | |
83 open(file, "wb").write(newdata) | |
61 | 84 |
62 def filemerge(repo, fw, fd, fo, wctx, mctx): | 85 def filemerge(repo, fw, fd, fo, wctx, mctx): |
63 """perform a 3-way merge in the working directory | 86 """perform a 3-way merge in the working directory |
64 | 87 |
65 fw = original filename in the working directory | 88 fw = original filename in the working directory |
156 | 179 |
157 if not r and _toolbool(ui, tool, "checkconflicts"): | 180 if not r and _toolbool(ui, tool, "checkconflicts"): |
158 if re.match("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcm.data()): | 181 if re.match("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcm.data()): |
159 r = 1 | 182 r = 1 |
160 | 183 |
184 if _toolbool(ui, tool, "fixeol"): | |
185 _matcheol(repo.join(fd), back) | |
186 | |
161 if r: | 187 if r: |
162 repo.ui.warn(_("merging %s failed!\n") % fd) | 188 repo.ui.warn(_("merging %s failed!\n") % fd) |
163 else: | 189 else: |
164 os.unlink(back) | 190 os.unlink(back) |
165 | 191 |