diff options
Diffstat (limited to 'git')
| -rw-r--r-- | git/__init__.py | 1 | ||||
| -rw-r--r-- | git/exc.py | 2 | ||||
| -rw-r--r-- | git/index/__init__.py | 2 | ||||
| -rw-r--r-- | git/objects/__init__.py | 1 | ||||
| -rw-r--r-- | git/objects/blob.py | 6 | ||||
| -rw-r--r-- | git/objects/tree.py | 8 | ||||
| -rw-r--r-- | git/refs/__init__.py | 14 | ||||
| -rw-r--r-- | git/refs/head.py | 4 | ||||
| -rw-r--r-- | git/refs/symbolic.py | 1 | ||||
| -rw-r--r-- | git/repo/__init__.py | 1 | ||||
| -rw-r--r-- | git/repo/base.py | 15 | ||||
| -rw-r--r-- | git/test/lib/__init__.py | 1 | ||||
| -rw-r--r-- | git/test/performance/test_utils.py | 190 | ||||
| -rw-r--r-- | git/util.py | 13 | 
14 files changed, 36 insertions, 223 deletions
| diff --git a/git/__init__.py b/git/__init__.py index 5580c9a6..5630b91d 100644 --- a/git/__init__.py +++ b/git/__init__.py @@ -3,6 +3,7 @@  #  # This module is part of GitPython and is released under  # the BSD License: http://www.opensource.org/licenses/bsd-license.php +# flake8: noqa  import os  import sys @@ -5,7 +5,7 @@  # the BSD License: http://www.opensource.org/licenses/bsd-license.php  """ Module containing all exceptions thrown througout the git package, """ -from gitdb.exc import * +from gitdb.exc import *     # NOQA  class InvalidGitRepositoryError(Exception): diff --git a/git/index/__init__.py b/git/index/__init__.py index c5080d2e..2516f01f 100644 --- a/git/index/__init__.py +++ b/git/index/__init__.py @@ -1,5 +1,5 @@  """Initialize the index package""" - +# flake8: noqa  from __future__ import absolute_import  from .base import * diff --git a/git/objects/__init__.py b/git/objects/__init__.py index 1fe881f3..70fc52cb 100644 --- a/git/objects/__init__.py +++ b/git/objects/__init__.py @@ -1,6 +1,7 @@  """  Import all submodules main classes into the package space  """ +# flake8: noqa  from __future__ import absolute_import  import inspect  from .base import * diff --git a/git/objects/blob.py b/git/objects/blob.py index 5f00a1ff..b05e5b84 100644 --- a/git/objects/blob.py +++ b/git/objects/blob.py @@ -17,9 +17,9 @@ class Blob(base.IndexObject):      type = "blob"      # valid blob modes -    executable_mode = 0100755 -    file_mode = 0100644 -    link_mode = 0120000 +    executable_mode = 0o100755 +    file_mode = 0o100644 +    link_mode = 0o120000      __slots__ = tuple() diff --git a/git/objects/tree.py b/git/objects/tree.py index beb5f1fd..c77e6056 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -119,10 +119,10 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):      __slots__ = "_cache"      # actual integer ids for comparison -    commit_id = 016     # equals stat.S_IFDIR | stat.S_IFLNK - a directory link -    blob_id = 010 -    symlink_id = 012 -    tree_id = 004 +    commit_id = 0o16     # equals stat.S_IFDIR | stat.S_IFLNK - a directory link +    blob_id = 0o10 +    symlink_id = 0o12 +    tree_id = 0o04      _map_id_to_type = {          commit_id: Submodule, diff --git a/git/refs/__init__.py b/git/refs/__init__.py index 0281121a..ded8b1f7 100644 --- a/git/refs/__init__.py +++ b/git/refs/__init__.py @@ -1,4 +1,4 @@ - +# flake8: noqa  from __future__ import absolute_import  # import all modules in order, fix the names they require  from .symbolic import * @@ -7,16 +7,4 @@ from .head import *  from .tag import *  from .remote import * -# name fixes -from . import head -head.RemoteReference = RemoteReference -del(head) - - -from . import symbolic -for item in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference): -    setattr(symbolic, item.__name__, item) -del(symbolic) - -  from .log import * diff --git a/git/refs/head.py b/git/refs/head.py index acdd37d6..25c994a3 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -81,7 +81,7 @@ class HEAD(SymbolicReference):          try:              self.repo.git.reset(mode, commit, add_arg, paths, **kwargs) -        except GitCommandError, e: +        except GitCommandError as e:              # git nowadays may use 1 as status to indicate there are still unstaged              # modifications after the reset              if e.status != 1: @@ -134,6 +134,7 @@ class Head(Reference):          :param remote_reference: The remote reference to track or None to untrack              any references          :return: self""" +        from .remote import RemoteReference          if remote_reference is not None and not isinstance(remote_reference, RemoteReference):              raise ValueError("Incorrect parameter type: %r" % remote_reference)          # END handle type @@ -156,6 +157,7 @@ class Head(Reference):          """          :return: The remote_reference we are tracking, or None if we are              not a tracking branch""" +        from .remote import RemoteReference          reader = self.config_reader()          if reader.has_option(self.k_config_remote) and reader.has_option(self.k_config_remote_ref):              ref = Head(self.repo, Head.to_full_path(reader.get_value(self.k_config_remote_ref))) diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 2fa58d12..e0f5531a 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -625,6 +625,7 @@ class SymbolicReference(object):          # Names like HEAD are inserted after the refs module is imported - we have an import dependency          # cycle and don't want to import these names in-function +        from . import HEAD, Head, RemoteReference, TagReference, Reference          for ref_type in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference):              try:                  instance = ref_type(repo, path) diff --git a/git/repo/__init__.py b/git/repo/__init__.py index 3ae97e66..5619aa69 100644 --- a/git/repo/__init__.py +++ b/git/repo/__init__.py @@ -1,3 +1,4 @@  """Initialize the Repo package""" +# flake8: noqa  from __future__ import absolute_import  from .base import * diff --git a/git/repo/base.py b/git/repo/base.py index d1af26e2..dcf98152 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -6,13 +6,22 @@  from git.exc import InvalidGitRepositoryError, NoSuchPathError  from git.cmd import Git +from git.refs import ( +    HEAD, +    Head, +    Reference, +    TagReference, +) +from git.objects import ( +    Submodule, +    RootModule, +    Commit +)  from git.util import (      Actor,      finalize_process  ) -from git.refs import *  from git.index import IndexFile -from git.objects import *  from git.config import GitConfigParser  from git.remote import (      Remote, @@ -659,7 +668,7 @@ class Repo(object):          :return: ``git.Repo`` (the newly created repo)"""          if mkdir and path and not os.path.exists(path): -            os.makedirs(path, 0755) +            os.makedirs(path, 0o755)          # git command automatically chdir into the directory          git = Git(path) diff --git a/git/test/lib/__init__.py b/git/test/lib/__init__.py index 033a1104..87e26752 100644 --- a/git/test/lib/__init__.py +++ b/git/test/lib/__init__.py @@ -4,6 +4,7 @@  # This module is part of GitPython and is released under  # the BSD License: http://www.opensource.org/licenses/bsd-license.php +# flake8: noqa  import inspect  from .asserts import *  from .helper import * diff --git a/git/test/performance/test_utils.py b/git/test/performance/test_utils.py deleted file mode 100644 index af8e8047..00000000 --- a/git/test/performance/test_utils.py +++ /dev/null @@ -1,190 +0,0 @@ -"""Performance of utilities""" -from __future__ import print_function -from time import time -import sys - -from .lib import ( -    TestBigRepoR -) - - -class TestUtilPerformance(TestBigRepoR): - -    def test_access(self): -        # compare dict vs. slot access -        class Slotty(object): -            __slots__ = "attr" - -            def __init__(self): -                self.attr = 1 - -        class Dicty(object): - -            def __init__(self): -                self.attr = 1 - -        class BigSlotty(object): -            __slots__ = ('attr', ) + tuple('abcdefghijk') - -            def __init__(self): -                for attr in self.__slots__: -                    setattr(self, attr, 1) - -        class BigDicty(object): - -            def __init__(self): -                for attr in BigSlotty.__slots__: -                    setattr(self, attr, 1) - -        ni = 1000000 -        for cls in (Slotty, Dicty, BigSlotty, BigDicty): -            cli = cls() -            st = time() -            for i in xrange(ni): -                cli.attr -            # END for each access -            elapsed = time() - st -            print("Accessed %s.attr %i times in %s s ( %f acc / s)" -                  % (cls.__name__, ni, elapsed, ni / elapsed), file=sys.stderr) -        # END for each class type - -        # check num of sequence-acceses -        for cls in (list, tuple): -            x = 10 -            st = time() -            s = cls(range(x)) -            for i in xrange(ni): -                s[0] -                s[1] -                s[2] -            # END for -            elapsed = time() - st -            na = ni * 3 -            print("Accessed %s[x] %i times in %s s ( %f acc / s)" -                  % (cls.__name__, na, elapsed, na / elapsed), file=sys.stderr) -        # END for each sequence - -    def test_instantiation(self): -        ni = 100000 -        max_num_items = 4 -        for mni in range(max_num_items + 1): -            for cls in (tuple, list): -                st = time() -                for i in xrange(ni): -                    if mni == 0: -                        cls() -                    elif mni == 1: -                        cls((1,)) -                    elif mni == 2: -                        cls((1, 2)) -                    elif mni == 3: -                        cls((1, 2, 3)) -                    elif mni == 4: -                        cls((1, 2, 3, 4)) -                    else: -                        cls(x for x in xrange(mni)) -                    # END handle empty cls -                # END for each item -                elapsed = time() - st -                print("Created %i %ss of size %i in %f s ( %f inst / s)" -                      % (ni, cls.__name__, mni, elapsed, ni / elapsed), file=sys.stderr) -            # END for each type -        # END for each item count - -        # tuple and tuple direct -        st = time() -        for i in xrange(ni): -            (1, 2, 3, 4) -        # END for each item -        elapsed = time() - st -        print("Created %i tuples (1,2,3,4) in %f s ( %f tuples / s)" -              % (ni, elapsed, ni / elapsed), file=sys.stderr) - -        st = time() -        for i in xrange(ni): -            tuple((1, 2, 3, 4)) -        # END for each item -        elapsed = time() - st -        print("Created %i tuples tuple((1,2,3,4)) in %f s ( %f tuples / s)" -              % (ni, elapsed, ni / elapsed), file=sys.stderr) - -    def test_unpacking_vs_indexing(self): -        ni = 1000000 -        list_items = [1, 2, 3, 4] -        tuple_items = (1, 2, 3, 4) - -        for sequence in (list_items, tuple_items): -            st = time() -            for i in xrange(ni): -                one, two, three, four = sequence -            # END for eac iteration -            elapsed = time() - st -            print("Unpacked %i %ss of size %i in %f s ( %f acc / s)" -                  % (ni, type(sequence).__name__, len(sequence), elapsed, ni / elapsed), file=sys.stderr) - -            st = time() -            for i in xrange(ni): -                one, two, three, four = sequence[0], sequence[1], sequence[2], sequence[3] -            # END for eac iteration -            elapsed = time() - st -            print("Unpacked %i %ss of size %i individually in %f s ( %f acc / s)" -                  % (ni, type(sequence).__name__, len(sequence), elapsed, ni / elapsed), file=sys.stderr) - -            st = time() -            for i in xrange(ni): -                one, two = sequence[0], sequence[1] -            # END for eac iteration -            elapsed = time() - st -            print("Unpacked %i %ss of size %i individually (2 of 4) in %f s ( %f acc / s)" -                  % (ni, type(sequence).__name__, len(sequence), elapsed, ni / elapsed), file=sys.stderr) -        # END for each sequence - -    def test_large_list_vs_iteration(self): -        # what costs more: alloc/realloc of lists, or the cpu strain of iterators ? -        def slow_iter(ni): -            for i in xrange(ni): -                yield i -        # END slow iter - be closer to the real world - -        # alloc doesn't play a role here it seems -        for ni in (500, 1000, 10000, 20000, 40000): -            st = time() -            for i in list(xrange(ni)): -                i -            # END for each item -            elapsed = time() - st -            print("Iterated %i items from list in %f s ( %f acc / s)" -                  % (ni, elapsed, ni / elapsed), file=sys.stderr) - -            st = time() -            for i in slow_iter(ni): -                i -            # END for each item -            elapsed = time() - st -            print("Iterated %i items from iterator in %f s ( %f acc / s)" -                  % (ni, elapsed, ni / elapsed), file=sys.stderr) -        # END for each number of iterations - -    def test_type_vs_inst_class(self): -        class NewType(object): -            pass - -        # lets see which way is faster -        inst = NewType() - -        ni = 1000000 -        st = time() -        for i in xrange(ni): -            inst.__class__() -        # END for each item -        elapsed = time() - st -        print("Created %i items using inst.__class__ in %f s ( %f items / s)" -              % (ni, elapsed, ni / elapsed), file=sys.stderr) - -        st = time() -        for i in xrange(ni): -            type(inst)() -        # END for each item -        elapsed = time() - st -        print("Created %i items using type(inst)() in %f s ( %f items / s)" -              % (ni, elapsed, ni / elapsed), file=sys.stderr) diff --git a/git/util.py b/git/util.py index c29ed70b..fecd9fa2 100644 --- a/git/util.py +++ b/git/util.py @@ -19,7 +19,7 @@ from exc import GitCommandError  # Most of these are unused here, but are for use by git-python modules so these  # don't see gitdb all the time. Flake of course doesn't like it. -from gitdb.util import ( +from gitdb.util import (  # NOQA      make_sha,      LockedFD,      file_contents_ro, @@ -84,14 +84,13 @@ def join_path(a, *p):      return path -def to_native_path_windows(path): -    return path.replace('/', '\\') - +if sys.platform.startswith('win'): +    def to_native_path_windows(path): +        return path.replace('/', '\\') -def to_native_path_linux(path): -    return path.replace('\\', '/') +    def to_native_path_linux(path): +        return path.replace('\\', '/') -if sys.platform.startswith('win'):      to_native_path = to_native_path_windows  else:      # no need for any work on linux | 
