equal
deleted
inserted
replaced
96 import os |
96 import os |
97 import re |
97 import re |
98 from mercurial.i18n import _ |
98 from mercurial.i18n import _ |
99 from mercurial import ( |
99 from mercurial import ( |
100 config, |
100 config, |
101 error, |
101 error as errormod, |
102 extensions, |
102 extensions, |
103 match, |
103 match, |
104 pycompat, |
104 pycompat, |
105 util, |
105 util, |
106 ) |
106 ) |
223 else: |
223 else: |
224 data = repo[node]['.hgeol'].data() |
224 data = repo[node]['.hgeol'].data() |
225 return eolfile(ui, repo.root, data) |
225 return eolfile(ui, repo.root, data) |
226 except (IOError, LookupError): |
226 except (IOError, LookupError): |
227 pass |
227 pass |
228 except error.ParseError as inst: |
228 except errormod.ParseError as inst: |
229 ui.warn(_("warning: ignoring .hgeol file due to parse error " |
229 ui.warn(_("warning: ignoring .hgeol file due to parse error " |
230 "at %s: %s\n") % (inst.args[1], inst.args[0])) |
230 "at %s: %s\n") % (inst.args[1], inst.args[0])) |
231 return None |
231 return None |
232 |
232 |
233 def _checkhook(ui, repo, node, headsonly): |
233 def _checkhook(ui, repo, node, headsonly): |
252 eols = {'to-lf': 'CRLF', 'to-crlf': 'LF'} |
252 eols = {'to-lf': 'CRLF', 'to-crlf': 'LF'} |
253 msgs = [] |
253 msgs = [] |
254 for f, target, node in sorted(failed): |
254 for f, target, node in sorted(failed): |
255 msgs.append(_(" %s in %s should not have %s line endings") % |
255 msgs.append(_(" %s in %s should not have %s line endings") % |
256 (f, node, eols[target])) |
256 (f, node, eols[target])) |
257 raise error.Abort(_("end-of-line check failed:\n") + "\n".join(msgs)) |
257 raise errormod.Abort(_("end-of-line check failed:\n") + "\n".join(msgs)) |
258 |
258 |
259 def checkallhook(ui, repo, node, hooktype, **kwargs): |
259 def checkallhook(ui, repo, node, hooktype, **kwargs): |
260 """verify that files have expected EOLs""" |
260 """verify that files have expected EOLs""" |
261 _checkhook(ui, repo, node, False) |
261 _checkhook(ui, repo, node, False) |
262 |
262 |
354 # the new .hgeol file specify a different filter |
354 # the new .hgeol file specify a different filter |
355 self.dirstate.normallookup(f) |
355 self.dirstate.normallookup(f) |
356 # Write the cache to update mtime and cache .hgeol |
356 # Write the cache to update mtime and cache .hgeol |
357 with self.vfs("eol.cache", "w") as f: |
357 with self.vfs("eol.cache", "w") as f: |
358 f.write(hgeoldata) |
358 f.write(hgeoldata) |
359 except error.LockUnavailable: |
359 except errormod.LockUnavailable: |
360 # If we cannot lock the repository and clear the |
360 # If we cannot lock the repository and clear the |
361 # dirstate, then a commit might not see all files |
361 # dirstate, then a commit might not see all files |
362 # as modified. But if we cannot lock the |
362 # as modified. But if we cannot lock the |
363 # repository, then we can also not make a commit, |
363 # repository, then we can also not make a commit, |
364 # so ignore the error. |
364 # so ignore the error. |
379 # We should not abort here, since the user should |
379 # We should not abort here, since the user should |
380 # be able to say "** = native" to automatically |
380 # be able to say "** = native" to automatically |
381 # have all non-binary files taken care of. |
381 # have all non-binary files taken care of. |
382 continue |
382 continue |
383 if inconsistenteol(data): |
383 if inconsistenteol(data): |
384 raise error.Abort(_("inconsistent newline style " |
384 raise errormod.Abort(_("inconsistent newline style " |
385 "in %s\n") % f) |
385 "in %s\n") % f) |
386 return super(eolrepo, self).commitctx(ctx, haserror) |
386 return super(eolrepo, self).commitctx(ctx, haserror) |
387 repo.__class__ = eolrepo |
387 repo.__class__ = eolrepo |
388 repo._hgcleardirstate() |
388 repo._hgcleardirstate() |