##// END OF EJS Templates
add a fix for issue 1175...
add a fix for issue 1175 If we copy a file followed by an update, it's possible for the parent manifest to no longer contain the source file of the copy, which could cause commit to fail. If this happens, we search backwares from the first parent to find the most likely original revision.

File last commit:

r6750:fb42030d default
r6875:0d714a48 default
Show More
win32text.py
106 lines | 3.4 KiB | text/x-python | PythonLexer
Jesse Glick
Issue 882: add standard hook to reject text files with CRLF....
r5675 # win32text.py - LF <-> CRLF translation utilities for Windows users
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# To perform automatic newline conversion, use:
#
# [extensions]
# hgext.win32text =
# [encode]
# ** = cleverencode:
# [decode]
# ** = cleverdecode:
#
# If not doing conversion, to make sure you do not commit CRLF by accident:
#
# [hooks]
# pretxncommit.crlf = python:hgext.win32text.forbidcrlf
#
# To do the same check on a server to prevent CRLF from being pushed or pulled:
#
# [hooks]
# pretxnchangegroup.crlf = python:hgext.win32text.forbidcrlf
Lee Cantey
Correct inadvertent line ending change.
r4859 from mercurial.i18n import gettext as _
Joel Rosdahl
Expand import * to allow Pyflakes to find problems
r6211 from mercurial.node import bin, short
Lee Cantey
Correct inadvertent line ending change.
r4859 import re
# regexp for single LF without CR preceding.
re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
Jesse Glick
Provide better context for custom Python encode/decode filters....
r5967 def dumbdecode(s, cmd, ui=None, repo=None, filename=None, **kwargs):
Lee Cantey
Correct inadvertent line ending change.
r4859 # warn if already has CRLF in repository.
# it might cause unexpected eol conversion.
# see issue 302:
# http://www.selenic.com/mercurial/bts/issue302
Jesse Glick
Provide better context for custom Python encode/decode filters....
r5967 if '\r\n' in s and ui and filename and repo:
ui.warn(_('WARNING: %s already has CRLF line endings\n'
'and does not need EOL conversion by the win32text plugin.\n'
'Before your next commit, please reconsider your '
'encode/decode settings in \nMercurial.ini or %s.\n') %
(filename, repo.join('hgrc')))
Lee Cantey
Correct inadvertent line ending change.
r4859 # replace single LF to CRLF
return re_single_lf.sub('\\1\r\n', s)
def dumbencode(s, cmd):
return s.replace('\r\n', '\n')
Patrick Mezard
Backed out changeset 7f4257b5cbfc...
r6473 def clevertest(s, cmd):
if '\0' in s: return False
return True
Jesse Glick
Provide better context for custom Python encode/decode filters....
r5967 def cleverdecode(s, cmd, **kwargs):
Patrick Mezard
Backed out changeset 7f4257b5cbfc...
r6473 if clevertest(s, cmd):
return dumbdecode(s, cmd, **kwargs)
return s
Lee Cantey
Correct inadvertent line ending change.
r4859
def cleverencode(s, cmd):
Patrick Mezard
Backed out changeset 7f4257b5cbfc...
r6473 if clevertest(s, cmd):
return dumbencode(s, cmd)
return s
Lee Cantey
Correct inadvertent line ending change.
r4859
Patrick Mezard
Register data filters in a localrepo instead of util...
r5966 _filters = {
Lee Cantey
Correct inadvertent line ending change.
r4859 'dumbdecode:': dumbdecode,
'dumbencode:': dumbencode,
'cleverdecode:': cleverdecode,
'cleverencode:': cleverencode,
Patrick Mezard
Register data filters in a localrepo instead of util...
r5966 }
Jesse Glick
Issue 882: add standard hook to reject text files with CRLF....
r5675
def forbidcrlf(ui, repo, hooktype, node, **kwargs):
halt = False
for rev in xrange(repo.changelog.rev(bin(node)), repo.changelog.count()):
c = repo.changectx(rev)
for f in c.files():
if f not in c:
continue
data = c[f].data()
Patrick Mezard
Backed out changeset 7f4257b5cbfc...
r6473 if '\0' not in data and '\r\n' in data:
Jesse Glick
Issue 882: add standard hook to reject text files with CRLF....
r5675 if not halt:
ui.warn(_('Attempt to commit or push text file(s) '
'using CRLF line endings\n'))
ui.warn(_('in %s: %s\n') % (short(c.node()), f))
halt = True
if halt and hooktype == 'pretxnchangegroup':
ui.warn(_('\nTo prevent this mistake in your local repository,\n'
'add to Mercurial.ini or .hg/hgrc:\n'
'\n'
'[hooks]\n'
'pretxncommit.crlf = python:hgext.win32text.forbidcrlf\n'
'\n'
'and also consider adding:\n'
'\n'
'[extensions]\n'
'hgext.win32text =\n'
'[encode]\n'
'** = cleverencode:\n'
'[decode]\n'
'** = cleverdecode:\n'))
return halt
Patrick Mezard
Register data filters in a localrepo instead of util...
r5966
def reposetup(ui, repo):
if not repo.local():
return
for name, fn in _filters.iteritems():
repo.adddatafilter(name, fn)