Skip to content

Commit c80d727

Browse files
committed
Bumped version, updated changelog, reduced code smell
There is more work to do though, as many imports are still incorrect. Also, there are still print statements
1 parent 965a08c commit c80d727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+157
-165
lines changed

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ New BSD License. See the LICENSE file.
6666
### DEVELOPMENT STATUS
6767

6868
[![Build Status](https://travis-ci.org/gitpython-developers/GitPython.svg?branch=0.3)](https://travis-ci.org/gitpython-developers/GitPython)
69-
[![Coverage Status](https://coveralls.io/repos/gitpython-developers/GitPython/badge.png)](https://coveralls.io/r/gitpython-developers/GitPython)
69+
[![Coverage Status](https://coveralls.io/repos/gitpython-developers/GitPython/badge.png?branch=0.3)](https://coveralls.io/r/gitpython-developers/GitPython?branch=0.3)
7070
[![Documentation Status](https://readthedocs.org/projects/gitpython/badge/?version=stable)](https://readthedocs.org/projects/gitpython/?badge=stable)
7171

7272

‎VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.2.1
1+
0.3.3

‎doc/source/changes.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changelog
55
0.3.3
66
=====
77
* When fetching, pulling or pushing, and an error occours, it will not be reported on stdout anymore. However, if there is a fatal error, it will still result in a GitCommandError to be thrown. This goes hand in hand with improved fetch result parsing.
8+
* Code Cleanup (in preparation for python 3 support)
9+
* Applied autopep8 and cleaned up code
10+
* Using python logging module instead of print statments to signal certain kinds of errors
811

912
0.3.2.1
1013
=======

‎git/cmd.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def execute(self, command,
334334
If you add additional keyword arguments to the signature of this method,
335335
you must update the execute_kwargs tuple housed in this module."""
336336
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != 'full' or as_process):
337-
print ' '.join(command)
337+
print(' '.join(command))
338338

339339
# Allow the user to have the command executed in their working dir.
340340
if with_keep_cwd or self._working_dir is None:
@@ -389,11 +389,11 @@ def execute(self, command,
389389
if self.GIT_PYTHON_TRACE == 'full':
390390
cmdstr = " ".join(command)
391391
if stderr_value:
392-
print "%s -> %d; stdout: '%s'; stderr: '%s'" % (cmdstr, status, stdout_value, stderr_value)
392+
print("%s -> %d; stdout: '%s'; stderr: '%s'" % (cmdstr, status, stdout_value, stderr_value))
393393
elif stdout_value:
394-
print "%s -> %d; stdout: '%s'" % (cmdstr, status, stdout_value)
394+
print("%s -> %d; stdout: '%s'" % (cmdstr, status, stdout_value))
395395
else:
396-
print "%s -> %d" % (cmdstr, status)
396+
print("%s -> %d" % (cmdstr, status))
397397
# END handle debug printing
398398

399399
if with_exceptions and status != 0:
@@ -522,14 +522,16 @@ def make_call():
522522
raise
523523
# END handle overridden variable
524524
type(self).GIT_PYTHON_GIT_EXECUTABLE = self.git_exec_name_win
525-
call = [self.GIT_PYTHON_GIT_EXECUTABLE] + list(args)
526525

527526
try:
528527
return self.execute(make_call(), **_kwargs)
529528
finally:
530529
import warnings
531-
msg = "WARNING: Automatically switched to use git.cmd as git executable, which reduces performance by ~70%."
532-
msg += "Its recommended to put git.exe into the PATH or to set the %s environment variable to the executable's location" % self._git_exec_env_var
530+
msg = "WARNING: Automatically switched to use git.cmd as git executable"
531+
msg += ", which reduces performance by ~70%."
532+
msg += "Its recommended to put git.exe into the PATH or to "
533+
msg += "set the %s " % self._git_exec_env_var
534+
msg += "environment variable to the executable's location"
533535
warnings.warn(msg)
534536
# END print of warning
535537
# END catch first failure

‎git/config.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
configuration files"""
88

99
import re
10-
import os
1110
import ConfigParser as cp
1211
import inspect
13-
import cStringIO
1412

1513
from git.odict import OrderedDict
1614
from git.util import LockFile
@@ -188,8 +186,8 @@ def __del__(self):
188186
try:
189187
try:
190188
self.write()
191-
except IOError, e:
192-
print "Exception during destruction of GitConfigParser: %s" % str(e)
189+
except IOError as e:
190+
print("Exception during destruction of GitConfigParser: %s" % str(e))
193191
finally:
194192
self._lock._release_lock()
195193

@@ -287,7 +285,7 @@ def read(self):
287285
try:
288286
fp = open(file_object)
289287
close_fp = True
290-
except IOError, e:
288+
except IOError:
291289
continue
292290
# END fp handling
293291

‎git/diff.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import re
88
from objects.blob import Blob
99
from objects.util import mode_str_to_int
10-
from exc import GitCommandError
1110

1211
from gitdb.util import hex_to_bin
1312

@@ -106,7 +105,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
106105
diff_method = Diff._index_from_patch_format
107106
index = diff_method(self.repo, proc.stdout)
108107

109-
status = proc.wait()
108+
proc.wait()
110109
return index
111110

112111

@@ -321,7 +320,7 @@ def _index_from_raw_format(cls, repo, stream):
321320
modify, delete and add files
322321
:return: git.DiffIndex"""
323322
# handles
324-
# :100644 100644 6870991011cc8d9853a7a8a6f02061512c6a8190 37c5e30c879213e9ae83b21e9d11e55fc20c54b7 M .gitignore
323+
# :100644 100644 687099101... 37c5e30c8... M .gitignore
325324
index = DiffIndex()
326325
for line in stream:
327326
if not line.startswith(":"):

‎git/index/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Initialize the index package"""
22

3-
from base import *
4-
from typ import *
3+
from __future__ import absolute_import
4+
5+
from .base import *
6+
from .typ import *

‎git/index/base.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
git_working_dir
2525
)
2626

27-
import git.objects
2827
import git.diff as diff
2928

3029
from git.exc import (
@@ -43,13 +42,11 @@
4342
from git.objects.util import Serializable
4443

4544
from git.util import (
46-
IndexFileSHA1Writer,
4745
LazyMixin,
4846
LockedFD,
4947
join_path_native,
5048
file_contents_ro,
5149
to_native_path_linux,
52-
to_native_path
5350
)
5451

5552
from fun import (
@@ -418,9 +415,6 @@ def iter_blobs(self, predicate=lambda t: True):
418415
iterator. A default filter, the BlobFilter, allows you to yield blobs
419416
only if they match a given list of paths. """
420417
for entry in self.entries.itervalues():
421-
# TODO: is it necessary to convert the mode ? We did that when adding
422-
# it to the index, right ?
423-
mode = stat_mode_to_index_mode(entry.mode)
424418
blob = entry.to_blob(self.repo)
425419
blob.size = entry.size
426420
output = (entry.stage, blob)
@@ -602,7 +596,7 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
602596
def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,
603597
write=True):
604598
"""Add files from the working tree, specific blobs or BaseIndexEntries
605-
to the index.
599+
to the index.
606600
607601
:param items:
608602
Multiple types of items are supported, types can be mixed within one call.
@@ -630,7 +624,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
630624
must be a path relative to our repository.
631625
632626
If their sha is null ( 40*0 ), their path must exist in the file system
633-
relative to the git repository as an object will be created from
627+
relative to the git repository as an object will be created from
634628
the data at the path.
635629
The handling now very much equals the way string paths are processed, except that
636630
the mode you have set will be kept. This allows you to create symlinks
@@ -892,7 +886,8 @@ def commit(self, message, parent_commits=None, head=True, author=None, committer
892886
:return:
893887
Commit object representing the new commit"""
894888
tree = self.write_tree()
895-
return Commit.create_from_tree(self.repo, tree, message, parent_commits, head, author=author, committer=committer)
889+
return Commit.create_from_tree(self.repo, tree, message, parent_commits,
890+
head, author=author, committer=committer)
896891

897892
@classmethod
898893
def _flush_stdin_and_wait(cls, proc, ignore_stdout=False):
@@ -995,7 +990,8 @@ def handle_stderr(proc, iter_checked_out_files):
995990
if failed_files:
996991
valid_files = list(set(iter_checked_out_files) - set(failed_files))
997992
raise CheckoutError(
998-
"Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons)
993+
"Some files could not be checked out from the index due to local modifications",
994+
failed_files, valid_files, failed_reasons)
999995
# END stderr handler
1000996

1001997
if paths is None:

‎git/index/fun.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
S_IFDIR,
66
S_IFLNK,
77
S_ISLNK,
8-
S_IFDIR,
98
S_ISDIR,
109
S_IFMT,
1110
S_IFREG,
@@ -146,7 +145,7 @@ def read_cache(stream):
146145
path = read(path_size)
147146

148147
real_size = ((tell() - beginoffset + 8) & ~7)
149-
data = read((beginoffset + real_size) - tell())
148+
read((beginoffset + real_size) - tell())
150149
entry = IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size))
151150
# entry_key would be the method to use, but we safe the effort
152151
entries[(path, entry.stage)] = entry
@@ -160,8 +159,8 @@ def read_cache(stream):
160159
# 4 bytes length of chunk
161160
# repeated 0 - N times
162161
extension_data = stream.read(~0)
163-
assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(
164-
extension_data)
162+
assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size"\
163+
% len(extension_data)
165164

166165
content_sha = extension_data[-20:]
167166

@@ -265,7 +264,7 @@ def aggressive_tree_merge(odb, tree_shas):
265264
# it exists in all branches, if it was changed in both
266265
# its a conflict, otherwise we take the changed version
267266
# This should be the most common branch, so it comes first
268-
if( base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0] ) or \
267+
if(base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0]) or \
269268
(base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1]):
270269
# changed by both
271270
out_append(_tree_entry_to_baseindexentry(base, 1))

‎git/index/typ.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,5 @@ def from_base(cls, base):
172172
def from_blob(cls, blob, stage=0):
173173
""":return: Minimal entry resembling the given blob object"""
174174
time = pack(">LL", 0, 0)
175-
return IndexEntry((blob.mode, blob.binsha, stage << CE_STAGESHIFT, blob.path, time, time, 0, 0, 0, 0, blob.size))
175+
return IndexEntry((blob.mode, blob.binsha, stage << CE_STAGESHIFT, blob.path,
176+
time, time, 0, 0, 0, 0, blob.size))

‎git/objects/__init__.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
22
Import all submodules main classes into the package space
33
"""
4+
from __future__ import absolute_import
45
import inspect
5-
from base import *
6+
from .base import *
67
# Fix import dependency - add IndexObject to the util module, so that it can be
78
# imported by the submodule.base
8-
import submodule.util
9-
submodule.util.IndexObject = IndexObject
10-
submodule.util.Object = Object
11-
from submodule.base import *
12-
from submodule.root import *
9+
from .submodule import util
10+
util.IndexObject = IndexObject
11+
util.Object = Object
12+
from .submodule.base import *
13+
from .submodule.root import *
1314

1415
# must come after submodule was made available
15-
from tag import *
16-
from blob import *
17-
from commit import *
18-
from tree import *
16+
from .tag import *
17+
from .blob import *
18+
from .commit import *
19+
from .tree import *
1920

2021
__all__ = [name for name, obj in locals().items()
2122
if not (name.startswith('_') or inspect.ismodule(obj))]

‎git/objects/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from git.util import LazyMixin, join_path_native, stream_copy
77
from util import get_object_type_by_name
88
from gitdb.util import (
9-
hex_to_bin,
109
bin_to_hex,
1110
basename
1211
)

‎git/objects/commit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
276276
If True, the HEAD will be advanced to the new commit automatically.
277277
Else the HEAD will remain pointing on the previous commit. This could
278278
lead to undesired results when diffing files.
279-
:param author: The name of the author, optional. If unset, the repository
279+
:param author: The name of the author, optional. If unset, the repository
280280
configuration is used to obtain this value.
281-
:param committer: The name of the committer, optional. If unset, the
281+
:param committer: The name of the committer, optional. If unset, the
282282
repository configuration is used to obtain this value.
283283
284284
:return: Commit object representing the new commit

‎git/objects/submodule/base.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import os
3030
import sys
31-
import time
3231

3332
__all__ = ["Submodule", "UpdateProgress"]
3433

@@ -140,7 +139,8 @@ def __str__(self):
140139
return self._name
141140

142141
def __repr__(self):
143-
return "git.%s(name=%s, path=%s, url=%s, branch_path=%s)" % (type(self).__name__, self._name, self.path, self.url, self.branch_path)
142+
return "git.%s(name=%s, path=%s, url=%s, branch_path=%s)"\
143+
% (type(self).__name__, self._name, self.path, self.url, self.branch_path)
144144

145145
@classmethod
146146
def _config_parser(cls, repo, parent_commit, read_only):
@@ -236,7 +236,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
236236

237237
# assure we never put backslashes into the url, as some operating systems
238238
# like it ...
239-
if url != None:
239+
if url is not None:
240240
url = to_native_path_linux(url)
241241
# END assure url correctness
242242

@@ -449,7 +449,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
449449
# handles dry_run
450450
if mrepo is not None and mrepo.head.commit.binsha != binsha:
451451
progress.update(BEGIN | UPDWKTREE, 0, 1, prefix +
452-
"Updating working tree at %s for submodule %r to revision %s" % (self.path, self.name, hexsha))
452+
"Updating working tree at %s for submodule %r to revision %s"
453+
% (self.path, self.name, hexsha))
453454
if not dry_run:
454455
if is_detached:
455456
# NOTE: for now we force, the user is no supposed to change detached
@@ -638,7 +639,8 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
638639
mod = self.module()
639640
if mod.is_dirty(untracked_files=True):
640641
raise InvalidGitRepositoryError(
641-
"Cannot delete module at %s with any modifications, unless force is specified" % mod.working_tree_dir)
642+
"Cannot delete module at %s with any modifications, unless force is specified"
643+
% mod.working_tree_dir)
642644
# END check for dirt
643645

644646
# figure out whether we have new commits compared to the remotes

‎git/objects/submodule/root.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
186186
# in the new remote as well.
187187
if len([r for r in smr.refs if r.remote_head == sm.branch_name]) == 0:
188188
raise ValueError(
189-
"Submodule branch named %r was not available in new submodule remote at %r" % (sm.branch_name, sm.url))
189+
"Submodule branch named %r was not available in new submodule remote at %r"
190+
% (sm.branch_name, sm.url)
191+
)
190192
# END head is not detached
191193

192194
# now delete the changed one
@@ -245,7 +247,8 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
245247
# this way, it will be checked out in the next step
246248
# This will change the submodule relative to us, so
247249
# the user will be able to commit the change easily
248-
print >> sys.stderr, "WARNING: Current sha %s was not contained in the tracking branch at the new remote, setting it the the remote's tracking branch" % sm.hexsha
250+
print >> sys.stderr, "WARNING: Current sha %s was not contained in the tracking\
251+
branch at the new remote, setting it the the remote's tracking branch" % sm.hexsha
249252
sm.binsha = rref.commit.binsha
250253
# END reset binsha
251254

@@ -262,7 +265,8 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
262265
# finally, create a new tracking branch which tracks the
263266
# new remote branch
264267
progress.update(BEGIN | BRANCHCHANGE, i, len_csms, prefix +
265-
"Changing branch of submodule %r from %s to %s" % (sm.name, psm.branch_path, sm.branch_path))
268+
"Changing branch of submodule %r from %s to %s"
269+
% (sm.name, psm.branch_path, sm.branch_path))
266270
if not dry_run:
267271
smm = sm.module()
268272
smmr = smm.remotes

‎git/objects/tree.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def __div__(self, file):
187187
else:
188188
for info in self._cache:
189189
if info[2] == file: # [2] == name
190-
return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2]))
190+
return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1],
191+
join_path(self.path, info[2]))
191192
# END for each obj
192193
raise KeyError(msg % file)
193194
# END handle long paths

0 commit comments

Comments
 (0)