summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/cmd.py7
-rw-r--r--git/compat.py4
-rw-r--r--git/config.py5
-rw-r--r--git/diff.py12
-rw-r--r--git/index/fun.py3
-rw-r--r--git/objects/tree.py5
-rw-r--r--git/refs/log.py8
-rw-r--r--git/repo/base.py8
-rw-r--r--git/test/test_fun.py1
-rw-r--r--git/test/test_git.py12
-rw-r--r--git/test/test_index.py6
-rw-r--r--git/test/test_repo.py6
-rw-r--r--git/util.py6
13 files changed, 13 insertions, 70 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 54614355..906ee585 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -24,7 +24,6 @@ from git.compat import (
string_types,
defenc,
force_bytes,
- PY3,
safe_decode,
is_posix,
is_win,
@@ -916,18 +915,12 @@ class Git(LazyMixin):
@classmethod
def __unpack_args(cls, arg_list):
if not isinstance(arg_list, (list, tuple)):
- # This is just required for unicode conversion, as subprocess can't handle it
- # However, in any other case, passing strings (usually utf-8 encoded) is totally fine
- if not PY3 and isinstance(arg_list, str):
- return [arg_list.encode(defenc)]
return [str(arg_list)]
outlist = []
for arg in arg_list:
if isinstance(arg_list, (list, tuple)):
outlist.extend(cls.__unpack_args(arg))
- elif not PY3 and isinstance(arg_list, str):
- outlist.append(arg_list.encode(defenc))
# END recursion
else:
outlist.append(str(arg))
diff --git a/git/compat.py b/git/compat.py
index d214b230..0c8ed4bb 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -70,9 +70,5 @@ def with_metaclass(meta, *bases):
def __new__(cls, name, nbases, d):
if nbases is None:
return type.__new__(cls, name, (), d)
- # There may be clients who rely on this attribute to be set to a reasonable value, which is why
- # we set the __metaclass__ attribute explicitly
- if not PY3 and '___metaclass__' not in d:
- d['__metaclass__'] = meta
return meta(name, bases, d)
return metaclass(meta.__name__ + 'Helper', None, {})
diff --git a/git/config.py b/git/config.py
index be816e0a..6b45bc63 100644
--- a/git/config.py
+++ b/git/config.py
@@ -20,7 +20,6 @@ from git.compat import (
defenc,
force_text,
with_metaclass,
- PY3,
is_win,
)
from git.util import LockFile
@@ -372,9 +371,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
v = v[:-1]
# end cut trailing escapes to prevent decode error
- if PY3:
- return v.encode(defenc).decode('unicode_escape')
- return v.decode('string_escape')
+ return v.encode(defenc).decode('unicode_escape')
# end
# end
diff --git a/git/diff.py b/git/diff.py
index 42a68dfc..567e3e70 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -6,10 +6,7 @@
import re
from git.cmd import handle_process_output
-from git.compat import (
- defenc,
- PY3
-)
+from git.compat import defenc
from git.util import finalize_process, hex_to_bin
from .objects.blob import Blob
@@ -27,10 +24,7 @@ _octal_byte_re = re.compile(b'\\\\([0-9]{3})')
def _octal_repl(matchobj):
value = matchobj.group(1)
value = int(value, 8)
- if PY3:
- value = bytes(bytearray((value,)))
- else:
- value = chr(value)
+ value = bytes(bytearray((value,)))
return value
@@ -369,8 +363,6 @@ class Diff(object):
# Python2 silliness: have to assure we convert our likely to be unicode object to a string with the
# right encoding. Otherwise it tries to convert it using ascii, which may fail ungracefully
res = h + msg
- if not PY3:
- res = res.encode(defenc)
# end
return res
diff --git a/git/index/fun.py b/git/index/fun.py
index 5906a358..5c28a38c 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -15,7 +15,6 @@ import subprocess
from git.cmd import PROC_CREATIONFLAGS, handle_process_output
from git.compat import (
- PY3,
defenc,
force_text,
force_bytes,
@@ -73,7 +72,7 @@ def run_commit_hook(name, index, *args):
return
env = os.environ.copy()
- env['GIT_INDEX_FILE'] = safe_decode(index.path) if PY3 else safe_encode(index.path)
+ env['GIT_INDEX_FILE'] = safe_decode(index.path)
env['GIT_EDITOR'] = ':'
try:
cmd = subprocess.Popen([hp] + list(args),
diff --git a/git/objects/tree.py b/git/objects/tree.py
index d6134e30..90996bfa 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -18,10 +18,7 @@ from .fun import (
tree_to_stream
)
-from git.compat import PY3
-
-if PY3:
- cmp = lambda a, b: (a > b) - (a < b)
+cmp = lambda a, b: (a > b) - (a < b)
__all__ = ("TreeModifier", "Tree")
diff --git a/git/refs/log.py b/git/refs/log.py
index 274660c5..d51c3458 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -2,7 +2,6 @@ import re
import time
from git.compat import (
- PY3,
string_types,
defenc
)
@@ -35,12 +34,7 @@ class RefLogEntry(tuple):
def __repr__(self):
"""Representation of ourselves in git reflog format"""
- res = self.format()
- if PY3:
- return res
- # repr must return a string, which it will auto-encode from unicode using the default encoding.
- # This usually fails, so we encode ourselves
- return res.encode(defenc)
+ return self.format()
def format(self):
""":return: a string suitable to be placed in a reflog file"""
diff --git a/git/repo/base.py b/git/repo/base.py
index 8c7b1e9a..2691136e 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -17,7 +17,6 @@ from git.cmd import (
from git.compat import (
text_type,
defenc,
- PY3,
safe_decode,
is_win,
)
@@ -691,11 +690,8 @@ class Repo(object):
# Special characters are escaped
if filename[0] == filename[-1] == '"':
filename = filename[1:-1]
- if PY3:
- # WHATEVER ... it's a mess, but works for me
- filename = filename.encode('ascii').decode('unicode_escape').encode('latin1').decode(defenc)
- else:
- filename = filename.decode('string_escape').decode(defenc)
+ # WHATEVER ... it's a mess, but works for me
+ filename = filename.encode('ascii').decode('unicode_escape').encode('latin1').decode(defenc)
untracked_files.append(filename)
finalize_process(proc)
return untracked_files
diff --git a/git/test/test_fun.py b/git/test/test_fun.py
index 314fb734..d5d0dde9 100644
--- a/git/test/test_fun.py
+++ b/git/test/test_fun.py
@@ -287,7 +287,6 @@ class TestFun(TestBase):
r = tree_entries_from_data(b'100644 \x9f\0aaa')
assert r == [('aaa', 33188, u'\udc9f')], r
- @skipIf(not PY3, 'odd types returned ... maybe figure it out one day')
def test_tree_entries_from_data_with_failing_name_decode_py3(self):
r = tree_entries_from_data(b'100644 \x9f\0aaa')
assert r == [(b'aaa', 33188, '\udc9f')], r
diff --git a/git/test/test_git.py b/git/test/test_git.py
index 357d9edb..e6bc19d1 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -17,7 +17,7 @@ from git import (
Repo,
cmd
)
-from git.compat import PY3, is_darwin
+from git.compat import is_darwin
from git.test.lib import (
TestBase,
patch,
@@ -61,18 +61,12 @@ class TestGit(TestBase):
def test_call_unpack_args_unicode(self):
args = Git._Git__unpack_args(u'Unicode€™')
- if PY3:
- mangled_value = 'Unicode\u20ac\u2122'
- else:
- mangled_value = 'Unicode\xe2\x82\xac\xe2\x84\xa2'
+ mangled_value = 'Unicode\u20ac\u2122'
assert_equal(args, [mangled_value])
def test_call_unpack_args(self):
args = Git._Git__unpack_args(['git', 'log', '--', u'Unicode€™'])
- if PY3:
- mangled_value = 'Unicode\u20ac\u2122'
- else:
- mangled_value = 'Unicode\xe2\x82\xac\xe2\x84\xa2'
+ mangled_value = 'Unicode\u20ac\u2122'
assert_equal(args, ['git', 'log', '--', mangled_value])
@raises(GitCommandError)
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 9b8c957e..4a23ceb1 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -25,7 +25,7 @@ from git import (
GitCommandError,
CheckoutError,
)
-from git.compat import string_types, is_win, PY3
+from git.compat import string_types, is_win
from git.exc import (
HookExecutionError,
InvalidGitRepositoryError
@@ -821,10 +821,6 @@ class TestIndex(TestBase):
asserted = True
assert asserted, "Adding using a filename is not correctly asserted."
- @skipIf(HIDE_WINDOWS_KNOWN_ERRORS and not PY3, r"""
- FIXME: File "C:\projects\gitpython\git\util.py", line 125, in to_native_path_linux
- return path.replace('\\', '/')
- UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)""")
@with_rw_directory
def test_add_utf8P_path(self, rw_dir):
# NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index ef28c74e..2d38f150 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -37,7 +37,6 @@ from git import (
GitCommandError
)
from git.compat import (
- PY3,
is_win,
string_types,
win_encode,
@@ -526,11 +525,6 @@ class TestRepo(TestBase):
num_test_untracked += join_path_native(base, utfile) in files
self.assertEqual(len(files), num_test_untracked)
- if is_win and not PY3 and is_invoking_git:
- ## On Windows, shell needed when passing unicode cmd-args.
- #
- repo_add = fnt.partial(repo_add, shell=True)
- untracked_files = [win_encode(f) for f in untracked_files]
repo_add(untracked_files)
self.assertEqual(len(rwrepo.untracked_files), (num_recently_untracked - len(files)))
# end for each run
diff --git a/git/util.py b/git/util.py
index 974657e6..4402e05f 100644
--- a/git/util.py
+++ b/git/util.py
@@ -33,8 +33,7 @@ import os.path as osp
from .compat import (
MAXSIZE,
- defenc,
- PY3
+ defenc
)
from .exc import InvalidGitRepositoryError
@@ -592,9 +591,6 @@ class Actor(object):
('email', env_email, cls.conf_email, default_email)):
try:
val = os.environ[evar]
- if not PY3:
- val = val.decode(defenc)
- # end assure we don't get 'invalid strings'
setattr(actor, attr, val)
except KeyError:
if config_reader is not None: