14
14
import stats
15
15
16
16
class 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
+ """
17
23
def __init__ (self , repo , id , tree = None , author = None , authored_date = None ,
18
24
committer = None , committed_date = None , message = None , parents = None ):
19
25
"""
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 ':'.
21
30
22
31
``id``
23
- is the id of the commit
32
+ is the sha id of the commit
24
33
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
27
36
28
- ``tree``
29
- is the correspdonding tree id (will be converted into a Tree object)
37
+ ``tree`` : Tree
38
+ is the corresponding tree id
30
39
31
- ``author``
32
- is the author string
40
+ ``author`` : Actor
41
+ is the author string ( will be implicitly converted into an Actor object )
33
42
34
- ``authored_date``
43
+ ``authored_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst )
35
44
is the authored DateTime
36
45
37
- ``committer``
46
+ ``committer`` : Actor
38
47
is the committer string
39
48
40
- ``committed_date``
49
+ ``committed_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst)
41
50
is the committed DateTime
42
51
43
- ``message``
52
+ ``message`` : string
44
53
is the commit message
45
54
46
- ``parents``
47
- is the list of the parents of the commit
48
-
49
55
Returns
50
56
git.Commit
51
57
"""
@@ -68,6 +74,10 @@ def __init__(self, repo, id, tree=None, author=None, authored_date=None,
68
74
self .tree = Tree (repo , id = tree )
69
75
70
76
def __bake__ (self ):
77
+ """
78
+ Called by LazyMixin superclass when the first uninitialized member needs
79
+ to be set as it is queried.
80
+ """
71
81
temp = Commit .find_all (self .repo , self .id , max_count = 1 )[0 ]
72
82
self .parents = temp .parents
73
83
self .tree = temp .tree
@@ -79,10 +89,18 @@ def __bake__(self):
79
89
80
90
@property
81
91
def id_abbrev (self ):
92
+ """
93
+ Returns
94
+ First 7 bytes of the commit's sha id as an abbreviation of the full string.
95
+ """
82
96
return self .id [0 :7 ]
83
97
84
98
@property
85
99
def summary (self ):
100
+ """
101
+ Returns
102
+ First line of the commit message.
103
+ """
86
104
return self .message .split ('\n ' , 1 )[0 ]
87
105
88
106
@classmethod
@@ -115,7 +133,8 @@ def find_all(cls, repo, ref, path='', **kwargs):
115
133
is the ref from which to begin (SHA1 or name)
116
134
117
135
``path``
118
- is an optinal path
136
+ is an optinal path, if set only Commits that include the path
137
+ will be considered
119
138
120
139
``options``
121
140
is a Hash of optional arguments to git where
@@ -140,7 +159,7 @@ def list_from_string(cls, repo, text):
140
159
is the Repo
141
160
142
161
``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)
144
163
145
164
Returns
146
165
git.Commit[]
@@ -173,7 +192,7 @@ def list_from_string(cls, repo, text):
173
192
@classmethod
174
193
def diff (cls , repo , a , b = None , paths = None ):
175
194
"""
176
- Show diffs between two trees:
195
+ Creates diffs between a tree and the index or between two trees:
177
196
178
197
``repo``
179
198
is the Repo
@@ -187,10 +206,13 @@ def diff(cls, repo, a, b=None, paths=None):
187
206
given paths.
188
207
189
208
``paths``
190
- is a list of paths to limit the diff.
209
+ is a list of paths to limit the diff to .
191
210
192
211
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
194
216
"""
195
217
paths = paths or []
196
218
@@ -209,6 +231,12 @@ def diff(cls, repo, a, b=None, paths=None):
209
231
210
232
@property
211
233
def 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
+ """
212
240
if not self .parents :
213
241
d = self .repo .git .show (self .id , '-M' , full_index = True , pretty = 'raw' )
214
242
if re .search (r'diff --git a' , d ):
@@ -223,6 +251,13 @@ def diffs(self):
223
251
224
252
@property
225
253
def 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
+ """
226
261
if not self .parents :
227
262
text = self .repo .git .diff_tree (self .id , '--' , numstat = True , root = True )
228
263
text2 = ""
@@ -247,7 +282,7 @@ def actor(cls, line):
247
282
Parse out the actor (author or committer) info
248
283
249
284
Returns
250
- [str (actor name and email), time (acted at time)]
285
+ [Actor, gmtime (acted at time)]
251
286
"""
252
287
m = re .search (r'^.+? (.*) (\d+) .*$' , line )
253
288
actor , epoch = m .groups ()
0 commit comments