diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-08 23:50:51 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-08 23:50:51 +0200 |
commit | b0e84a3401c84507dc017d6e4f57a9dfdb31de53 (patch) | |
tree | 59ad57c3bb4460ed824a144ddc4f84e4b20675dc /lib/git/commit.py | |
parent | 6da04adff0b96c5163b0c2530028b72be2fd26fd (diff) | |
parent | 07eaa4ce2696a88ec0db6e91f191af1e48226aca (diff) | |
download | gitpython-b0e84a3401c84507dc017d6e4f57a9dfdb31de53.tar.gz |
Merge branch 'doc_enhancements' into fixes
Diffstat (limited to 'lib/git/commit.py')
-rw-r--r-- | lib/git/commit.py | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py index ba7a7102..edfe47ca 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -14,38 +14,44 @@ import diff import stats class Commit(LazyMixin): + """ + Wraps a git Commit object. + + 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. + """ 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 + Instantiate a new Commit. All keyword arguments taking None as default will + be implicitly set if id names a valid sha. + + The parameter documentation indicates the type of the argument after a colon ':'. ``id`` - is the id of the commit + is the sha id of the commit - ``parents`` - is a list of commit ids (will be converted into Commit instances) + ``parents`` : list( Commit, ... ) + is a list of commit ids - ``tree`` - is the correspdonding tree id (will be converted into a Tree object) + ``tree`` : Tree + is the corresponding tree id - ``author`` - is the author string + ``author`` : Actor + is the author string ( will be implicitly converted into an Actor object ) - ``authored_date`` + ``authored_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst ) is the authored DateTime - ``committer`` + ``committer`` : Actor is the committer string - ``committed_date`` + ``committed_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst) is the committed DateTime - ``message`` + ``message`` : string is the commit message - ``parents`` - is the list of the parents of the commit - Returns git.Commit """ @@ -74,6 +80,10 @@ class Commit(LazyMixin): return self.id != other.id def __bake__(self): + """ + Called by LazyMixin superclass when the first uninitialized member needs + to be set as it is queried. + """ temp = Commit.find_all(self.repo, self.id, max_count=1)[0] self.parents = temp.parents self.tree = temp.tree @@ -85,10 +95,18 @@ class Commit(LazyMixin): @property def id_abbrev(self): + """ + Returns + First 7 bytes of the commit's sha id as an abbreviation of the full string. + """ return self.id[0:7] @property def summary(self): + """ + Returns + First line of the commit message. + """ return self.message.split('\n', 1)[0] @classmethod @@ -122,10 +140,11 @@ class Commit(LazyMixin): is the ref from which to begin (SHA1 or name) ``path`` - is an optinal path + is an optinal path, if set only Commits that include the path + will be considered - ``options`` - is a Hash of optional arguments to git where + ``kwargs`` + optional keyword arguments to git where ``max_count`` is the maximum number of commits to fetch ``skip`` is the number of commits to skip @@ -147,7 +166,7 @@ class Commit(LazyMixin): is the Repo ``text`` - is the text output from the git command (raw format) + is the text output from the git-rev-list command (raw format) Returns git.Commit[] @@ -180,7 +199,7 @@ class Commit(LazyMixin): @classmethod def diff(cls, repo, a, b=None, paths=None): """ - Show diffs between two trees: + Creates diffs between a tree and the index or between two trees: ``repo`` is the Repo @@ -194,10 +213,13 @@ class Commit(LazyMixin): given paths. ``paths`` - is a list of paths to limit the diff. + is a list of paths to limit the diff to. Returns - git.Diff[] + git.Diff[]:: + + between tree and the index if only a is given + between two trees if a and b are given and are commits """ paths = paths or [] @@ -216,6 +238,12 @@ class Commit(LazyMixin): @property def diffs(self): + """ + Returns + git.Diff[] + Diffs between this commit and its first parent or all changes if this + commit is the first commit and has no parent. + """ if not self.parents: d = self.repo.git.show(self.id, '-M', full_index=True, pretty='raw') if re.search(r'diff --git a', d): @@ -230,6 +258,13 @@ class Commit(LazyMixin): @property def stats(self): + """ + 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 + """ if not self.parents: text = self.repo.git.diff_tree(self.id, '--', numstat=True, root=True) text2 = "" @@ -254,7 +289,7 @@ class Commit(LazyMixin): Parse out the actor (author or committer) info Returns - [str (actor name and email), time (acted at time)] + [Actor, gmtime(acted at time)] """ m = re.search(r'^.+? (.*) (\d+) .*$', line) actor, epoch = m.groups() |