| @@ -124,21 +124,13 @@ impl crate::Repository { · 123 unmodified lines |
| 124 | self.tag_reference(name, tag_id, constraint).map_err(Into::into) | 124 | self.tag_reference(name, tag_id, constraint).map_err(Into::into) |
| 125 | } | 125 | } |
| 126 | | 126 | |
| 127 | /// Create a new commit object with `message` referring to `tree` with `parents`, and point `reference` | 127 | /// Similar to [`commit(…)`][crate::Repository::commit()], but allows to create the commit with `committer` and `author` specified. |
| 128 | /// to it. The commit is written without message encoding field, which can be assumed to be UTF-8. | | |
| 129 | /// `author` and `committer` fields are pre-set from the configuration, which can be altered | | |
| 130 | /// [temporarily][crate::Repository::config_snapshot_mut()] before the call if required. | | |
| 131 | /// | | |
| 132 | /// `reference` will be created if it doesn't exist, and can be `"HEAD"` to automatically write-through to the symbolic reference | | |
| 133 | /// that `HEAD` points to if it is not detached. For this reason, detached head states cannot be created unless the `HEAD` is detached | | |
| 134 | /// already. The reflog will be written as canonical git would do, like `<operation> (<detail>): <summary>`. | | |
| 135 | /// | | |
| 136 | /// The first parent id in `parents` is expected to be the current target of `reference` and the operation will fail if it is not. | | |
| 137 | /// If there is no parent, the `reference` is expected to not exist yet. | | |
| 138 | /// | 128 | /// |
| 139 | /// The method fails immediately if a `reference` lock can't be acquired. | 129 | /// This forces setting the commit time and author time by hand. Note that typically, committer and author are the same. |
| 140 | pub fn commit<Name, E>( | 130 | pub fn commit_as<'a, 'c, Name, E>( |
| 141 | &self, | 131 | &self, |
| | 132 | committer: impl Into<git_actor::SignatureRef<'c>>, |
| | 133 | author: impl Into<git_actor::SignatureRef<'a>>, |
| 142 | reference: Name, | 134 | reference: Name, |
| 143 | message: impl AsRef<str>, | 135 | message: impl AsRef<str>, |
| 144 | tree: impl Into<ObjectId>, | 136 | tree: impl Into<ObjectId>, |
| @@ -156,13 +148,11 @@ impl crate::Repository { · 11 unmodified lines |
| 156 | // TODO: possibly use CommitRef to save a few allocations (but will have to allocate for object ids anyway. | 148 | // TODO: possibly use CommitRef to save a few allocations (but will have to allocate for object ids anyway. |
| 157 | // This can be made vastly more efficient though if we wanted to, so we lie in the API | 149 | // This can be made vastly more efficient though if we wanted to, so we lie in the API |
| 158 | let reference = reference.try_into()?; | 150 | let reference = reference.try_into()?; |
| 159 | let author = self.author_or_default(); | | |
| 160 | let committer = self.committer_or_default(); | | |
| 161 | let commit = git_object::Commit { | 151 | let commit = git_object::Commit { |
| 162 | message: message.as_ref().into(), | 152 | message: message.as_ref().into(), |
| 163 | tree: tree.into(), | 153 | tree: tree.into(), |
| 164 | author: author.to_owned(), | 154 | author: author.into().to_owned(), |
| 165 | committer: committer.to_owned(), | 155 | committer: committer.into().to_owned(), |
| 166 | encoding: None, | 156 | encoding: None, |
| 167 | parents: parents.into_iter().map(|id| id.into()).collect(), | 157 | parents: parents.into_iter().map(|id| id.into()).collect(), |
| 168 | extra_headers: Default::default(), | 158 | extra_headers: Default::default(), |
| @@ -194,6 +184,35 @@ impl crate::Repository { · 25 unmodified lines |
| 194 | Ok(commit_id) | 184 | Ok(commit_id) |
| 195 | } | 185 | } |
| 196 | | 186 | |
| | 187 | /// Create a new commit object with `message` referring to `tree` with `parents`, and point `reference` |
| | 188 | /// to it. The commit is written without message encoding field, which can be assumed to be UTF-8. |
| | 189 | /// `author` and `committer` fields are pre-set from the configuration, which can be altered |
| | 190 | /// [temporarily][crate::Repository::config_snapshot_mut()] before the call if required. |
| | 191 | /// |
| | 192 | /// `reference` will be created if it doesn't exist, and can be `"HEAD"` to automatically write-through to the symbolic reference |
| | 193 | /// that `HEAD` points to if it is not detached. For this reason, detached head states cannot be created unless the `HEAD` is detached |
| | 194 | /// already. The reflog will be written as canonical git would do, like `<operation> (<detail>): <summary>`. |
| | 195 | /// |
| | 196 | /// The first parent id in `parents` is expected to be the current target of `reference` and the operation will fail if it is not. |
| | 197 | /// If there is no parent, the `reference` is expected to not exist yet. |
| | 198 | /// |
| | 199 | /// The method fails immediately if a `reference` lock can't be acquired. |
| | 200 | pub fn commit<Name, E>( |
| | 201 | &self, |
| | 202 | reference: Name, |
| | 203 | message: impl AsRef<str>, |
| | 204 | tree: impl Into<ObjectId>, |
| | 205 | parents: impl IntoIterator<Item = impl Into<ObjectId>>, |
| | 206 | ) -> Result<Id<'_>, commit::Error> |
| | 207 | where |
| | 208 | Name: TryInto<FullName, Error = E>, |
| | 209 | commit::Error: From<E>, |
| | 210 | { |
| | 211 | let author = self.author_or_default(); |
| | 212 | let committer = self.committer_or_default(); |
| | 213 | self.commit_as(committer, author, reference, message, tree, parents) |
| | 214 | } |
| | 215 | |
| 197 | /// Return an empty tree object, suitable for [getting changes](crate::Tree::changes()). | 216 | /// Return an empty tree object, suitable for [getting changes](crate::Tree::changes()). |
| 198 | /// | 217 | /// |
| 199 | /// Note that it is special and doesn't physically exist in the object database even though it can be returned. | 218 | /// Note that it is special and doesn't physically exist in the object database even though it can be returned. |