mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 06:47:41 +03:00
py3: fix eol
Reviewed By: markbt Differential Revision: D19802025 fbshipit-source-id: f6e6c03ea2d64500b92bcf8b97c9ddedb83fd3c0
This commit is contained in:
parent
c4f7d32501
commit
c9b1fee40f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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":
|
||||
|
@ -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)
|
||||
|
@ -1,4 +1,3 @@
|
||||
#require py2
|
||||
#chg-compatible
|
||||
|
||||
Test encode/decode filters
|
||||
|
@ -1,4 +1,3 @@
|
||||
#require py2
|
||||
#chg-compatible
|
||||
|
||||
$ disable treemanifest
|
||||
|
@ -1,4 +1,3 @@
|
||||
#require py2
|
||||
#chg-compatible
|
||||
|
||||
$ disable treemanifest
|
||||
|
@ -1,4 +1,3 @@
|
||||
#require py2
|
||||
#chg-compatible
|
||||
|
||||
$ disable treemanifest
|
||||
|
@ -1,4 +1,3 @@
|
||||
#require py2
|
||||
#chg-compatible
|
||||
|
||||
$ disable treemanifest
|
||||
|
Loading…
Reference in New Issue
Block a user