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+ """
1723def __init__ (self ,repo ,id ,tree = None ,author = None ,authored_date = None ,
1824committer = 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 thesha 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 thecorrespdonding tree id (will be converted into a Tree object)
37+ ``tree`` : Tree
38+ is thecorresponding 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 """
@@ -68,6 +74,10 @@ def __init__(self, repo, id, tree=None, author=None, authored_date=None,
6874self .tree = Tree (repo ,id = tree )
6975
7076def __bake__ (self ):
77+ """
78+ Called by LazyMixin superclass when the first uninitialized member needs
79+ to be set as it is queried.
80+ """
7181temp = Commit .find_all (self .repo ,self .id ,max_count = 1 )[0 ]
7282self .parents = temp .parents
7383self .tree = temp .tree
@@ -79,10 +89,18 @@ def __bake__(self):
7989
8090@property
8191def id_abbrev (self ):
92+ """
93+ Returns
94+ First 7 bytes of the commit's sha id as an abbreviation of the full string.
95+ """
8296return self .id [0 :7 ]
8397
8498@property
8599def summary (self ):
100+ """
101+ Returns
102+ First line of the commit message.
103+ """
86104return self .message .split ('\n ' ,1 )[0 ]
87105
88106@classmethod
@@ -115,7 +133,8 @@ def find_all(cls, repo, ref, path='', **kwargs):
115133 is the ref from which to begin (SHA1 or name)
116134
117135 ``path``
118- is an optinal path
136+ is an optinal path, if set only Commits that include the path
137+ will be considered
119138
120139 ``options``
121140 is a Hash of optional arguments to git where
@@ -140,7 +159,7 @@ def list_from_string(cls, repo, text):
140159 is the Repo
141160
142161 ``text``
143- is the text output from the git command (raw format)
162+ is the text output from the git-rev-list command (raw format)
144163
145164 Returns
146165 git.Commit[]
@@ -173,7 +192,7 @@ def list_from_string(cls, repo, text):
173192@classmethod
174193def diff (cls ,repo ,a ,b = None ,paths = None ):
175194"""
176- Show diffs between two trees:
195+ Creates diffs between a tree and the index or between two trees:
177196
178197 ``repo``
179198 is the Repo
@@ -187,10 +206,13 @@ def diff(cls, repo, a, b=None, paths=None):
187206 given paths.
188207
189208 ``paths``
190- is a list of paths to limit the diff.
209+ is a list of paths to limit the diff to .
191210
192211 Returns
193- git.Diff[]
212+ git.Diff[]::
213+
214+ between tree and the index if only a is given
215+ between two trees if a and b are given and are commits
194216 """
195217paths = paths or []
196218
@@ -209,6 +231,12 @@ def diff(cls, repo, a, b=None, paths=None):
209231
210232@property
211233def diffs (self ):
234+ """
235+ Returns
236+ git.Diff[]
237+ Diffs between this commit and its first parent or all changes if this
238+ commit is the first commit and has no parent.
239+ """
212240if not self .parents :
213241d = self .repo .git .show (self .id ,'-M' ,full_index = True ,pretty = 'raw' )
214242if re .search (r'diff --git a' ,d ):
@@ -223,6 +251,13 @@ def diffs(self):
223251
224252@property
225253def stats (self ):
254+ """
255+ Create a git stat from changes between this commit and its first parent
256+ or from all changes done if this is the very first commit.
257+
258+ Return
259+ git.Stats
260+ """
226261if not self .parents :
227262text = self .repo .git .diff_tree (self .id ,'--' ,numstat = True ,root = True )
228263text2 = ""
@@ -247,7 +282,7 @@ def actor(cls, line):
247282 Parse out the actor (author or committer) info
248283
249284 Returns
250- [str (actor name and email), time (acted at time)]
285+ [Actor, gmtime (acted at time)]
251286 """
252287m = re .search (r'^.+? (.*) (\d+) .*$' ,line )
253288actor ,epoch = m .groups ()