py3: fix eol

Reviewed By: markbt

Differential Revision: D19802025

fbshipit-source-id: f6e6c03ea2d64500b92bcf8b97c9ddedb83fd3c0
This commit is contained in:
Durham Goode 2020-02-17 14:47:28 -08:00 committed by Facebook Github Bot
parent c4f7d32501
commit c9b1fee40f
10 changed files with 18 additions and 25 deletions

View File

@ -133,11 +133,11 @@ configitem("eol", "native", default=pycompat.oslinesep)
configitem("eol", "only-consistent", default=True)
# Matches a lone LF, i.e., one that is not part of CRLF.
singlelf = re.compile("(^|[^\r])\n")
singlelf = re.compile(b"(^|[^\r])\n")
def inconsistenteol(data):
return "\r\n" in data and singlelf.search(data)
return b"\r\n" in data and singlelf.search(data)
def tolf(s, params, ui, **kwargs):
@ -146,8 +146,8 @@ def tolf(s, params, ui, **kwargs):
return s
if ui.configbool("eol", "only-consistent") and inconsistenteol(s):
return s
if ui.configbool("eol", "fix-trailing-newline") and s and s[-1] != "\n":
s = s + "\n"
if ui.configbool("eol", "fix-trailing-newline") and s and s[-1] != b"\n":
s = s + b"\n"
return util.tolf(s)
@ -157,12 +157,12 @@ def tocrlf(s, params, ui, **kwargs):
return s
if ui.configbool("eol", "only-consistent") and inconsistenteol(s):
return s
if ui.configbool("eol", "fix-trailing-newline") and s and s[-1] != "\n":
s = s + "\n"
if ui.configbool("eol", "fix-trailing-newline") and s and s[-1] != b"\n":
s = s + b"\n"
return util.tocrlf(s)
def isbinary(s, params):
def isbinary(s, params, *args, **kwargs):
"""Filter to do nothing with the file."""
return s
@ -235,7 +235,7 @@ class eolfile(object):
data = ctx[f].data()
if (
target == "to-lf"
and "\r\n" in data
and b"\r\n" in data
or target == "to-crlf"
and singlelf.search(data)
):
@ -254,6 +254,7 @@ def parseeol(ui, repo, nodes):
data = repo.wvfs(".hgeol").read()
else:
data = repo[node][".hgeol"].data()
data = pycompat.decodeutf8(data)
return eolfile(ui, repo.root, data)
except (IOError, LookupError):
pass
@ -374,6 +375,7 @@ def reposetup(ui, repo):
else:
olddata = self.localvfs.read("eol.cache")
if olddata:
olddata = pycompat.decodeutf8(olddata)
oldeol = eolfile(self.ui, self.root, olddata)
try:
@ -385,6 +387,7 @@ def reposetup(ui, repo):
self.ui.debug("eol: detected change in .hgeol\n")
hgeoldata = self.wvfs.read(".hgeol")
hgeoldata = pycompat.decodeutf8(hgeoldata)
neweol = eolfile(self.ui, self.root, hgeoldata)
try:
@ -411,8 +414,8 @@ def reposetup(ui, repo):
# the new .hgeol file specify a different filter
self.dirstate.normallookup(f)
# Write the cache to update mtime and cache .hgeol
with self.localvfs("eol.cache", "w") as f:
f.write(hgeoldata)
with self.localvfs("eol.cache", "wb") as f:
f.write(pycompat.encodeutf8(hgeoldata))
except errormod.LockUnavailable:
# If we cannot lock the repository and clear the
# dirstate, then a commit might not see all files

View File

@ -116,7 +116,7 @@ def cleverdecode(s, cmd, **kwargs):
return s
def cleverencode(s, cmd):
def cleverencode(s, cmd, **kwargs):
if not util.binary(s):
return dumbencode(s, cmd)
return s

View File

@ -14,7 +14,6 @@ from __future__ import absolute_import
import errno
import hashlib
import inspect
import os
import random
import time
@ -1242,10 +1241,6 @@ class localrepository(object):
break
if not fn:
fn = lambda s, c, **kwargs: util.filter(s, c)
# Wrap old filters not supporting keyword arguments
if not inspect.getargspec(fn)[2]:
oldfn = fn
fn = lambda s, c, **kwargs: oldfn(s, c)
l.append((mf, fn, params))
self.filterpats[filter] = l
return self.filterpats[filter]

View File

@ -2414,15 +2414,15 @@ bytecount = unitcountfn(
# Matches a single EOL which can either be a CRLF where repeated CR
# are removed or a LF. We do not care about old Macintosh files, so a
# stray CR is an error.
_eolre = remod.compile(r"\r*\n")
_eolre = remod.compile(b"\r*\n")
def tolf(s):
return _eolre.sub("\n", s)
return _eolre.sub(b"\n", s)
def tocrlf(s):
return _eolre.sub("\r\n", s)
return _eolre.sub(b"\r\n", s)
if pycompat.oslinesep == "\r\n":

View File

@ -30,7 +30,7 @@ def stripprefix(s, cmd, filename, **kwargs):
if s[:len(header)] != header:
raise error.Abort('missing header "%s" in %s' % (cmd, filename))
return s[len(header):]
def insertprefix(s, cmd):
def insertprefix(s, cmd, **kwargs):
return '%s\n%s' % (cmd, s)
def reposetup(ui, repo):
repo.adddatafilter('stripprefix:', stripprefix)

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible
Test encode/decode filters

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible
$ disable treemanifest

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible
$ disable treemanifest

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible
$ disable treemanifest

View File

@ -1,4 +1,3 @@
#require py2
#chg-compatible
$ disable treemanifest