FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pygit2/src/commit.c at master · libgit2/pygit2 · GitHub
libgit2
pygit2
Repository navigation
Code
Issues
184
(184)
Pull requests
5
(5)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pygit2
/
src
/
commit.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
359 lines (286 loc) · 11.4 KB
Breadcrumbs
pygit2
/
src
/
commit.c
Copy path
File metadata and controls
359 lines (286 loc) · 11.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
* Copyright 2010-2026 The pygit2 contributors
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#define
PY_SSIZE_T_CLEAN
#include
<Python.h>
#include
"error.h"
#include
"utils.h"
#include
"signature.h"
#include
"object.h"
#include
"oid.h"
extern
PyTypeObject
TreeType
;
extern
PyObject
*
GitError
;
PyDoc_STRVAR
(
Commit_message_encoding__doc__
,
"Message encoding."
);
PyObject
*
Commit_message_encoding__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
const
char
*
encoding
=
git_commit_message_encoding
(
self
->
commit
);
if
(
encoding
==
NULL
)
Py_RETURN_NONE
;
return
to_encoding
(
encoding
);
}
PyDoc_STRVAR
(
Commit_message__doc__
,
"The commit message, a text string."
);
PyObject
*
Commit_message__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
const
char
*
message
=
git_commit_message
(
self
->
commit
);
const
char
*
encoding
=
git_commit_message_encoding
(
self
->
commit
);
return
to_unicode
(
message
,
encoding
,
NULL
);
}
PyDoc_STRVAR
(
Commit_gpg_signature__doc__
,
"A tuple with the GPG signature and the signed payload."
);
PyObject
*
Commit_gpg_signature__get__
(
Commit
*
self
)
{
git_buf
gpg_signature
=
{
NULL
},
signed_data
=
{
NULL
};
PyObject
*
py_gpg_signature
,
*
py_signed_data
;
const
git_oid
*
oid
=
Object__id
((
Object
*
)
self
);
int
err
=
git_commit_extract_signature
(
&
gpg_signature
,
&
signed_data
,
self
->
repo
->
repo
, (
git_oid
*
)
oid
,
NULL
);
if
(
err
!=
GIT_OK
){
git_buf_dispose
(
&
gpg_signature
);
git_buf_dispose
(
&
signed_data
);
if
(
err
==
GIT_ENOTFOUND
){
return
Py_BuildValue
(
"OO"
,
Py_None
,
Py_None
);
}
return
Error_set
(
err
);
}
py_gpg_signature
=
PyBytes_FromString
(
gpg_signature
.
ptr
);
py_signed_data
=
PyBytes_FromString
(
signed_data
.
ptr
);
git_buf_dispose
(
&
gpg_signature
);
git_buf_dispose
(
&
signed_data
);
return
Py_BuildValue
(
"NN"
,
py_gpg_signature
,
py_signed_data
);
}
PyDoc_STRVAR
(
Commit_message_trailers__doc__
,
"Returns commit message trailers (e.g., Bug: 1234) as a dictionary."
);
PyObject
*
Commit_message_trailers__get__
(
Commit
*
self
)
{
git_message_trailer_array
gmt_arr
;
int
i
,
trailer_count
,
err
;
PyObject
*
dict
;
PyObject
*
py_val
;
const
char
*
message
=
git_commit_message
(
self
->
commit
);
const
char
*
encoding
=
git_commit_message_encoding
(
self
->
commit
);
err
=
git_message_trailers
(
&
gmt_arr
,
message
);
if
(
err
<
0
)
return
Error_set
(
err
);
dict
=
PyDict_New
();
if
(
dict
==
NULL
)
goto
error
;
trailer_count
=
gmt_arr
.
count
;
for
(
i
=
0
;
i
<
trailer_count
;
i
++
) {
py_val
=
to_unicode
(
gmt_arr
.
trailers
[
i
].
value
,
encoding
,
NULL
);
err
=
PyDict_SetItemString
(
dict
,
gmt_arr
.
trailers
[
i
].
key
,
py_val
);
Py_DECREF
(
py_val
);
if
(
err
<
0
)
goto
error
;
}
git_message_trailer_array_free
(
&
gmt_arr
);
return
dict
;
error
:
git_message_trailer_array_free
(
&
gmt_arr
);
Py_CLEAR
(
dict
);
return
NULL
;
}
PyDoc_STRVAR
(
Commit_raw_message__doc__
,
"Message (bytes)."
);
PyObject
*
Commit_raw_message__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
return
PyBytes_FromString
(
git_commit_message
(
self
->
commit
));
}
PyDoc_STRVAR
(
Commit_commit_time__doc__
,
"Commit time, an int (Unix timestamp)."
);
PyObject
*
Commit_commit_time__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
return
PyLong_FromLongLong
(
git_commit_time
(
self
->
commit
));
}
PyDoc_STRVAR
(
Commit_commit_time_offset__doc__
,
"Commit time zone UTC offset, an int (minutes)."
);
PyObject
*
Commit_commit_time_offset__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
return
PyLong_FromLong
(
git_commit_time_offset
(
self
->
commit
));
}
PyDoc_STRVAR
(
Commit_committer__doc__
,
"The committer of the commit."
);
PyObject
*
Commit_committer__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
const
git_signature
*
signature
=
git_commit_committer
(
self
->
commit
);
const
char
*
encoding
=
git_commit_message_encoding
(
self
->
commit
);
return
build_signature
((
Object
*
)
self
,
signature
,
encoding
);
}
PyDoc_STRVAR
(
Commit_author__doc__
,
"The author of the commit."
);
PyObject
*
Commit_author__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
const
git_signature
*
signature
=
git_commit_author
(
self
->
commit
);
const
char
*
encoding
=
git_commit_message_encoding
(
self
->
commit
);
return
build_signature
((
Object
*
)
self
,
signature
,
encoding
);
}
PyDoc_STRVAR
(
Commit_tree__doc__
,
"The tree object attached to the commit."
);
PyObject
*
Commit_tree__get__
(
Commit
*
self
)
{
git_tree
*
tree
;
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
int
err
=
git_commit_tree
(
&
tree
,
self
->
commit
);
if
(
err
==
GIT_ENOTFOUND
) {
char
tree_id
[
GIT_OID_HEXSZ
+
1
]
=
{
0
};
git_oid_fmt
(
tree_id
,
git_commit_tree_id
(
self
->
commit
));
return
PyErr_Format
(
GitError
,
"Unable to read tree %s"
,
tree_id
);
}
if
(
err
<
0
)
return
Error_set
(
err
);
return
wrap_object
((
git_object
*
)
tree
,
self
->
repo
,
NULL
);
}
PyDoc_STRVAR
(
Commit_tree_id__doc__
,
"The id of the tree attached to the commit."
);
PyObject
*
Commit_tree_id__get__
(
Commit
*
self
)
{
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
return
git_oid_to_python
(
git_commit_tree_id
(
self
->
commit
));
}
PyDoc_STRVAR
(
Commit_parents__doc__
,
"The list of parent commits."
);
PyObject
*
Commit_parents__get__
(
Commit
*
self
)
{
Repository
*
py_repo
;
unsigned
int
i
,
parent_count
;
const
git_oid
*
parent_oid
;
git_commit
*
parent
;
int
err
;
PyObject
*
py_parent
;
PyObject
*
list
;
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
parent_count
=
git_commit_parentcount
(
self
->
commit
);
list
=
PyList_New
(
parent_count
);
if
(!
list
)
return
NULL
;
py_repo
=
self
->
repo
;
for
(
i
=
0
;
i
<
parent_count
;
i
++
) {
parent_oid
=
git_commit_parent_id
(
self
->
commit
,
i
);
if
(
parent_oid
==
NULL
) {
Py_DECREF
(
list
);
Error_set
(
GIT_ENOTFOUND
);
return
NULL
;
}
err
=
git_commit_lookup
(
&
parent
,
py_repo
->
repo
,
parent_oid
);
if
(
err
<
0
) {
Py_DECREF
(
list
);
return
Error_set_oid
(
err
,
parent_oid
,
GIT_OID_HEXSZ
);
}
py_parent
=
wrap_object
((
git_object
*
)
parent
,
py_repo
,
NULL
);
if
(
py_parent
==
NULL
) {
Py_DECREF
(
list
);
return
NULL
;
}
PyList_SET_ITEM
(
list
,
i
,
py_parent
);
}
return
list
;
}
PyDoc_STRVAR
(
Commit_parent_ids__doc__
,
"The list of parent commits' ids."
);
PyObject
*
Commit_parent_ids__get__
(
Commit
*
self
)
{
unsigned
int
i
,
parent_count
;
const
git_oid
*
id
;
PyObject
*
list
;
if
(
Object__load
((
Object
*
)
self
)
==
NULL
) {
return
NULL
; }
// Lazy load
parent_count
=
git_commit_parentcount
(
self
->
commit
);
list
=
PyList_New
(
parent_count
);
if
(!
list
)
return
NULL
;
for
(
i
=
0
;
i
<
parent_count
;
i
++
) {
id
=
git_commit_parent_id
(
self
->
commit
,
i
);
PyList_SET_ITEM
(
list
,
i
,
git_oid_to_python
(
id
));
}
return
list
;
}
PyGetSetDef
Commit_getseters
[]
=
{
GETTER
(
Commit
,
message_encoding
),
GETTER
(
Commit
,
message
),
GETTER
(
Commit
,
raw_message
),
GETTER
(
Commit
,
commit_time
),
GETTER
(
Commit
,
commit_time_offset
),
GETTER
(
Commit
,
committer
),
GETTER
(
Commit
,
author
),
GETTER
(
Commit
,
gpg_signature
),
GETTER
(
Commit
,
tree
),
GETTER
(
Commit
,
tree_id
),
GETTER
(
Commit
,
parents
),
GETTER
(
Commit
,
parent_ids
),
GETTER
(
Commit
,
message_trailers
),
{
NULL
}
};
PyDoc_STRVAR
(
Commit__doc__
,
"Commit objects."
);
PyTypeObject
CommitType
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_pygit2.Commit"
,
/* tp_name */
sizeof
(
Commit
),
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
(
reprfunc
)
Object_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
,
/* tp_flags */
Commit__doc__
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_members */
Commit_getseters
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_new */
};
Back
|
FazBrowse Home
|
New Git URL