summaryrefslogtreecommitdiff
path: root/fastimport/commands.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2021-09-18 16:55:06 +0100
committerJelmer Vernooij <jelmer@jelmer.uk>2021-09-18 16:55:06 +0100
commit90cc92891309e192f6c6ba2665badac12619a1ed (patch)
treec6e3e5720f914749799946f40bca3a39b0729f02 /fastimport/commands.py
parent088bc0459e50bbcb948f3317772825859347b014 (diff)
parent6ed4b196e21974c6bac4323522cd086794618068 (diff)
downloadpython-fastimport-git-upstream.tar.gz
Import upstream version 0.9.14upstream/0.9.14upstream
Diffstat (limited to 'fastimport/commands.py')
-rw-r--r--fastimport/commands.py61
1 files changed, 30 insertions, 31 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py
index 7f29599..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 fastimport.helpers import (
+from .helpers import (
newobject as object,
utf8_bytes_string,
- repr_bytes,
)
@@ -43,9 +41,9 @@ GIT_FAST_IMPORT_NEEDS_EXTRA_SPACE_AFTER_QUOTE = False
# Lists of command names
COMMAND_NAMES = [b'blob', b'checkpoint', b'commit', b'feature', b'progress',
- b'reset', b'tag']
+ b'reset', b'tag']
FILE_COMMAND_NAMES = [b'filemodify', b'filedelete', b'filecopy', b'filerename',
- b'filedeleteall']
+ b'filedeleteall']
# Feature names
MULTIPLE_AUTHORS_FEATURE = b'multiple-authors'
@@ -70,10 +68,7 @@ class ImportCommand(object):
return repr(self)
def __repr__(self):
- if sys.version_info[0] == 2:
- return self.__bytes__()
- else:
- return bytes(self).decode('utf8')
+ return bytes(self).decode('utf8')
def __bytes__(self):
raise NotImplementedError(
@@ -147,7 +142,8 @@ class CheckpointCommand(ImportCommand):
class CommitCommand(ImportCommand):
def __init__(self, ref, mark, author, committer, message, from_,
- merges, file_iter, lineno=0, more_authors=None, properties=None):
+ merges, file_iter, lineno=0, more_authors=None,
+ properties=None):
ImportCommand.__init__(self, b'commit')
self.ref = ref
self.mark = mark
@@ -188,7 +184,6 @@ class CommitCommand(ImportCommand):
def __bytes__(self):
return self.to_string(include_file_contents=True)
-
def to_string(self, use_features=True, include_file_contents=False):
"""
@todo the name to_string is ambiguous since the method actually
@@ -224,8 +219,8 @@ class CommitCommand(ImportCommand):
if self.merges is None:
merge_lines = b''
else:
- merge_lines = b''.join([b'\nmerge ' + m
- for m in self.merges])
+ merge_lines = b''.join(
+ [b'\nmerge ' + m for m in self.merges])
if use_features and self.properties:
property_lines = []
for name in sorted(self.properties):
@@ -238,11 +233,11 @@ class CommitCommand(ImportCommand):
filecommands = b''
else:
if include_file_contents:
- filecommands = b''.join([b'\n' + repr_bytes(c)
- for c in self.iter_files()])
+ filecommands = b''.join(
+ [b'\n' + bytes(c) for c in self.iter_files()])
else:
- filecommands = b''.join([b'\n' + str(c)
- for c in self.iter_files()])
+ filecommands = b''.join(
+ [b'\n' + str(c) for c in self.iter_files()])
return b''.join([
b'commit ',
self.ref,
@@ -390,7 +385,9 @@ class FileModifyCommand(FileCommand):
elif self.dataref is None:
dataref = b'inline'
if include_file_contents:
- datastr = ('\ndata %d\n' % len(self.data)).encode('ascii') + self.data
+ datastr = (
+ ('\ndata %d\n' % len(self.data)).encode('ascii') +
+ self.data)
else:
dataref = self.dataref
path = format_path(self.path)
@@ -417,9 +414,9 @@ class FileCopyCommand(FileCommand):
self.dest_path = check_path(dest_path)
def __bytes__(self):
- return b' '.join([b'C',
- format_path(self.src_path, quote_spaces=True),
- format_path(self.dest_path)])
+ return b' '.join(
+ [b'C', format_path(self.src_path, quote_spaces=True),
+ format_path(self.dest_path)])
class FileRenameCommand(FileCommand):
@@ -456,7 +453,7 @@ class NoteModifyCommand(FileCommand):
def __bytes__(self):
return (b'N inline :' + self.from_ +
- ('\ndata %d\n'% len(self.data)).encode('ascii') + self.data)
+ ('\ndata %d\n' % len(self.data)).encode('ascii') + self.data)
def check_path(path):
@@ -468,11 +465,8 @@ def check_path(path):
if path is None or path == b'' or path.startswith(b'/'):
raise ValueError("illegal path '%s'" % path)
- if (
- (sys.version_info[0] >= 3 and not isinstance(path, bytes)) and
- (sys.version_info[0] == 2 and not isinstance(path, str))
- ):
- raise TypeError("illegale type for path '%r'" % path)
+ if not isinstance(path, bytes):
+ raise TypeError("illegal type for path '%r'" % path)
return path
@@ -491,7 +485,7 @@ def format_path(p, quote_spaces=False):
def format_who_when(fields):
- """Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string."""
+ """Format tuple of name,email,secs-since-epoch,utc-offset-secs as bytes."""
offset = fields[3]
if offset < 0:
offset_sign = b'-'
@@ -500,7 +494,9 @@ def format_who_when(fields):
offset_sign = b'+'
offset_hours = offset // 3600
offset_minutes = offset // 60 - offset_hours * 60
- offset_str = offset_sign + ('%02d%02d' % (offset_hours, offset_minutes)).encode('ascii')
+ offset_str = (
+ offset_sign +
+ ('%02d%02d' % (offset_hours, offset_minutes)).encode('ascii'))
name = fields[0]
if name == b'':
@@ -514,7 +510,9 @@ def format_who_when(fields):
email = utf8_bytes_string(email)
- return b''.join((name, sep, b'<', email, b'> ', ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
+ return b''.join(
+ (name, sep, b'<', email, b'> ',
+ ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
def format_property(name, value):
@@ -525,6 +523,7 @@ def format_property(name, value):
result = b'property ' + utf8_name
if value is not None:
utf8_value = utf8_bytes_string(value)
- result += b' ' + ('%d' % len(utf8_value)).encode('ascii') + b' ' + utf8_value
+ result += (b' ' + ('%d' % len(utf8_value)).encode('ascii') +
+ b' ' + utf8_value)
return result