1414import stats
1515
1616class Commit (LazyMixin ):
17+ """
18+ Wraps a git Commit object.
19+
20+ This class will act lazily on some of its attributes and will query the
21+ value on demand only if it involves calling the git binary.
22+ """
1723 def __init__ (self , repo , id , tree = None , author = None , authored_date = None ,
1824 committer = None , committed_date = None , message = None , parents = None ):
1925 """
20- Instantiate a new Commit
26+ Instantiate a new Commit. All keyword arguments taking None as default will
27+ be implicitly set if id names a valid sha.
28+
29+ The parameter documentation indicates the type of the argument after a colon ':'.
2130
2231 ``id``
23- is the id of the commit
32+ is the sha id of the commit
2433
25- ``parents``
26- is a list of commit ids (will be converted into Commit instances)
34+ ``parents`` : list( Commit, ... )
35+ is a list of commit ids
2736
28- ``tree``
29- is the correspdonding tree id (will be converted into a Tree object)
37+ ``tree`` : Tree
38+ is the corresponding tree id
3039
31- ``author``
32- is the author string
40+ ``author`` : Actor
41+ is the author string ( will be implicitly converted into an Actor object )
3342
34- ``authored_date``
43+ ``authored_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst )
3544 is the authored DateTime
3645
37- ``committer``
46+ ``committer`` : Actor
3847 is the committer string
3948
40- ``committed_date``
49+ ``committed_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
4150 is the committed DateTime
4251
43- ``message``
52+ ``message`` : string
4453 is the commit message
4554
46- ``parents``
47- is the list of the parents of the commit
48-
4955 Returns
5056 git.Commit
5157 """
@@ -74,6 +80,10 @@ def __ne__(self, other):
7480 return self .id != other .id
7581
7682 def __bake__ (self ):
83+ """
84+ Called by LazyMixin superclass when the first uninitialized member needs
85+ to be set as it is queried.
86+ """
7787 temp = Commit .find_all (self .repo , self .id , max_count = 1 )[0 ]
7888 self .parents = temp .parents
7989 self .tree = temp .tree
@@ -85,10 +95,18 @@ def __bake__(self):
8595
8696 @property
8797 def id_abbrev (self ):
98+ """
99+ Returns
100+ First 7 bytes of the commit's sha id as an abbreviation of the full string.
101+ """
88102 return self .id [0 :7 ]
89103
90104 @property
91105 def summary (self ):
106+ """
107+ Returns
108+ First line of the commit message.
109+ """
92110 return self .message .split ('\n ' , 1 )[0 ]
93111
94112 @classmethod
@@ -122,10 +140,11 @@ def find_all(cls, repo, ref, path='', **kwargs):
122140 is the ref from which to begin (SHA1 or name)
123141
124142 ``path``
125- is an optinal path
143+ is an optinal path, if set only Commits that include the path
144+ will be considered
126145
127- ``options ``
128- is a Hash of optional arguments to git where
146+ ``kwargs ``
147+ optional keyword arguments to git where
129148 ``max_count`` is the maximum number of commits to fetch
130149 ``skip`` is the number of commits to skip
131150
@@ -147,7 +166,7 @@ def list_from_string(cls, repo, text):
147166 is the Repo
148167
149168 ``text``
150- is the text output from the git command (raw format)
169+ is the text output from the git-rev-list command (raw format)
151170
152171 Returns
153172 git.Commit[]
@@ -180,7 +199,7 @@ def list_from_string(cls, repo, text):
180199 @classmethod
181200 def diff (cls , repo , a , b = None , paths = None ):
182201 """
183- Show diffs between two trees:
202+ Creates diffs between a tree and the index or between two trees:
184203
185204 ``repo``
186205 is the Repo
@@ -194,10 +213,13 @@ def diff(cls, repo, a, b=None, paths=None):
194213 given paths.
195214
196215 ``paths``
197- is a list of paths to limit the diff.
216+ is a list of paths to limit the diff to .
198217
199218 Returns
200- git.Diff[]
219+ git.Diff[]::
220+
221+ between tree and the index if only a is given
222+ between two trees if a and b are given and are commits
201223 """
202224 paths = paths or []
203225
@@ -216,6 +238,12 @@ def diff(cls, repo, a, b=None, paths=None):
216238
217239 @property
218240 def diffs (self ):
241+ """
242+ Returns
243+ git.Diff[]
244+ Diffs between this commit and its first parent or all changes if this
245+ commit is the first commit and has no parent.
246+ """
219247 if not self .parents :
220248 d = self .repo .git .show (self .id , '-M' , full_index = True , pretty = 'raw' )
221249 if re .search (r'diff --git a' , d ):
@@ -230,6 +258,13 @@ def diffs(self):
230258
231259 @property
232260 def stats (self ):
261+ """
262+ Create a git stat from changes between this commit and its first parent
263+ or from all changes done if this is the very first commit.
264+
265+ Return
266+ git.Stats
267+ """
233268 if not self .parents :
234269 text = self .repo .git .diff_tree (self .id , '--' , numstat = True , root = True )
235270 text2 = ""
@@ -254,7 +289,7 @@ def actor(cls, line):
254289 Parse out the actor (author or committer) info
255290
256291 Returns
257- [str (actor name and email), time (acted at time)]
292+ [Actor, gmtime (acted at time)]
258293 """
259294 m = re .search (r'^.+? (.*) (\d+) .*$' , line )
260295 actor , epoch = m .groups ()
0 commit comments