Mercurial > hg > check_whitespace
changeset 16:86405cf4b913
Ported to Mercurial 5.2 under Python 3.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Tue, 14 Apr 2020 19:24:46 +0200 (2020-04-14) |
parents | 3c168c892742 |
children | 8d5ba09be6c5 |
files | check_whitespace.py |
diffstat | 1 files changed, 27 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/check_whitespace.py Wed Jun 12 09:05:17 2019 +0200 +++ b/check_whitespace.py Tue Apr 14 19:24:46 2020 +0200 @@ -39,27 +39,27 @@ linenum = 0 header = False filename = '' - fnre = re.compile(r'(?:---|\+\+\+) (?P<filename>[^\t\r\n]+)') - lnre = re.compile(r'@@ -\d+,\d+ \+(?P<lineno>\d+),') - wsre = re.compile(r'\+.*[ \t]$') - tbre = re.compile(r'\+.*\t') - resre = re.compile(r'\+(<<<<<<<|>>>>>>>|======= end)') + fnre = re.compile(br'(?:---|\+\+\+) (?P<filename>[^\t\r\n]+)') + lnre = re.compile(br'@@ -\d+,\d+ \+(?P<lineno>\d+),') + wsre = re.compile(br'\+.*[ \t]$') + tbre = re.compile(br'\+.*\t') + resre = re.compile(br'\+(<<<<<<<|>>>>>>>|======= end)') adding = False islink = False # symlinks can have no newline at end for chunk in difflines: - for line in chunk.split('\n'): + for line in chunk.split(b'\n'): if header: - if line.startswith('new file mode'): - islink = '120000' in line + if line.startswith(b'new file mode'): + islink = b'120000' in line # remember the name of the file that this diff affects m = fnre.match(line) - if m is not None and m.group('filename') != '/dev/null': - filename = m.group('filename').split('/', 1)[-1] - if line.startswith('+++ '): + if m is not None and m.group('filename') != b'/dev/null': + filename = m.group('filename').split(b'/', 1)[-1] + if line.startswith(b'+++ '): header = False continue - if line.startswith('diff '): + if line.startswith(b'diff '): header = True adding = False islink = False @@ -71,44 +71,44 @@ continue if header or not filename: continue - if line[:1] == '+': + if line[:1] == b'+': adding = True - elif line[:1] in (' ', '-'): + elif line[:1] in (b' ', b'-'): adding = False elif adding \ and not islink \ - and line.startswith(r'\ No newline at end of file') \ - and not filename.endswith('vertoo.data') \ + and line.startswith(br'\ No newline at end of file') \ + and not filename.endswith(b'vertoo.data') \ and not os.path.splitext(filename)[1] in binary_suffixes: adding = False - yield filename, linenum, 'no newline at end of file' + yield filename, linenum, b'no newline at end of file' # hunk body - check for an added line with bad whitespace - if filename[-3:] == '.py' or filename[-5:] == '.py.in': + if filename[-3:] == b'.py' or filename[-5:] == b'.py.in': m = tbre.match(line) if m is not None: - yield filename, linenum, 'TABs' + yield filename, linenum, b'TABs' # trailing whitespace, for now only in Python source m = wsre.match(line) if m is not None: - if filename[-3:] == '.py' or filename[-5:] == '.py.in': - yield filename, linenum, 'trailing whitespace' + if filename[-3:] == b'.py' or filename[-5:] == b'.py.in': + yield filename, linenum, b'trailing whitespace' # conflict markers m = resre.match(line) if m is not None: - yield filename, linenum, 'conflict marker' - if line and line[0] in ' +': + yield filename, linenum, b'conflict marker' + if line and line[0] in b' +': linenum += 1 def hook(ui, repo, hooktype, node=None, source=None, **kwargs): import os, sys, subprocess - if hooktype not in ['pretxnchangegroup', 'pretxncommit']: - ui.write('Hook should be pretxncommit/pretxnchangegroup not "%s".' % hooktype) + if hooktype not in [b'pretxnchangegroup', b'pretxncommit']: + ui.write(b'Hook should be pretxncommit/pretxnchangegroup not "%s".' % hooktype) return 1 added = False branches = {} - for rev in xrange(repo[node].rev(), len(repo)): + for rev in range(repo[node].rev(), len(repo)): branch = repo[rev].branch() - if not branches.has_key(branch): + if branch not in branches: # first time we see this branch, remember parents to diff against branches[branch] = repo[rev].parents() desc = 0