summaryrefslogtreecommitdiffstats
path: root/vendor/git2/src/blame.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/git2/src/blame.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/git2/src/blame.rs')
-rw-r--r--vendor/git2/src/blame.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/vendor/git2/src/blame.rs b/vendor/git2/src/blame.rs
index 496efa923..4bf41fed1 100644
--- a/vendor/git2/src/blame.rs
+++ b/vendor/git2/src/blame.rs
@@ -1,9 +1,11 @@
use crate::util::{self, Binding};
-use crate::{raw, signature, Oid, Repository, Signature};
-use std::marker;
+use crate::{raw, signature, Error, Oid, Repository, Signature};
+use libc::c_char;
+use std::iter::FusedIterator;
use std::mem;
use std::ops::Range;
use std::path::Path;
+use std::{marker, ptr};
/// Opaque structure to hold blame results.
pub struct Blame<'repo> {
@@ -29,6 +31,24 @@ pub struct BlameIter<'blame> {
}
impl<'repo> Blame<'repo> {
+ /// Get blame data for a file that has been modified in memory.
+ ///
+ /// Lines that differ between the buffer and the committed version are
+ /// marked as having a zero OID for their final_commit_id.
+ pub fn blame_buffer(&self, buffer: &[u8]) -> Result<Blame<'_>, Error> {
+ let mut raw = ptr::null_mut();
+
+ unsafe {
+ try_call!(raw::git_blame_buffer(
+ &mut raw,
+ self.raw,
+ buffer.as_ptr() as *const c_char,
+ buffer.len()
+ ));
+ Ok(Binding::from_raw(raw))
+ }
+ }
+
/// Gets the number of hunks that exist in the blame structure.
pub fn len(&self) -> usize {
unsafe { raw::git_blame_get_hunk_count(self.raw) as usize }
@@ -307,6 +327,8 @@ impl<'blame> DoubleEndedIterator for BlameIter<'blame> {
}
}
+impl<'blame> FusedIterator for BlameIter<'blame> {}
+
impl<'blame> ExactSizeIterator for BlameIter<'blame> {}
#[cfg(test)]
@@ -345,6 +367,13 @@ mod tests {
assert_eq!(hunk.final_start_line(), 1);
assert_eq!(hunk.path(), Some(Path::new("foo/bar")));
assert_eq!(hunk.lines_in_hunk(), 0);
- assert!(!hunk.is_boundary())
+ assert!(!hunk.is_boundary());
+
+ let blame_buffer = blame.blame_buffer("\n".as_bytes()).unwrap();
+ let line = blame_buffer.get_line(1).unwrap();
+
+ assert_eq!(blame_buffer.len(), 2);
+ assert_eq!(blame_buffer.iter().count(), 2);
+ assert!(line.final_commit_id().is_zero());
}
}