summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2021-04-10 15:28:12 +0100
committerJelmer Vernooij <jelmer@jelmer.uk>2021-04-10 15:28:12 +0100
commitf32bf2e57f6a4d14ed135719ff718e148888bbdf (patch)
tree2b6bc47efe4de47c9e4d81ee03918306f055e84f
parentd42d2cf768f2bf7beafcbf79e0194f4e3319aa68 (diff)
downloadpython-fastimport-git-f32bf2e57f6a4d14ed135719ff718e148888bbdf.tar.gz
Drop python2 helper.
-rw-r--r--fastimport/commands.py4
-rw-r--r--fastimport/helpers.py6
-rw-r--r--fastimport/processors/filter_processor.py2
-rw-r--r--fastimport/tests/test_commands.py73
4 files changed, 38 insertions, 47 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py
index 9cd72ee..39119c6 100644
--- a/fastimport/commands.py
+++ b/fastimport/commands.py
@@ -22,12 +22,10 @@ from __future__ import division
import re
import stat
-import sys
from .helpers import (
newobject as object,
utf8_bytes_string,
- repr_bytes,
)
@@ -236,7 +234,7 @@ class CommitCommand(ImportCommand):
else:
if include_file_contents:
filecommands = b''.join(
- [b'\n' + repr_bytes(c) for c in self.iter_files()])
+ [b'\n' + bytes(c) for c in self.iter_files()])
else:
filecommands = b''.join(
[b'\n' + str(c) for c in self.iter_files()])
diff --git a/fastimport/helpers.py b/fastimport/helpers.py
index 78fe50c..b1451f7 100644
--- a/fastimport/helpers.py
+++ b/fastimport/helpers.py
@@ -14,7 +14,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Miscellaneous useful stuff."""
-import sys
def _common_path_and_rest(l1, l2, common=[]):
@@ -110,11 +109,6 @@ def utf8_bytes_string(s):
return s
-def repr_bytes(obj):
- """Return a bytes representation of the object"""
- return bytes(obj)
-
-
class newobject(object):
"""
A magical object class that provides Python 2 compatibility methods::
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py
index 91c54f1..a252990 100644
--- a/fastimport/processors/filter_processor.py
+++ b/fastimport/processors/filter_processor.py
@@ -157,7 +157,7 @@ class FilterProcessor(processor.ImportProcessor):
def _print_command(self, cmd):
"""Wrapper to avoid adding unnecessary blank lines."""
- text = helpers.repr_bytes(cmd)
+ text = bytes(cmd)
self.outf.write(text)
if not text.endswith(b'\n'):
self.outf.write(b'\n')
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index 8075661..dabd6a7 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -18,7 +18,6 @@
from unittest import TestCase
from fastimport.helpers import (
- repr_bytes,
utf8_bytes_string,
)
@@ -31,18 +30,18 @@ class TestBlobDisplay(TestCase):
def test_blob(self):
c = commands.BlobCommand(b"1", b"hello world")
- self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", repr_bytes(c))
+ self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", bytes(c))
def test_blob_no_mark(self):
c = commands.BlobCommand(None, b"hello world")
- self.assertEqual(b"blob\ndata 11\nhello world", repr_bytes(c))
+ self.assertEqual(b"blob\ndata 11\nhello world", bytes(c))
class TestCheckpointDisplay(TestCase):
def test_checkpoint(self):
c = commands.CheckpointCommand()
- self.assertEqual(b'checkpoint', repr_bytes(c))
+ self.assertEqual(b'checkpoint', bytes(c))
class TestCommitDisplay(TestCase):
@@ -60,7 +59,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_unicode_committer(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -80,7 +79,7 @@ class TestCommitDisplay(TestCase):
b'refs/heads/master', b'bbb', None, committer,
b'release v1.0', b':aaa', None, None)
- self.assertEqual(commit_utf8, repr_bytes(c))
+ self.assertEqual(commit_utf8, bytes(c))
def test_commit_no_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -94,7 +93,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_no_from(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -108,7 +107,7 @@ class TestCommitDisplay(TestCase):
b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 12\n"
b"release v1.0",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_author(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -125,7 +124,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_merges(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -142,7 +141,7 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"merge :bbb\n"
b"merge :ccc",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_filecommands(self):
file_cmds = iter([
@@ -166,7 +165,7 @@ class TestCommitDisplay(TestCase):
b"M 644 inline NEWS\n"
b"data 14\n"
b"blah blah blah",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_more_authors(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -190,7 +189,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_properties(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -212,7 +211,7 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"property greeting 5 hello\n"
b"property planet 5 world",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_int_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -234,7 +233,7 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"property greeting 5 hello\n"
b"property planet 5 world",
- repr_bytes(c))
+ bytes(c))
class TestCommitCopy(TestCase):
@@ -256,13 +255,13 @@ class TestCommitCopy(TestCase):
c2 = self.c.copy()
self.assertFalse(self.c is c2)
- self.assertEqual(repr_bytes(self.c), repr_bytes(c2))
+ self.assertEqual(bytes(self.c), bytes(c2))
def test_replace_attr(self):
c2 = self.c.copy(mark=b'ccc')
self.assertEqual(
- repr_bytes(self.c).replace(b'mark :bbb', b'mark :ccc'),
- repr_bytes(c2)
+ bytes(self.c).replace(b'mark :bbb', b'mark :ccc'),
+ bytes(c2)
)
def test_invalid_attribute(self):
@@ -273,29 +272,29 @@ class TestFeatureDisplay(TestCase):
def test_feature(self):
c = commands.FeatureCommand(b"dwim")
- self.assertEqual(b"feature dwim", repr_bytes(c))
+ self.assertEqual(b"feature dwim", bytes(c))
def test_feature_with_value(self):
c = commands.FeatureCommand(b"dwim", b"please")
- self.assertEqual(b"feature dwim=please", repr_bytes(c))
+ self.assertEqual(b"feature dwim=please", bytes(c))
class TestProgressDisplay(TestCase):
def test_progress(self):
c = commands.ProgressCommand(b"doing foo")
- self.assertEqual(b"progress doing foo", repr_bytes(c))
+ self.assertEqual(b"progress doing foo", bytes(c))
class TestResetDisplay(TestCase):
def test_reset(self):
c = commands.ResetCommand(b"refs/tags/v1.0", b":xxx")
- self.assertEqual(b"reset refs/tags/v1.0\nfrom :xxx\n", repr_bytes(c))
+ self.assertEqual(b"reset refs/tags/v1.0\nfrom :xxx\n", bytes(c))
def test_reset_no_from(self):
c = commands.ResetCommand(b'refs/remotes/origin/master', None)
- self.assertEqual(b'reset refs/remotes/origin/master', repr_bytes(c))
+ self.assertEqual(b'reset refs/remotes/origin/master', bytes(c))
class TestTagDisplay(TestCase):
@@ -311,7 +310,7 @@ class TestTagDisplay(TestCase):
b"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 11\n"
b"create v1.0",
- repr_bytes(c))
+ bytes(c))
def test_tag_no_from(self):
tagger = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
@@ -322,73 +321,73 @@ class TestTagDisplay(TestCase):
b"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 11\n"
b"create v1.0",
- repr_bytes(c))
+ bytes(c))
class TestFileModifyDisplay(TestCase):
def test_filemodify_file(self):
c = commands.FileModifyCommand(b'foo/bar', 0o100644, b':23', None)
- self.assertEqual(b'M 644 :23 foo/bar', repr_bytes(c))
+ self.assertEqual(b'M 644 :23 foo/bar', bytes(c))
def test_filemodify_file_executable(self):
c = commands.FileModifyCommand(b'foo/bar', 0o100755, b':23', None)
- self.assertEqual(b'M 755 :23 foo/bar', repr_bytes(c))
+ self.assertEqual(b'M 755 :23 foo/bar', bytes(c))
def test_filemodify_file_internal(self):
c = commands.FileModifyCommand(
b'foo/bar', 0o100644, None, b'hello world')
self.assertEqual(
- b'M 644 inline foo/bar\ndata 11\nhello world', repr_bytes(c))
+ b'M 644 inline foo/bar\ndata 11\nhello world', bytes(c))
def test_filemodify_symlink(self):
c = commands.FileModifyCommand(b'foo/bar', 0o120000, None, b'baz')
self.assertEqual(
- b'M 120000 inline foo/bar\ndata 3\nbaz', repr_bytes(c))
+ b'M 120000 inline foo/bar\ndata 3\nbaz', bytes(c))
def test_filemodify_treeref(self):
c = commands.FileModifyCommand(
b'tree-info', 0o160000, b'revision-id-info', None)
self.assertEqual(
- b'M 160000 revision-id-info tree-info', repr_bytes(c))
+ b'M 160000 revision-id-info tree-info', bytes(c))
class TestFileDeleteDisplay(TestCase):
def test_filedelete(self):
c = commands.FileDeleteCommand(b'foo/bar')
- self.assertEqual(b'D foo/bar', repr_bytes(c))
+ self.assertEqual(b'D foo/bar', bytes(c))
class TestFileCopyDisplay(TestCase):
def test_filecopy(self):
c = commands.FileCopyCommand(b'foo/bar', b'foo/baz')
- self.assertEqual(b'C foo/bar foo/baz', repr_bytes(c))
+ self.assertEqual(b'C foo/bar foo/baz', bytes(c))
def test_filecopy_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileCopyCommand(b'foo/b a r', b'foo/b a z')
- self.assertEqual(b'C "foo/b a r" foo/b a z', repr_bytes(c))
+ self.assertEqual(b'C "foo/b a r" foo/b a z', bytes(c))
class TestFileRenameDisplay(TestCase):
def test_filerename(self):
c = commands.FileRenameCommand(b'foo/bar', b'foo/baz')
- self.assertEqual(b'R foo/bar foo/baz', repr_bytes(c))
+ self.assertEqual(b'R foo/bar foo/baz', bytes(c))
def test_filerename_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileRenameCommand(b'foo/b a r', b'foo/b a z')
- self.assertEqual(b'R "foo/b a r" foo/b a z', repr_bytes(c))
+ self.assertEqual(b'R "foo/b a r" foo/b a z', bytes(c))
class TestFileDeleteAllDisplay(TestCase):
def test_filedeleteall(self):
c = commands.FileDeleteAllCommand()
- self.assertEqual(b'deleteall', repr_bytes(c))
+ self.assertEqual(b'deleteall', bytes(c))
class TestNotesDisplay(TestCase):
@@ -396,7 +395,7 @@ class TestNotesDisplay(TestCase):
def test_noteonly(self):
c = commands.NoteModifyCommand(b'foo', b'A basic note')
self.assertEqual(
- b'N inline :foo\ndata 12\nA basic note', repr_bytes(c))
+ b'N inline :foo\ndata 12\nA basic note', bytes(c))
def test_notecommit(self):
committer = (b'Ed Mund', b'ed@example.org', 1234565432, 0)
@@ -463,7 +462,7 @@ Notes added by 'git notes add'
N inline :1
data 10
Test test
-""", b''.join([repr_bytes(s) for s in commits]))
+""", b''.join([bytes(s) for s in commits]))
class TestPathChecking(TestCase):