diff options
author | Steve Frécinaux <code@istique.net> | 2008-09-06 00:35:04 +0200 |
---|---|---|
committer | Steve Frécinaux <code@istique.net> | 2008-09-06 00:35:04 +0200 |
commit | c8c50d8be2dc5ae74e53e44a87f580bf25956af9 (patch) | |
tree | 39348788be4e9acf31abcf4d81e391cdd9183304 /lib/git | |
parent | 2f6a6e35d003c243968cdb41b72fbbe609e56841 (diff) | |
download | gitpython-c8c50d8be2dc5ae74e53e44a87f580bf25956af9.tar.gz |
Do not use **kwargs for constructors.
It is better to have an explicit list of variables for the constructors,
be it only to avoid mispelled arguments.
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/blob.py | 24 | ||||
-rw-r--r-- | lib/git/commit.py | 33 | ||||
-rw-r--r-- | lib/git/tree.py | 11 |
3 files changed, 35 insertions, 33 deletions
diff --git a/lib/git/blob.py b/lib/git/blob.py index 0b4b19c2..80d237d7 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -14,29 +14,33 @@ from commit import Commit class Blob(object): DEFAULT_MIME_TYPE = "text/plain" - def __init__(self, repo, **kwargs): + def __init__(self, repo, id, mode=None, name=None): """ Create an unbaked Blob containing just the specified attributes ``repo`` is the Repo - ``atts`` - is a dict of instance variable data + ``id`` + is the git object id + + ``mode`` + is the file mode + + ``name`` + is the file name Returns GitPython.Blob """ - self.id = None - self.mode = None - self.name = None + self.repo = repo + self.id = id + self.mode = mode + self.name = name + self._size = None self.data_stored = None - self.repo = repo - for k, v in kwargs.items(): - setattr(self, k, v) - @property def size(self): """ diff --git a/lib/git/commit.py b/lib/git/commit.py index 13472deb..93a2b70f 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -9,12 +9,13 @@ import time from actor import Actor from lazy import LazyMixin -import tree +from tree import Tree import diff import stats class Commit(LazyMixin): - def __init__(self, repo, **kwargs): + def __init__(self, repo, id, tree=None, author=None, authored_date=None, + committer=None, committed_date=None, message=None, parents=None): """ Instantiate a new Commit @@ -42,29 +43,29 @@ class Commit(LazyMixin): ``message`` is the first line of the commit message + ``parents`` + is the list of the parents of the commit + Returns GitPython.Commit """ LazyMixin.__init__(self) self.repo = repo - self.id = None - self.tree = None - self.author = None - self.authored_date = None - self.committer = None - self.committed_date = None - self.message = None + self.id = id self.parents = None - - for k, v in kwargs.items(): - setattr(self, k, v) + self.tree = None + self.author = author + self.authored_date = authored_date + self.committer = committer + self.committed_date = committed_date + self.message = message if self.id: - if 'parents' in kwargs: - self.parents = map(lambda p: Commit(repo, id=p), kwargs['parents']) - if 'tree' in kwargs: - self.tree = tree.Tree(repo, id=kwargs['tree']) + if parents is not None: + self.parents = [Commit(repo, p) for p in parents] + if tree is not None: + self.tree = Tree(repo, id=tree) def __bake__(self): temp = Commit.find_all(self.repo, self.id, max_count=1)[0] diff --git a/lib/git/tree.py b/lib/git/tree.py index 59d3af1e..dbd78ac4 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -9,17 +9,14 @@ from lazy import LazyMixin import blob class Tree(LazyMixin): - def __init__(self, repo, **kwargs): + def __init__(self, repo, id, mode=None, name=None): LazyMixin.__init__(self) self.repo = repo - self.id = None - self.mode = None - self.name = None + self.id = id + self.mode = mode + self.name = name self._contents = None - for k, v in kwargs.items(): - setattr(self, k, v) - def __bake__(self): # Ensure the treeish references directly a tree treeish = self.id |