@@ -10,6 +10,7 @@ use gix_ref::{
10
10
} ;
11
11
use smallvec:: SmallVec ;
12
12
13
+ use crate :: repository:: { new_commit, new_commit_as} ;
13
14
use crate :: { commit, ext:: ObjectIdExt , object, tag, Blob , Commit , Id , Object , Reference , Tag , Tree } ;
14
15
15
16
/// Tree editing
@@ -264,7 +265,7 @@ impl crate::Repository {
264
265
/// Create a tag reference named `name` (without `refs/tags/` prefix) pointing to a newly created tag object
265
266
/// which in turn points to `target` and return the newly created reference.
266
267
///
267
- /// It will be created with `constraint` which is most commonly to [only create it][ PreviousValue::MustNotExist]
268
+ /// It will be created with `constraint` which is most commonly to [only create it]( PreviousValue::MustNotExist)
268
269
/// or to [force overwriting a possibly existing tag](PreviousValue::Any).
269
270
pub fn tag (
270
271
& self ,
@@ -406,37 +407,36 @@ impl crate::Repository {
406
407
self . commit_as ( committer, author, reference, message, tree, parents)
407
408
}
408
409
409
- /// Create a raw commit object with `message` referring to `tree` with `parents`, without writing it to the object database
410
- /// or updating any references. The commit object can later be written using [`Self::write_object()`] .
411
- ///
410
+ /// Create a new commit object with `message` referring to `tree` with `parents`, and write it to the object database.
411
+ /// Do not, however, update any references .
412
+ ///
412
413
/// The commit is created without message encoding field, which can be assumed to be UTF-8.
413
414
/// `author` and `committer` fields are pre-set from the configuration, which can be altered
414
415
/// [temporarily](crate::Repository::config_snapshot_mut()) before the call if required.
415
- pub fn commit_raw (
416
+ pub fn new_commit (
416
417
& self ,
417
418
message : impl AsRef < str > ,
418
419
tree : impl Into < ObjectId > ,
419
420
parents : impl IntoIterator < Item = impl Into < ObjectId > > ,
420
- ) -> Result < gix_object :: Commit , commit :: Error > {
421
- let author = self . author ( ) . ok_or ( commit :: Error :: AuthorMissing ) ??;
422
- let committer = self . committer ( ) . ok_or ( commit :: Error :: CommitterMissing ) ??;
423
- self . commit_as_raw ( committer, author, message, tree, parents)
421
+ ) -> Result < Commit < ' _ > , new_commit :: Error > {
422
+ let author = self . author ( ) . ok_or ( new_commit :: Error :: AuthorMissing ) ??;
423
+ let committer = self . committer ( ) . ok_or ( new_commit :: Error :: CommitterMissing ) ??;
424
+ Ok ( self . new_commit_as ( committer, author, message, tree, parents) ? )
424
425
}
425
426
426
- /// Create a raw commit object with `message` referring to `tree` with `parents`, using the specified
427
- /// `committer` and `author`, without writing it to the object database or updating any references.
428
- /// The commit object can later be written using [`Self::write_object()`].
427
+ /// Create a nwe commit object with `message` referring to `tree` with `parents`, using the specified
428
+ /// `committer` and `author`, and write it to the object database. Do not, however, update any references.
429
429
///
430
430
/// This forces setting the commit time and author time by hand. Note that typically, committer and author are the same.
431
431
/// The commit is created without message encoding field, which can be assumed to be UTF-8.
432
- pub fn commit_as_raw < ' a , ' c > (
432
+ pub fn new_commit_as < ' a , ' c > (
433
433
& self ,
434
434
committer : impl Into < gix_actor:: SignatureRef < ' c > > ,
435
435
author : impl Into < gix_actor:: SignatureRef < ' a > > ,
436
436
message : impl AsRef < str > ,
437
437
tree : impl Into < ObjectId > ,
438
438
parents : impl IntoIterator < Item = impl Into < ObjectId > > ,
439
- ) -> Result < gix_object :: Commit , commit :: Error > {
439
+ ) -> Result < Commit < ' _ > , new_commit_as :: Error > {
440
440
let commit = gix_object:: Commit {
441
441
message : message. as_ref ( ) . into ( ) ,
442
442
tree : tree. into ( ) ,
@@ -446,7 +446,8 @@ impl crate::Repository {
446
446
parents : parents. into_iter ( ) . map ( Into :: into) . collect ( ) ,
447
447
extra_headers : Default :: default ( ) ,
448
448
} ;
449
- Ok ( commit)
449
+ let id = self . write_object ( commit) ?;
450
+ Ok ( id. object ( ) ?. into_commit ( ) )
450
451
}
451
452
452
453
/// Return an empty tree object, suitable for [getting changes](Tree::changes()).
0 commit comments