Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09935bc

Browse files
committed
Fix things Tox didn't like for Python3
1 parent bd97e05 commit 09935bc

File tree

16 files changed

+1330
-812
lines changed

16 files changed

+1330
-812
lines changed

git/cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def check_unsafe_protocols(cls, url: str) -> None:
198198
)
199199

200200
@classmethod
201-
def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) -> None:
201+
def check_unsafe_options(cls, options, unsafe_options):
202202
"""
203203
Check for unsafe options.
204204
Some options that are passed to `git <command>` can be used to execute
@@ -1131,7 +1131,7 @@ def get_object_data(self, ref):
11311131
:note: not threadsafe"""
11321132
hexsha, typename, size, stream = self.stream_object_data(ref)
11331133
data = stream.read(size)
1134-
del(stream)
1134+
del (stream)
11351135
return (hexsha, typename, size, data)
11361136

11371137
def stream_object_data(self, ref):

git/index/base.py

Lines changed: 192 additions & 110 deletions
Large diffs are not rendered by default.

git/index/fun.py

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,74 +23,73 @@
2323
safe_encode,
2424
safe_decode,
2525
)
26-
from git.exc import (
27-
UnmergedEntriesError,
28-
HookExecutionError
29-
)
26+
from git.exc import UnmergedEntriesError, HookExecutionError
3027
from git.objects.fun import (
3128
tree_to_stream,
3229
traverse_tree_recursive,
33-
traverse_trees_recursive
30+
traverse_trees_recursive,
3431
)
3532
from git.util import IndexFileSHA1Writer, finalize_process
3633
from gitdb.base import IStream
3734
from gitdb.typ import str_tree_type
3835

3936
import os.path as osp
4037

41-
from .typ import (
42-
BaseIndexEntry,
43-
IndexEntry,
44-
CE_NAMEMASK,
45-
CE_STAGESHIFT
46-
)
47-
from .util import (
48-
pack,
49-
unpack
50-
)
38+
from .typ import BaseIndexEntry, IndexEntry, CE_NAMEMASK, CE_STAGESHIFT
39+
from .util import pack, unpack
5140

5241

53-
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
42+
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
5443
CE_NAMEMASK_INV = ~CE_NAMEMASK
5544

56-
__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key',
57-
'stat_mode_to_index_mode', 'S_IFGITLINK', 'run_commit_hook', 'hook_path')
45+
__all__ = (
46+
"write_cache",
47+
"read_cache",
48+
"write_tree_from_cache",
49+
"entry_key",
50+
"stat_mode_to_index_mode",
51+
"S_IFGITLINK",
52+
"run_commit_hook",
53+
"hook_path",
54+
)
5855

5956

6057
def hook_path(name, git_dir):
6158
""":return: path to the given named hook in the given git repository directory"""
62-
return osp.join(git_dir, 'hooks', name)
59+
return osp.join(git_dir, "hooks", name)
6360

6461

6562
def run_commit_hook(name, index, *args):
6663
"""Run the commit hook of the given name. Silently ignores hooks that do not exist.
6764
:param name: name of hook, like 'pre-commit'
6865
:param index: IndexFile instance
6966
:param args: arguments passed to hook file
70-
:raises HookExecutionError: """
67+
:raises HookExecutionError:"""
7168
hp = hook_path(name, index.repo.git_dir)
7269
if not os.access(hp, os.X_OK):
7370
return
7471

7572
env = os.environ.copy()
76-
env['GIT_INDEX_FILE'] = safe_decode(index.path) if PY3 else safe_encode(index.path)
77-
env['GIT_EDITOR'] = ':'
73+
env["GIT_INDEX_FILE"] = safe_decode(index.path) if PY3 else safe_encode(index.path)
74+
env["GIT_EDITOR"] = ":"
7875
try:
79-
cmd = subprocess.Popen([hp] + list(args),
80-
env=env,
81-
stdout=subprocess.PIPE,
82-
stderr=subprocess.PIPE,
83-
cwd=index.repo.working_dir,
84-
close_fds=is_posix,
85-
creationflags=PROC_CREATIONFLAGS,)
76+
cmd = subprocess.Popen(
77+
[hp] + list(args),
78+
env=env,
79+
stdout=subprocess.PIPE,
80+
stderr=subprocess.PIPE,
81+
cwd=index.repo.working_dir,
82+
close_fds=is_posix,
83+
creationflags=PROC_CREATIONFLAGS,
84+
)
8685
except Exception as ex:
8786
raise HookExecutionError(hp, ex)
8887
else:
8988
stdout = []
9089
stderr = []
9190
handle_process_output(cmd, stdout.append, stderr.append, finalize_process)
92-
stdout = ''.join(stdout)
93-
stderr = ''.join(stderr)
91+
stdout = "".join(stdout)
92+
stderr = "".join(stderr)
9493
if cmd.returncode != 0:
9594
stdout = force_text(stdout, defenc)
9695
stderr = force_text(stderr, defenc)
@@ -101,11 +100,11 @@ def run_commit_hook(name, index, *args):
101100
def stat_mode_to_index_mode(mode):
102101
"""Convert the given mode from a stat call to the corresponding index mode
103102
and return it"""
104-
if S_ISLNK(mode): # symlinks
103+
if S_ISLNK(mode): # symlinks
105104
return S_IFLNK
106-
if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules
105+
if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules
107106
return S_IFGITLINK
108-
return S_IFREG | 0o644 | (mode & 0o111) # blobs with or without executable bit
107+
return S_IFREG | 0o644 | (mode & 0o111) # blobs with or without executable bit
109108

110109

111110
def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer):
@@ -134,17 +133,28 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
134133
# body
135134
for entry in entries:
136135
beginoffset = tell()
137-
write(entry[4]) # ctime
138-
write(entry[5]) # mtime
136+
write(entry[4]) # ctime
137+
write(entry[5]) # mtime
139138
path = entry[3]
140139
path = force_bytes(path, encoding=defenc)
141-
plen = len(path) & CE_NAMEMASK # path length
140+
plen = len(path) & CE_NAMEMASK # path length
142141
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
143-
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
144-
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
145-
entry[8], entry[9], entry[10], entry[1], flags))
142+
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
143+
write(
144+
pack(
145+
">LLLLLL20sH",
146+
entry[6],
147+
entry[7],
148+
entry[0],
149+
entry[8],
150+
entry[9],
151+
entry[10],
152+
entry[1],
153+
flags,
154+
)
155+
)
146156
write(path)
147-
real_size = ((tell() - beginoffset + 8) & ~7)
157+
real_size = (tell() - beginoffset + 8) & ~7
148158
write(b"\0" * ((beginoffset + real_size) - tell()))
149159
# END for each entry
150160

@@ -195,14 +205,17 @@ def read_cache(stream):
195205
beginoffset = tell()
196206
ctime = unpack(">8s", read(8))[0]
197207
mtime = unpack(">8s", read(8))[0]
198-
(dev, ino, mode, uid, gid, size, sha, flags) = \
199-
unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2))
208+
(dev, ino, mode, uid, gid, size, sha, flags) = unpack(
209+
">LLLLLL20sH", read(20 + 4 * 6 + 2)
210+
)
200211
path_size = flags & CE_NAMEMASK
201212
path = read(path_size).decode(defenc)
202213

203-
real_size = ((tell() - beginoffset + 8) & ~7)
214+
real_size = (tell() - beginoffset + 8) & ~7
204215
read((beginoffset + real_size) - tell())
205-
entry = IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size))
216+
entry = IndexEntry(
217+
(mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size)
218+
)
206219
# entry_key would be the method to use, but we safe the effort
207220
entries[(path, entry.stage)] = entry
208221
count += 1
@@ -215,8 +228,10 @@ def read_cache(stream):
215228
# 4 bytes length of chunk
216229
# repeated 0 - N times
217230
extension_data = stream.read(~0)
218-
assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size"\
219-
% len(extension_data)
231+
assert len(extension_data) > 19, (
232+
"Index Footer was not at least a sha on content as it was only %i bytes in size"
233+
% len(extension_data)
234+
)
220235

221236
content_sha = extension_data[-20:]
222237

@@ -246,7 +261,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
246261
raise UnmergedEntriesError(entry)
247262
# END abort on unmerged
248263
ci += 1
249-
rbound = entry.path.find('/', si)
264+
rbound = entry.path.find("/", si)
250265
if rbound == -1:
251266
# its not a tree
252267
tree_items_append((entry.binsha, entry.mode, entry.path[si:]))
@@ -256,7 +271,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
256271
xi = ci
257272
while xi < end:
258273
oentry = entries[xi]
259-
orbound = oentry.path.find('/', si)
274+
orbound = oentry.path.find("/", si)
260275
if orbound == -1 or oentry.path[si:orbound] != base:
261276
break
262277
# END abort on base mismatch
@@ -265,7 +280,9 @@ def write_tree_from_cache(entries, odb, sl, si=0):
265280

266281
# enter recursion
267282
# ci - 1 as we want to count our current item as well
268-
sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1) # @UnusedVariable
283+
sha, tree_entry_list = write_tree_from_cache(
284+
entries, odb, slice(ci - 1, xi), rbound + 1
285+
) # @UnusedVariable
269286
tree_items_append((sha, S_IFDIR, base))
270287

271288
# skip ahead
@@ -283,7 +300,9 @@ def write_tree_from_cache(entries, odb, sl, si=0):
283300

284301

285302
def _tree_entry_to_baseindexentry(tree_entry, stage):
286-
return BaseIndexEntry((tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2]))
303+
return BaseIndexEntry(
304+
(tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2])
305+
)
287306

288307

289308
def aggressive_tree_merge(odb, tree_shas):
@@ -301,7 +320,7 @@ def aggressive_tree_merge(odb, tree_shas):
301320
# one and two way is the same for us, as we don't have to handle an existing
302321
# index, instrea
303322
if len(tree_shas) in (1, 2):
304-
for entry in traverse_tree_recursive(odb, tree_shas[-1], ''):
323+
for entry in traverse_tree_recursive(odb, tree_shas[-1], ""):
305324
out_append(_tree_entry_to_baseindexentry(entry, 0))
306325
# END for each entry
307326
return out
@@ -311,7 +330,7 @@ def aggressive_tree_merge(odb, tree_shas):
311330
raise ValueError("Cannot handle %i trees at once" % len(tree_shas))
312331

313332
# three trees
314-
for base, ours, theirs in traverse_trees_recursive(odb, tree_shas, ''):
333+
for base, ours, theirs in traverse_trees_recursive(odb, tree_shas, ""):
315334
if base is not None:
316335
# base version exists
317336
if ours is not None:
@@ -320,8 +339,15 @@ def aggressive_tree_merge(odb, tree_shas):
320339
# it exists in all branches, if it was changed in both
321340
# its a conflict, otherwise we take the changed version
322341
# This should be the most common branch, so it comes first
323-
if(base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0]) or \
324-
(base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1]):
342+
if (
343+
base[0] != ours[0]
344+
and base[0] != theirs[0]
345+
and ours[0] != theirs[0]
346+
) or (
347+
base[1] != ours[1]
348+
and base[1] != theirs[1]
349+
and ours[1] != theirs[1]
350+
):
325351
# changed by both
326352
out_append(_tree_entry_to_baseindexentry(base, 1))
327353
out_append(_tree_entry_to_baseindexentry(ours, 2))

git/objects/fun.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
"""Module with functions which are supposed to be as fast as possible"""
2+
23
from stat import S_ISDIR
3-
from git.compat import (
4-
byte_ord,
5-
safe_decode,
6-
defenc,
7-
xrange,
8-
text_type,
9-
bchr
10-
)
4+
from git.compat import byte_ord, safe_decode, defenc, xrange, text_type, bchr
115

12-
__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
13-
'traverse_tree_recursive')
6+
__all__ = (
7+
"tree_to_stream",
8+
"tree_entries_from_data",
9+
"traverse_trees_recursive",
10+
"traverse_tree_recursive",
11+
)
1412

1513

1614
def tree_to_stream(entries, write):
1715
"""Write the give list of entries into a stream using its write method
1816
:param entries: **sorted** list of tuples with (binsha, mode, name)
1917
:param write: write method which takes a data string"""
20-
ord_zero = ord('0')
21-
bit_mask = 7 # 3 bits set
18+
ord_zero = ord("0")
19+
bit_mask = 7 # 3 bits set
2220

2321
for binsha, mode, name in entries:
24-
mode_str = b''
22+
mode_str = b""
2523
for i in xrange(6):
2624
mode_str = bchr(((mode >> (i * 3)) & bit_mask) + ord_zero) + mode_str
2725
# END for each 8 octal value
@@ -38,16 +36,16 @@ def tree_to_stream(entries, write):
3836
# takes the input literally, which appears to be utf8 on linux.
3937
if isinstance(name, text_type):
4038
name = name.encode(defenc)
41-
write(b''.join((mode_str, b' ', name, b'\0', binsha)))
39+
write(b"".join((mode_str, b" ", name, b"\0", binsha)))
4240
# END for each item
4341

4442

4543
def tree_entries_from_data(data):
4644
"""Reads the binary representation of a tree and returns tuples of Tree items
4745
:param data: data block with tree data (as bytes)
4846
:return: list(tuple(binsha, mode, tree_relative_path), ...)"""
49-
ord_zero = ord('0')
50-
space_ord = ord(' ')
47+
ord_zero = ord("0")
48+
space_ord = ord(" ")
5149
len_data = len(data)
5250
i = 0
5351
out = []
@@ -81,7 +79,7 @@ def tree_entries_from_data(data):
8179

8280
# byte is NULL, get next 20
8381
i += 1
84-
sha = data[i:i + 20]
82+
sha = data[i: i + 20]
8583
i = i + 20
8684
out.append((sha, mode, name))
8785
# END for each byte in data stream
@@ -156,8 +154,8 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
156154
# END skip already done items
157155
entries = [None for _ in range(nt)]
158156
entries[ti] = item
159-
sha, mode, name = item # its faster to unpack @UnusedVariable
160-
is_dir = S_ISDIR(mode) # type mode bits
157+
sha, mode, name = item # its faster to unpack @UnusedVariable
158+
is_dir = S_ISDIR(mode) # type mode bits
161159

162160
# find this item in all other tree data items
163161
# wrap around, but stop one before our current index, hence
@@ -169,8 +167,13 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
169167

170168
# if we are a directory, enter recursion
171169
if is_dir:
172-
out.extend(traverse_trees_recursive(
173-
odb, [((ei and ei[0]) or None) for ei in entries], path_prefix + name + '/'))
170+
out.extend(
171+
traverse_trees_recursive(
172+
odb,
173+
[((ei and ei[0]) or None) for ei in entries],
174+
path_prefix + name + "/",
175+
)
176+
)
174177
else:
175178
out_append(tuple(_to_full_path(e, path_prefix) for e in entries))
176179
# END handle recursion
@@ -180,7 +183,7 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
180183
# END for each item
181184

182185
# we are done with one tree, set all its data empty
183-
del(tree_data[:])
186+
del tree_data[:]
184187
# END for each tree_data chunk
185188
return out
186189

@@ -199,7 +202,7 @@ def traverse_tree_recursive(odb, tree_sha, path_prefix):
199202
# unpacking/packing is faster than accessing individual items
200203
for sha, mode, name in data:
201204
if S_ISDIR(mode):
202-
entries.extend(traverse_tree_recursive(odb, sha, path_prefix + name + '/'))
205+
entries.extend(traverse_tree_recursive(odb, sha, path_prefix + name + "/"))
203206
else:
204207
entries.append((sha, mode, path_prefix + name))
205208
# END for each item

0 commit comments

Comments
 (0)