File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -2359,6 +2359,17 @@ extern "C" {
2359
2359
parent_count : size_t ,
2360
2360
parents : * mut * const git_commit ,
2361
2361
) -> c_int ;
2362
+ pub fn git_commit_create_buffer (
2363
+ out : * mut git_buf ,
2364
+ repo : * mut git_repository ,
2365
+ author : * const git_signature ,
2366
+ committer : * const git_signature ,
2367
+ message_encoding : * const c_char ,
2368
+ message : * const c_char ,
2369
+ tree : * const git_tree ,
2370
+ parent_count : size_t ,
2371
+ parents : * mut * const git_commit ,
2372
+ ) -> c_int ;
2362
2373
pub fn git_commit_header_field (
2363
2374
out : * mut git_buf ,
2364
2375
commit : * const git_commit ,
Original file line number Diff line number Diff line change @@ -1089,6 +1089,40 @@ impl Repository {
1089
1089
}
1090
1090
}
1091
1091
1092
+ /// Create a commit object and return that as a string.
1093
+ ///
1094
+ /// This string is suitable to be passed to the `commit_signed` function,
1095
+ /// the arguments behave the same as in the `commit` function.
1096
+ pub fn commit_create_buffer (
1097
+ & self ,
1098
+ author : & Signature < ' _ > ,
1099
+ committer : & Signature < ' _ > ,
1100
+ message : & str ,
1101
+ tree : & Tree < ' _ > ,
1102
+ parents : & [ & Commit < ' _ > ] ,
1103
+ ) -> Result < String , Error > {
1104
+ let mut parent_ptrs = parents
1105
+ . iter ( )
1106
+ . map ( |p| p. raw ( ) as * const raw:: git_commit )
1107
+ . collect :: < Vec < _ > > ( ) ;
1108
+ let message = CString :: new ( message) ?;
1109
+ let buf = Buf :: new ( ) ;
1110
+ unsafe {
1111
+ try_call ! ( raw:: git_commit_create_buffer(
1112
+ buf. raw( ) ,
1113
+ self . raw( ) ,
1114
+ author. raw( ) ,
1115
+ committer. raw( ) ,
1116
+ ptr:: null( ) ,
1117
+ message,
1118
+ tree. raw( ) ,
1119
+ parents. len( ) as size_t,
1120
+ parent_ptrs. as_mut_ptr( )
1121
+ ) ) ;
1122
+ Ok ( str:: from_utf8 ( & buf) . unwrap ( ) . to_string ( ) )
1123
+ }
1124
+ }
1125
+
1092
1126
/// Create a commit object from the given buffer and signature
1093
1127
///
1094
1128
/// Given the unsigned commit object's contents, its signature and the
You can’t perform that action at this time.
0 commit comments