diff options
author | Antoine Musso <hashar@free.fr> | 2014-11-16 21:09:47 +0100 |
---|---|---|
committer | Antoine Musso <hashar@free.fr> | 2014-11-16 21:09:47 +0100 |
commit | c8e70749887370a99adeda972cc3503397b5f9a7 (patch) | |
tree | 38e1241fd6d756f783b6b56dc6628ac3ca41ed4f /git/objects | |
parent | bed3b0989730cdc3f513884325f1447eb378aaee (diff) | |
download | gitpython-c8e70749887370a99adeda972cc3503397b5f9a7.tar.gz |
pep8 linting (trailing whitespace)
W291 trailing whitespace
Diffstat (limited to 'git/objects')
-rw-r--r-- | git/objects/__init__.py | 2 | ||||
-rw-r--r-- | git/objects/base.py | 14 | ||||
-rw-r--r-- | git/objects/commit.py | 66 | ||||
-rw-r--r-- | git/objects/fun.py | 18 | ||||
-rw-r--r-- | git/objects/submodule/base.py | 84 | ||||
-rw-r--r-- | git/objects/submodule/root.py | 60 | ||||
-rw-r--r-- | git/objects/submodule/util.py | 8 | ||||
-rw-r--r-- | git/objects/tag.py | 8 | ||||
-rw-r--r-- | git/objects/tree.py | 34 | ||||
-rw-r--r-- | git/objects/util.py | 34 |
10 files changed, 164 insertions, 164 deletions
diff --git a/git/objects/__init__.py b/git/objects/__init__.py index 5708ac0b..088dd699 100644 --- a/git/objects/__init__.py +++ b/git/objects/__init__.py @@ -3,7 +3,7 @@ Import all submodules main classes into the package space """ import inspect from base import * -# Fix import dependency - add IndexObject to the util module, so that it can be +# Fix import dependency - add IndexObject to the util module, so that it can be # imported by the submodule.base import submodule.util submodule.util.IndexObject = IndexObject diff --git a/git/objects/base.py b/git/objects/base.py index d7c92d8a..0fcd25d6 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -29,7 +29,7 @@ class Object(LazyMixin): type = None # to be set by subclass def __init__(self, repo, binsha): - """Initialize an object by identifying it by its binary sha. + """Initialize an object by identifying it by its binary sha. All keyword arguments will be set on demand if None. :param repo: repository this object is located in @@ -43,8 +43,8 @@ class Object(LazyMixin): @classmethod def new(cls, repo, id): """ - :return: New Object instance of a type appropriate to the object type behind - id. The id of the newly created object will be a binsha even though + :return: New Object instance of a type appropriate to the object type behind + id. The id of the newly created object will be a binsha even though the input id may have been a Reference or Rev-Spec :param id: reference, rev-spec, or hexsha @@ -56,7 +56,7 @@ class Object(LazyMixin): @classmethod def new_from_sha(cls, repo, sha1): """ - :return: new object instance of a type appropriate to represent the given + :return: new object instance of a type appropriate to represent the given binary sha1 :param sha1: 20 byte binary sha1""" if sha1 == cls.NULL_BIN_SHA: @@ -66,7 +66,7 @@ class Object(LazyMixin): oinfo = repo.odb.info(sha1) inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha) inst.size = oinfo.size - return inst + return inst def _set_cache_(self, attr): """Retrieve object information""" @@ -150,7 +150,7 @@ class IndexObject(Object): def __hash__(self): """:return: - Hash of our path as index items are uniquely identifyable by path, not + Hash of our path as index items are uniquely identifyable by path, not by their data !""" return hash(self.path) @@ -171,7 +171,7 @@ class IndexObject(Object): def abspath(self): """ :return: - Absolute path to this index object in the file system ( as opposed to the + Absolute path to this index object in the file system ( as opposed to the .path field which is a path relative to the git repository ). The returned path will be native to the system and contains '\' on windows. """ diff --git a/git/objects/commit.py b/git/objects/commit.py index 14cf5bbb..d778f2d7 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -27,7 +27,7 @@ from util import ( parse_actor_and_date ) from time import ( - time, + time, altzone ) import os @@ -40,7 +40,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): """Wraps a git Commit object. - This class will act lazily on some of its attributes and will query the + This class will act lazily on some of its attributes and will query the value on demand only if it involves calling the git binary.""" # ENVIRONMENT VARIABLES @@ -54,7 +54,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # INVARIANTS default_encoding = "UTF-8" - # object configuration + # object configuration type = "commit" __slots__ = ("tree", "author", "authored_date", "author_tz_offset", @@ -68,21 +68,21 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): """Instantiate a new Commit. All keyword arguments taking None as default will be implicitly set on first query. :param binsha: 20 byte sha1 - :param parents: tuple( Commit, ... ) + :param parents: tuple( Commit, ... ) is a tuple of commit ids or actual Commits :param tree: Tree Tree object :param author: Actor is the author string ( will be implicitly converted into an Actor object ) :param authored_date: int_seconds_since_epoch - is the authored DateTime - use time.gmtime() to convert it into a + is the authored DateTime - use time.gmtime() to convert it into a different format :param author_tz_offset: int_seconds_west_of_utc is the timezone that the authored_date is in :param committer: Actor is the committer string :param committed_date: int_seconds_since_epoch - is the committed DateTime - use time.gmtime() to convert it into a + is the committed DateTime - use time.gmtime() to convert it into a different format :param committer_tz_offset: int_seconds_west_of_utc is the timezone that the authored_date is in @@ -91,12 +91,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): :param encoding: string encoding of the message, defaults to UTF-8 :param parents: - List or tuple of Commit objects which are our parent(s) in the commit + List or tuple of Commit objects which are our parent(s) in the commit dependency graph :return: git.Commit - :note: Timezone information is in the same format and in the same sign - as what time.altzone returns. The sign is inverted compared to git's + :note: Timezone information is in the same format and in the same sign + as what time.altzone returns. The sign is inverted compared to git's UTC timezone.""" super(Commit, self).__init__(repo, binsha) if tree is not None: @@ -145,7 +145,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): """Count the number of commits reachable from this commit :param paths: - is an optinal path or a list of paths restricting the return value + is an optinal path or a list of paths restricting the return value to commits actually containing the paths :param kwargs: @@ -174,7 +174,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): :param repo: is the Repo :param rev: revision specifier, see git-rev-parse for viable options :param paths: - is an optinal path or list of paths, if set only Commits that include the path + is an optinal path or list of paths, if set only Commits that include the path or paths will be considered :param kwargs: optional keyword arguments to git rev-list where @@ -197,13 +197,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): """Iterate _all_ parents of this commit. :param paths: - Optional path or list of paths limiting the Commits to those that + Optional path or list of paths limiting the Commits to those that contain at least one of the paths :param kwargs: All arguments allowed by git-rev-list :return: Iterator yielding Commit objects which are parents of self """ # skip ourselves skip = kwargs.get("skip", 1) - if skip == 0: # skip ourselves + if skip == 0: # skip ourselves skip = 1 kwargs['skip'] = skip @@ -211,7 +211,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): @property def stats(self): - """Create a git stat from changes between this commit and its first parent + """Create a git stat from changes between this commit and its first parent or from all changes done if this is the very first commit. :return: git.Stats""" @@ -261,27 +261,27 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False): """Commit the given tree, creating a commit object. - :param repo: Repo object the commit should be part of - :param tree: Tree object or hex or bin sha + :param repo: Repo object the commit should be part of + :param tree: Tree object or hex or bin sha the tree of the new commit :param message: Commit message. It may be an empty string if no message is provided. It will be converted to a string in any case. :param parent_commits: Optional Commit objects to use as parents for the new commit. - If empty list, the commit will have no parents at all and become + If empty list, the commit will have no parents at all and become a root commit. - If None , the current head commit will be the parent of the + If None , the current head commit will be the parent of the new commit object :param head: If True, the HEAD will be advanced to the new commit automatically. - Else the HEAD will remain pointing on the previous commit. This could + Else the HEAD will remain pointing on the previous commit. This could lead to undesired results when diffing files. :return: Commit object representing the new commit :note: Additional information about the committer and Author are taken from the - environment or from the git configuration, see git-commit-tree for + environment or from the git configuration, see git-commit-tree for more information""" parents = parent_commits if parent_commits is None: @@ -293,9 +293,9 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # END handle parent commits # END if parent commits are unset - # retrieve all additional information, create a commit object, and + # retrieve all additional information, create a commit object, and # serialize it - # Generally: + # Generally: # * Environment variables override configuration values # * Sensible defaults are set according to the git documentation @@ -318,7 +318,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # END set author time committer_date_str = env.get(cls.env_committer_date, '') - if committer_date_str: + if committer_date_str: committer_time, committer_offset = parse_date(committer_date_str) else: committer_time, committer_offset = unix_time, offset @@ -335,8 +335,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # END tree conversion # CREATE NEW COMMIT - new_commit = cls(repo, cls.NULL_BIN_SHA, tree, - author, author_time, author_offset, + new_commit = cls(repo, cls.NULL_BIN_SHA, tree, + author, author_time, author_offset, committer, committer_time, committer_offset, message, parent_commits, conf_encoding) @@ -350,7 +350,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): if head: # need late import here, importing git at the very beginning throws - # as well ... + # as well ... import git.refs try: repo.head.set_commit(new_commit, logmsg="commit: %s" % message) @@ -361,7 +361,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message) repo.head.set_reference(master, logmsg='commit: Switching to %s' % master) # END handle empty repositories - # END advance head handling + # END advance head handling return new_commit @@ -381,8 +381,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): c = self.committer fmt = "%s %s <%s> %s %s\n" - write(fmt % ("author", aname, a.email, - self.authored_date, + write(fmt % ("author", aname, a.email, + self.authored_date, altz_to_utctz_str(self.author_tz_offset))) # encode committer @@ -390,7 +390,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): if isinstance(aname, unicode): aname = aname.encode(self.encoding) # END handle unicode in name - write(fmt % ("committer", aname, c.email, + write(fmt % ("committer", aname, c.email, self.committed_date, altz_to_utctz_str(self.committer_tz_offset))) @@ -468,14 +468,14 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # decode the authors name try: - self.author.name = self.author.name.decode(self.encoding) + self.author.name = self.author.name.decode(self.encoding) except UnicodeDecodeError: print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding) # END handle author's encoding # decode committer name try: - self.committer.name = self.committer.name.decode(self.encoding) + self.committer.name = self.committer.name.decode(self.encoding) except UnicodeDecodeError: print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (self.committer.name, self.encoding) # END handle author's encoding @@ -487,7 +487,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): self.message = self.message.decode(self.encoding) except UnicodeDecodeError: print >> sys.stderr, "Failed to decode message '%s' using encoding %s" % (self.message, self.encoding) - # END exception handling + # END exception handling return self #} END serializable implementation diff --git a/git/objects/fun.py b/git/objects/fun.py index 0bb14376..21b89fca 100644 --- a/git/objects/fun.py +++ b/git/objects/fun.py @@ -24,13 +24,13 @@ def tree_to_stream(entries, write): # END save a byte # here it comes: if the name is actually unicode, the replacement below - # will not work as the binsha is not part of the ascii unicode encoding - + # will not work as the binsha is not part of the ascii unicode encoding - # hence we must convert to an utf8 string for it to work properly. # According to my tests, this is exactly what git does, that is it just # takes the input literally, which appears to be utf8 on linux. if isinstance(name, unicode): name = name.encode("utf8") - write("%s %s\0%s" % (mode_str, name, binsha)) + write("%s %s\0%s" % (mode_str, name, binsha)) # END for each item @@ -89,7 +89,7 @@ def tree_entries_from_data(data): def _find_by_name(tree_data, name, is_dir, start_at): """return data entry matching the given name and tree mode or None. - Before the item is returned, the respective data item is set + Before the item is returned, the respective data item is set None in the tree_data list to mark it done""" try: item = tree_data[start_at] @@ -117,17 +117,17 @@ def _to_full_path(item, path_prefix): def traverse_trees_recursive(odb, tree_shas, path_prefix): """ - :return: list with entries according to the given binary tree-shas. + :return: list with entries according to the given binary tree-shas. The result is encoded in a list - of n tuple|None per blob/commit, (n == len(tree_shas)), where + of n tuple|None per blob/commit, (n == len(tree_shas)), where * [0] == 20 byte sha * [1] == mode as int * [2] == path relative to working tree root - The entry tuple is None if the respective blob/commit did not + The entry tuple is None if the respective blob/commit did not exist in the given tree. - :param tree_shas: iterable of shas pointing to trees. All trees must + :param tree_shas: iterable of shas pointing to trees. All trees must be on the same level. A tree-sha may be None in which case None - :param path_prefix: a prefix to be added to the returned paths on this level, + :param path_prefix: a prefix to be added to the returned paths on this level, set it '' for the first iteration :note: The ordering of the returned items will be partially lost""" trees_data = list() @@ -158,7 +158,7 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix): is_dir = S_ISDIR(mode) # type mode bits # find this item in all other tree data items - # wrap around, but stop one before our current index, hence + # wrap around, but stop one before our current index, hence # ti+nt, not ti+1+nt for tio in range(ti + 1, ti + nt): tio = tio % nt diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 770dcffd..f26cac91 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -1,17 +1,17 @@ import util from util import ( mkhead, - sm_name, - sm_section, - unbare_repo, + sm_name, + sm_section, + unbare_repo, SubmoduleConfigParser, find_first_remote_branch ) from git.objects.util import Traversable from StringIO import StringIO # need a dict to set bloody .name field from git.util import ( - Iterable, - join_path_native, + Iterable, + join_path_native, to_native_path_linux, RemoteProgress, rmtree @@ -19,7 +19,7 @@ from git.util import ( from git.config import SectionConstraint from git.exc import ( - InvalidGitRepositoryError, + InvalidGitRepositoryError, NoSuchPathError ) @@ -35,7 +35,7 @@ __all__ = ["Submodule", "UpdateProgress"] class UpdateProgress(RemoteProgress): - """Class providing detailed progress information to the caller who should + """Class providing detailed progress information to the caller who should derive from it and implement the ``update(...)`` message""" CLONE, FETCH, UPDWKTREE = [1 << x for x in range(RemoteProgress._num_op_codes, RemoteProgress._num_op_codes + 3)] _num_op_codes = RemoteProgress._num_op_codes + 3 @@ -50,14 +50,14 @@ FETCH = UpdateProgress.FETCH UPDWKTREE = UpdateProgress.UPDWKTREE -# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import +# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import # mechanism which cause plenty of trouble of the only reason for packages and # modules is refactoring - subpackages shoudn't depend on parent packages class Submodule(util.IndexObject, Iterable, Traversable): """Implements access to a git submodule. They are special in that their sha represents a commit in the submodule's repository which is to be checked out - at the path of this instance. + at the path of this instance. The submodule type does not have a string type associated with it, as it exists solely as a marker in the tree and index. @@ -76,7 +76,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): _cache_attrs = ('path', '_url', '_branch_path') def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=None, url=None, branch_path=None): - """Initialize this instance with its attributes. We only document the ones + """Initialize this instance with its attributes. We only document the ones that differ from ``IndexObject`` :param repo: Our parent repository @@ -140,13 +140,13 @@ class Submodule(util.IndexObject, Iterable, Traversable): return self._name def __repr__(self): - return "git.%s(name=%s, path=%s, url=%s, branch_path=%s)" % (type(self).__name__, self._name, self.path, self.url, self.branch_path) + return "git.%s(name=%s, path=%s, url=%s, branch_path=%s)" % (type(self).__name__, self._name, self.path, self.url, self.branch_path) @classmethod def _config_parser(cls, repo, parent_commit, read_only): """:return: Config Parser constrained to our submodule in read or write mode :raise IOError: If the .gitmodules file cannot be found, either locally or in the repository - at the given parent commit. Otherwise the exception would be delayed until the first + at the given parent commit. Otherwise the exception would be delayed until the first access of the config parser""" parent_matches_head = repo.head.commit == parent_commit if not repo.bare and parent_matches_head: @@ -204,7 +204,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): :param repo: Repository instance which should receive the submodule :param name: The name/identifier for the submodule - :param path: repository-relative or absolute path at which the submodule + :param path: repository-relative or absolute path at which the submodule should be located It will be created as required during the repository initialization. :param url: git-clone compatible URL, see git-clone reference for more information @@ -219,7 +219,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): The result you get in these situation is somewhat fuzzy, and it is recommended to specify at least 'master' here. Examples are 'master' or 'feature/new' - :param no_checkout: if True, and if the repository has to be cloned manually, + :param no_checkout: if True, and if the repository has to be cloned manually, no checkout will be performed :return: The newly created submodule instance :note: works atomically, such that no change will be done if the repository @@ -233,8 +233,8 @@ class Submodule(util.IndexObject, Iterable, Traversable): path = path[:-1] # END handle trailing slash - # assure we never put backslashes into the url, as some operating systems - # like it ... + # assure we never put backslashes into the url, as some operating systems + # like it ... if url != None: url = to_native_path_linux(url) #END assure url correctness @@ -306,7 +306,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): return sm - def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, + def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False): """Update the repository of this submodule to point to the checkout we point at with the binsha of this instance. @@ -317,7 +317,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): :param to_latest_revision: if True, the submodule's sha will be ignored during checkout. Instead, the remote will be fetched, and the local tracking branch updated. This only works if we have a local tracking branch, which is the case - if the remote repository had a master branch, or of the 'branch' option + if the remote repository had a master branch, or of the 'branch' option was specified for this submodule and the branch existed remotely :param progress: UpdateProgress instance or None of no progress should be shown :param dry_run: if True, the operation will only be simulated, but not performed. @@ -405,12 +405,12 @@ class Submodule(util.IndexObject, Iterable, Traversable): mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch) mrepo.head.ref.set_tracking_branch(remote_branch) except IndexError: - print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path + print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path #END handle tracking branch # NOTE: Have to write the repo config file as well, otherwise # the default implementation will be offended and not update the repository - # Maybe this is a good way to assure it doesn't get into our way, but + # Maybe this is a good way to assure it doesn't get into our way, but # we want to stay backwards compatible too ... . Its so redundant ! self.repo.config_writer().set_value(sm_section(self.name), 'url', self.url) #END handle dry_run @@ -434,7 +434,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): binsha = rcommit.binsha hexsha = rcommit.hexsha else: - print >> sys.stderr, "%s a tracking branch was not set for local branch '%s'" % (msg_base, mrepo.head.ref) + print >> sys.stderr, "%s a tracking branch was not set for local branch '%s'" % (msg_base, mrepo.head.ref) # END handle remote ref else: print >> sys.stderr, "%s there was no local tracking branch" % msg_base @@ -448,7 +448,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): if not dry_run: if is_detached: # NOTE: for now we force, the user is no supposed to change detached - # submodules anyway. Maybe at some point this becomes an option, to + # submodules anyway. Maybe at some point this becomes an option, to # properly handle user modifications - see below for future options # regarding rebase and merge. mrepo.git.checkout(hexsha, force=True) @@ -485,10 +485,10 @@ class Submodule(util.IndexObject, Iterable, Traversable): repository-relative path. Intermediate directories will be created accordingly. If the path already exists, it must be empty. Trailling (back)slashes are removed automatically - :param configuration: if True, the configuration will be adjusted to let + :param configuration: if True, the configuration will be adjusted to let the submodule point to the given path. :param module: if True, the repository managed by this submodule - will be moved, not the configuration. This will effectively + will be moved, not the configuration. This will effectively leave your repository in an inconsistent state unless the configuration and index already point to the target location. :return: self @@ -549,7 +549,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): renamed_module = True #END move physical module - # rename the index entry - have to manipulate the index directly as + # rename the index entry - have to manipulate the index directly as # git-mv cannot be used on submodules ... yeah try: if configuration: @@ -583,20 +583,20 @@ class Submodule(util.IndexObject, Iterable, Traversable): """Remove this submodule from the repository. This will remove our entry from the .gitmodules file and the entry in the .git/config file. - :param module: If True, the module we point to will be deleted - as well. If the module is currently on a commit which is not part - of any branch in the remote, if the currently checked out branch + :param module: If True, the module we point to will be deleted + as well. If the module is currently on a commit which is not part + of any branch in the remote, if the currently checked out branch working tree, or untracked files, is ahead of its tracking branch, if you have modifications in the - In case the removal of the repository fails for these reasons, the + In case the removal of the repository fails for these reasons, the submodule status will not have been altered. If this submodule has child-modules on its own, these will be deleted prior to touching the own module. - :param force: Enforces the deletion of the module even though it contains + :param force: Enforces the deletion of the module even though it contains modifications. This basically enforces a brute-force file system based deletion. - :param configuration: if True, the submodule is deleted from the configuration, - otherwise it isn't. Although this should be enabled most of the times, + :param configuration: if True, the submodule is deleted from the configuration, + otherwise it isn't. Although this should be enabled most of the times, this flag enables you to safely delete the repository of your submodule. :param dry_run: if True, we will not actually do anything, but throw the errors we would usually throw @@ -636,7 +636,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): # END check for dirt # figure out whether we have new commits compared to the remotes - # NOTE: If the user pulled all the time, the remote heads might + # NOTE: If the user pulled all the time, the remote heads might # not have been updated, so commits coming from the remote look # as if they come from us. But we stay strictly read-only and # don't fetch beforhand. @@ -650,7 +650,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): if num_branches_with_new_commits == len(rrefs): raise InvalidGitRepositoryError("Cannot delete module at %s as there are new commits" % mod.working_tree_dir) # END handle new commits - # have to manually delete references as python's scoping is + # have to manually delete references as python's scoping is # not existing, they could keep handles open ( on windows this is a problem ) if len(rrefs): del(rref) @@ -686,7 +686,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): #END delete entry index.write() - # now git config - need the config intact, otherwise we can't query + # now git config - need the config intact, otherwise we can't query # inforamtion anymore self.repo.config_writer().remove_section(sm_section(self.name)) self.config_writer().remove_section() @@ -698,7 +698,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): return self def set_parent_commit(self, commit, check=True): - """Set this instance to use the given commit whose tree is supposed to + """Set this instance to use the given commit whose tree is supposed to contain the .gitmodules blob. :param commit: Commit'ish reference pointing at the root_tree @@ -721,7 +721,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): parser = self._config_parser(self.repo, self._parent_commit, read_only=True) if not parser.has_section(sm_section(self.name)): self._parent_commit = prev_pc - raise ValueError("Submodule at path %r did not exist in parent commit %s" % (self.path, commit)) + raise ValueError("Submodule at path %r did not exist in parent commit %s" % (self.path, commit)) # END handle submodule did not exist # END handle checking mode @@ -741,8 +741,8 @@ class Submodule(util.IndexObject, Iterable, Traversable): defaults to the index of the Submodule's parent repository. :param write: if True, the index will be written each time a configuration value changes. - :note: the parameters allow for a more efficient writing of the index, - as you can pass in a modified index on your own, prevent automatic writing, + :note: the parameters allow for a more efficient writing of the index, + as you can pass in a modified index on your own, prevent automatic writing, and write yourself once the whole operation is complete :raise ValueError: if trying to get a writer on a parent_commit which does not match the current head commit @@ -760,10 +760,10 @@ class Submodule(util.IndexObject, Iterable, Traversable): @unbare_repo def module(self): """:return: Repo instance initialized from the repository at our submodule path - :raise InvalidGitRepositoryError: if a repository was not available. This could + :raise InvalidGitRepositoryError: if a repository was not available. This could also mean that it was not yet initialized""" # late import to workaround circular dependencies - module_path = self.abspath + module_path = self.abspath try: repo = git.Repo(module_path) if repo != self.repo: @@ -847,7 +847,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): @property def name(self): - """:return: The name of this submodule. It is used to identify it within the + """:return: The name of this submodule. It is used to identify it within the .gitmodules file. :note: by default, the name is the path at which to find the submodule, but in git-python it should be a unique identifier similar to the identifiers diff --git a/git/objects/submodule/root.py b/git/objects/submodule/root.py index b8cc904c..581c5a7c 100644 --- a/git/objects/submodule/root.py +++ b/git/objects/submodule/root.py @@ -38,11 +38,11 @@ class RootModule(Submodule): def __init__(self, repo): # repo, binsha, mode=None, path=None, name = None, parent_commit=None, url=None, ref=None) super(RootModule, self).__init__( - repo, - binsha=self.NULL_BIN_SHA, - mode=self.k_default_mode, - path='', - name=self.k_root_name, + repo, + binsha=self.NULL_BIN_SHA, + mode=self.k_default_mode, + path='', + name=self.k_root_name, parent_commit=repo.head.commit, url='', branch_path=git.Head.to_full_path(self.k_head_default) @@ -52,28 +52,28 @@ class RootModule(Submodule): """May not do anything""" pass - #{ Interface + #{ Interface - def update(self, previous_commit=None, recursive=True, force_remove=False, init=True, + def update(self, previous_commit=None, recursive=True, force_remove=False, init=True, to_latest_revision=False, progress=None, dry_run=False): """Update the submodules of this repository to the current HEAD commit. This method behaves smartly by determining changes of the path of a submodules - repository, next to changes to the to-be-checked-out commit or the branch to be + repository, next to changes to the to-be-checked-out commit or the branch to be checked out. This works if the submodules ID does not change. Additionally it will detect addition and removal of submodules, which will be handled gracefully. - :param previous_commit: If set to a commit'ish, the commit we should use - as the previous commit the HEAD pointed to before it was set to the commit it points to now. + :param previous_commit: If set to a commit'ish, the commit we should use + as the previous commit the HEAD pointed to before it was set to the commit it points to now. If None, it defaults to HEAD@{1} otherwise :param recursive: if True, the children of submodules will be updated as well using the same technique :param force_remove: If submodules have been deleted, they will be forcibly removed. - Otherwise the update may fail if a submodule's repository cannot be deleted as + Otherwise the update may fail if a submodule's repository cannot be deleted as changes have been made to it (see Submodule.update() for more information) :param init: If we encounter a new module which would need to be initialized, then do it. - :param to_latest_revision: If True, instead of checking out the revision pointed to - by this submodule's sha, the checked out tracking branch will be merged with the + :param to_latest_revision: If True, instead of checking out the revision pointed to + by this submodule's sha, the checked out tracking branch will be merged with the newest remote branch fetched from the repository's origin :param progress: RootUpdateProgress instance or None if no progress should be sent :param dry_run: if True, operations will not actually be performed. Progress messages @@ -106,7 +106,7 @@ class RootModule(Submodule): previous_commit = cur_commit #END exception handling else: - previous_commit = repo.commit(previous_commit) # obtain commit object + previous_commit = repo.commit(previous_commit) # obtain commit object # END handle previous commit psms = self.list_items(repo, parent_commit=previous_commit) @@ -150,7 +150,7 @@ class RootModule(Submodule): #PATH CHANGES ############## if sm.path != psm.path and psm.module_exists(): - progress.update(BEGIN | PATHCHANGE, i, len_csms, prefix + "Moving repository of submodule %r from %s to %s" % (sm.name, psm.abspath, sm.abspath)) + progress.update(BEGIN | PATHCHANGE, i, len_csms, prefix + "Moving repository of submodule %r from %s to %s" % (sm.name, psm.abspath, sm.abspath)) # move the module to the new path if not dry_run: psm.move(sm.path, module=True, configuration=False) @@ -163,7 +163,7 @@ class RootModule(Submodule): ################### if sm.url != psm.url: # Add the new remote, remove the old one - # This way, if the url just changes, the commits will not + # This way, if the url just changes, the commits will not # have to be re-retrieved nn = '__new_origin__' smm = sm.module() @@ -193,14 +193,14 @@ class RootModule(Submodule): # END if urls match # END for each remote - # if we didn't find a matching remote, but have exactly one, + # if we didn't find a matching remote, but have exactly one, # we can safely use this one if rmt_for_deletion is None: if len(rmts) == 1: rmt_for_deletion = rmts[0] else: # if we have not found any remote with the original url - # we may not have a name. This is a special case, + # we may not have a name. This is a special case, # and its okay to fail here # Alternatively we could just generate a unique name and leave all # existing ones in place @@ -211,8 +211,8 @@ class RootModule(Submodule): orig_name = rmt_for_deletion.name smm.delete_remote(rmt_for_deletion) # NOTE: Currently we leave tags from the deleted remotes - # as well as separate tracking branches in the possibly totally - # changed repository ( someone could have changed the url to + # as well as separate tracking branches in the possibly totally + # changed repository ( someone could have changed the url to # another project ). At some point, one might want to clean # it up, but the danger is high to remove stuff the user # has added explicitly @@ -221,7 +221,7 @@ class RootModule(Submodule): smr.rename(orig_name) # early on, we verified that the our current tracking branch - # exists in the remote. Now we have to assure that the + # exists in the remote. Now we have to assure that the # sha we point to is still contained in the new remote # tracking branch. smsha = sm.binsha @@ -237,7 +237,7 @@ class RootModule(Submodule): if not found: # adjust our internal binsha to use the one of the remote # this way, it will be checked out in the next step - # This will change the submodule relative to us, so + # This will change the submodule relative to us, so # the user will be able to commit the change easily 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 sm.binsha = rref.commit.binsha @@ -252,7 +252,7 @@ class RootModule(Submodule): # HANDLE PATH CHANGES ##################### if sm.branch_path != psm.branch_path: - # finally, create a new tracking branch which tracks the + # finally, create a new tracking branch which tracks the # new remote branch progress.update(BEGIN | BRANCHCHANGE, i, len_csms, prefix + "Changing branch of submodule %r from %s to %s" % (sm.name, psm.branch_path, sm.branch_path)) if not dry_run: @@ -267,7 +267,7 @@ class RootModule(Submodule): tbr.set_tracking_branch(find_first_remote_branch(smmr, sm.branch_name)) # figure out whether the previous tracking branch contains - # new commits compared to the other one, if not we can + # new commits compared to the other one, if not we can # delete it. try: tbr = find_first_remote_branch(smmr, psm.branch_name) @@ -285,24 +285,24 @@ class RootModule(Submodule): progress.update(END | BRANCHCHANGE, i, len_csms, prefix + "Done changing branch of submodule %r" % sm.name) #END handle branch - #END handle - # END for each common submodule + #END handle + # END for each common submodule # FINALLY UPDATE ALL ACTUAL SUBMODULES ###################################### for sm in sms: # update the submodule using the default method - sm.update(recursive=False, init=init, to_latest_revision=to_latest_revision, + sm.update(recursive=False, init=init, to_latest_revision=to_latest_revision, progress=progress, dry_run=dry_run) - # update recursively depth first - question is which inconsitent + # update recursively depth first - question is which inconsitent # state will be better in case it fails somewhere. Defective branch - # or defective depth. The RootSubmodule type will never process itself, + # or defective depth. The RootSubmodule type will never process itself, # which was done in the previous expression if recursive: # the module would exist by now if we are not in dry_run mode if sm.module_exists(): - type(self)(sm.module()).update(recursive=True, force_remove=force_remove, + type(self)(sm.module()).update(recursive=True, force_remove=force_remove, init=init, to_latest_revision=to_latest_revision, progress=progress, dry_run=dry_run) #END handle dry_run diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index a66fcddc..bbdf5e1e 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -4,7 +4,7 @@ from git.config import GitConfigParser from StringIO import StringIO import weakref -__all__ = ('sm_section', 'sm_name', 'mkhead', 'unbare_repo', 'find_first_remote_branch', +__all__ = ('sm_section', 'sm_name', 'mkhead', 'unbare_repo', 'find_first_remote_branch', 'SubmoduleConfigParser') #{ Utilities @@ -27,7 +27,7 @@ def mkhead(repo, path): def unbare_repo(func): - """Methods with this decorator raise InvalidGitRepositoryError if they + """Methods with this decorator raise InvalidGitRepositoryError if they encounter a bare repository""" def wrapper(self, *args, **kwargs): @@ -60,7 +60,7 @@ class SubmoduleConfigParser(GitConfigParser): """ Catches calls to _write, and updates the .gitmodules blob in the index - with the new data, if we have written into a stream. Otherwise it will + with the new data, if we have written into a stream. Otherwise it will add the local file to the index to make it correspond with the working tree. Additionally, the cache must be cleared @@ -75,7 +75,7 @@ class SubmoduleConfigParser(GitConfigParser): #{ Interface def set_submodule(self, submodule): - """Set this instance's submodule. It must be called before + """Set this instance's submodule. It must be called before the first write operation begins""" self._smref = weakref.ref(submodule) diff --git a/git/objects/tag.py b/git/objects/tag.py index 345bb1d5..3fd7a4d4 100644 --- a/git/objects/tag.py +++ b/git/objects/tag.py @@ -20,7 +20,7 @@ class TagObject(base.Object): type = "tag" __slots__ = ("object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message") - def __init__(self, repo, binsha, object=None, tag=None, + def __init__(self, repo, binsha, object=None, tag=None, tagger=None, tagged_date=None, tagger_tz_offset=None, message=None): """Initialize a tag object with additional data @@ -30,9 +30,9 @@ class TagObject(base.Object): :param tag: name of this tag :param tagger: Actor identifying the tagger :param tagged_date: int_seconds_since_epoch - is the DateTime of the tag creation - use time.gmtime to convert + is the DateTime of the tag creation - use time.gmtime to convert it into a different format - :param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the + :param tagged_tz_offset: int_seconds_west_of_utc is the timezone that the authored_date is in, in a format similar to time.altzone""" super(TagObject, self).__init__(repo, binsha) if object is not None: @@ -64,7 +64,7 @@ class TagObject(base.Object): self.tagger, self.tagged_date, self.tagger_tz_offset = parse_actor_and_date(tagger_info) # line 4 empty - it could mark the beginning of the next header - # in case there really is no message, it would not exist. Otherwise + # in case there really is no message, it would not exist. Otherwise # a newline separates header from message if len(lines) > 5: self.message = "\n".join(lines[5:]) diff --git a/git/objects/tree.py b/git/objects/tree.py index e4e49d1a..cc3699f5 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -11,12 +11,12 @@ from submodule.base import Submodule import git.diff as diff from fun import ( - tree_entries_from_data, + tree_entries_from_data, tree_to_stream ) from gitdb.util import ( - to_bin_sha, + to_bin_sha, ) __all__ = ("TreeModifier", "Tree") @@ -26,7 +26,7 @@ class TreeModifier(object): """A utility class providing methods to alter the underlying cache in a list-like fashion. - Once all adjustments are complete, the _cache, which really is a refernce to + Once all adjustments are complete, the _cache, which really is a refernce to the cache of a tree, will be sorted. Assuring it will be in a serializable state""" __slots__ = '_cache' @@ -42,10 +42,10 @@ class TreeModifier(object): # END for each item in cache return -1 - #{ Interface + #{ Interface def set_done(self): """Call this method once you are done modifying the tree information. - It may be called several times, but be aware that each call will cause + It may be called several times, but be aware that each call will cause a sort operation :return self:""" self._cache.sort(key=lambda t: t[2]) # sort by name @@ -55,8 +55,8 @@ class TreeModifier(object): #{ Mutators def add(self, sha, mode, name, force=False): """Add the given item to the tree. If an item with the given name already - exists, nothing will be done, but a ValueError will be raised if the - sha and mode of the existing item do not match the one you add, unless + exists, nothing will be done, but a ValueError will be raised if the + sha and mode of the existing item do not match the one you add, unless force is True :param sha: The 20 or 40 byte sha of the item to add @@ -87,8 +87,8 @@ class TreeModifier(object): return self def add_unchecked(self, binsha, mode, name): - """Add the given item to the tree, its correctness is assumed, which - puts the caller into responsibility to assure the input is correct. + """Add the given item to the tree, its correctness is assumed, which + puts the caller into responsibility to assure the input is correct. For more information on the parameters, see ``add`` :param binsha: 20 byte binary sha""" self._cache.append((binsha, mode, name)) @@ -108,7 +108,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): ``Tree as a list``:: - Access a specific blob using the + Access a specific blob using the tree['filename'] notation. You may as well access by index @@ -118,15 +118,15 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): type = "tree" __slots__ = "_cache" - # actual integer ids for comparison + # 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 _map_id_to_type = { - commit_id: Submodule, - blob_id: Blob, + commit_id: Submodule, + blob_id: Blob, symlink_id: Blob # tree id added once Tree is defined } @@ -147,7 +147,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): self._cache = tree_entries_from_data(ostream.read()) else: super(Tree, self)._set_cache_(attr) - # END handle attribute + # END handle attribute def _iter_convert_to_object(self, iterable): """Iterable yields tuples of (binsha, mode, name), which will be converted @@ -158,7 +158,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): yield self._map_id_to_type[mode >> 12](self.repo, binsha, mode, path) except KeyError: raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path)) - # END for each item + # END for each item def __div__(self, file): """Find the named object in this tree's contents @@ -236,7 +236,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): if isinstance(item, basestring): # compatability return self.__div__(item) - # END index is basestring + # END index is basestring raise TypeError("Invalid index type: %r" % item) @@ -262,7 +262,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): return reversed(self._iter_convert_to_object(self._cache)) def _serialize(self, stream): - """Serialize this tree into the stream. Please note that we will assume + """Serialize this tree into the stream. Please note that we will assume our tree data to be in a sorted state. If this is not the case, serialization will not generate a correct tree representation as these are assumed to be sorted by algorithms""" diff --git a/git/objects/util.py b/git/objects/util.py index 6321399d..f6daca0f 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """Module for general utility functions""" from git.util import ( - IterableList, + IterableList, Actor ) @@ -16,8 +16,8 @@ from string import digits import time import os -__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', - 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz', +__all__ = ('get_object_type_by_name', 'parse_date', 'parse_actor_and_date', + 'ProcessStreamAdapter', 'Traversable', 'altz_to_utctz_str', 'utctz_to_altz', 'verify_utctz', 'Actor') #{ Functions @@ -27,8 +27,8 @@ def mode_str_to_int(modestr): """ :param modestr: string like 755 or 644 or 100644 - only the last 6 chars will be used :return: - String identifying a mode compatible to the mode methods ids of the - stat module regarding the rwx permissions for user, group and other, + String identifying a mode compatible to the mode methods ids of the + stat module regarding the rwx permissions for user, group and other, special flags and file system flags, i.e. whether it is a symlink for example.""" mode = 0 @@ -64,7 +64,7 @@ def get_object_type_by_name(object_type_name): def utctz_to_altz(utctz): """we convert utctz to the timezone in seconds, it is the format time.altzone - returns. Git stores it as UTC timezone which has the opposite sign as well, + returns. Git stores it as UTC timezone which has the opposite sign as well, which explains the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200""" return -1 * int(float(utctz) / 100 * 3600) @@ -102,7 +102,7 @@ def parse_date(string_date): Parse the given date as one of the following * Git internal format: timestamp offset - * RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200. + * RFC 2822: Thu, 07 Apr 2005 22:13:13 +0200. * ISO 8601 2005-04-07T22:13:13 The T can be a space as well @@ -139,7 +139,7 @@ def parse_date(string_date): if splitter == -1: splitter = string_date.rfind(' ') # END handle 'T' and ' ' - # END handle rfc or iso + # END handle rfc or iso assert splitter > -1 @@ -153,7 +153,7 @@ def parse_date(string_date): for fmt in date_formats: try: dtstruct = time.strptime(date_part, fmt) - fstruct = time.struct_time((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday, + fstruct = time.struct_time((dtstruct.tm_year, dtstruct.tm_mon, dtstruct.tm_mday, tstruct.tm_hour, tstruct.tm_min, tstruct.tm_sec, dtstruct.tm_wday, dtstruct.tm_yday, tstruct.tm_isdst)) return int(time.mktime(fstruct)), utctz_to_altz(offset) @@ -166,7 +166,7 @@ def parse_date(string_date): raise ValueError("no format matched") # END handle format except Exception: - raise ValueError("Unsupported date format: %s" % string_date) + raise ValueError("Unsupported date format: %s" % string_date) # END handle exceptions @@ -193,14 +193,14 @@ def parse_actor_and_date(line): #} END functions -#{ Classes +#{ Classes class ProcessStreamAdapter(object): """Class wireing all calls to the contained Process instance. - Use this type to hide the underlying process to provide access only to a specified - stream. The process is usually wrapped into an AutoInterrupt class to kill + Use this type to hide the underlying process to provide access only to a specified + stream. The process is usually wrapped into an AutoInterrupt class to kill it if the instance goes out of scope.""" __slots__ = ("_proc", "_stream") @@ -214,7 +214,7 @@ class ProcessStreamAdapter(object): class Traversable(object): - """Simple interface to perforam depth-first or breadth-first traversals + """Simple interface to perforam depth-first or breadth-first traversals into one direction. Subclasses only need to implement one function. Instances of the Subclass must be hashable""" @@ -244,7 +244,7 @@ class Traversable(object): :param predicate: f(i,d) returns False if item i at depth d should not be included in the result - :param prune: + :param prune: f(i,d) return True if the search should stop at item i at depth d. Item i will not be returned. @@ -267,8 +267,8 @@ class Traversable(object): If as_edge is True, the source of the first edge is None :param as_edge: - if True, return a pair of items, first being the source, second the - destinatination, i.e. tuple(src, dest) with the edge spanning from + if True, return a pair of items, first being the source, second the + destinatination, i.e. tuple(src, dest) with the edge spanning from source to destination""" visited = set() stack = Deque() |