diff --git a/gitoxide-core/src/repository/blame.rs b/gitoxide-core/src/repository/blame.rs index d33d34f3c4a..1001df0c7fe 100644 --- a/gitoxide-core/src/repository/blame.rs +++ b/gitoxide-core/src/repository/blame.rs @@ -31,7 +31,7 @@ fn write_blame_entries(mut out: impl std::io::Write, outcome: gix::blame::Outcom for (entry, lines_in_hunk) in outcome.entries_with_lines() { for ((actual_lno, source_lno), line) in entry .range_in_blamed_file - .zip(entry.range_in_original_file) + .zip(entry.range_in_source_file) .zip(lines_in_hunk) { write!( diff --git a/gix-blame/src/file/function.rs b/gix-blame/src/file/function.rs index 0a18ee60e96..3729ed0e905 100644 --- a/gix-blame/src/file/function.rs +++ b/gix-blame/src/file/function.rs @@ -29,9 +29,9 @@ use std::ops::Range; /// *For brevity, `HEAD` denotes the starting point of the blame operation. It could be any commit, or even commits that /// represent the worktree state. /// We begin with a single *Unblamed Hunk* and a single suspect, usually the `HEAD` commit as the commit containing the -/// *Original File*, so that it contains the entire file, with the first commit being a candidate for the entire *Original File*. +/// *Blamed File*, so that it contains the entire file, with the first commit being a candidate for the entire *Blamed File*. /// We traverse the commit graph starting at the first suspect, and see if there have been changes to `file_path`. -/// If so, we have found a *Blamed File* and a *Suspect* commit, and have hunks that represent these changes. +/// If so, we have found a *Source File* and a *Suspect* commit, and have hunks that represent these changes. /// Now the *Unblamed Hunk* is split at the boundaries of each matching change, creating a new *Unblamed Hunk* on each side, /// along with a [`BlameEntry`] to represent the match. /// This is repeated until there are no non-empty *Unblamed Hunk*s left. @@ -69,22 +69,22 @@ where let mut stats = Statistics::default(); let (mut buf, mut buf2, mut buf3) = (Vec::new(), Vec::new(), Vec::new()); - let original_file_entry = find_path_entry_in_commit(&odb, &suspect, file_path, &mut buf, &mut buf2, &mut stats)? + let blamed_file_entry = find_path_entry_in_commit(&odb, &suspect, file_path, &mut buf, &mut buf2, &mut stats)? .ok_or_else(|| Error::FileMissing { file_path: file_path.to_owned(), commit_id: suspect, })?; - let original_file_blob = odb.find_blob(&original_file_entry.oid, &mut buf)?.data.to_vec(); - let num_lines_in_original = { - let mut interner = gix_diff::blob::intern::Interner::new(original_file_blob.len() / 100); - tokens_for_diffing(&original_file_blob) + let blamed_file_blob = odb.find_blob(&blamed_file_entry.oid, &mut buf)?.data.to_vec(); + let num_lines_in_blamed = { + let mut interner = gix_diff::blob::intern::Interner::new(blamed_file_blob.len() / 100); + tokens_for_diffing(&blamed_file_blob) .tokenize() .map(|token| interner.intern(token)) .count() }; let mut hunks_to_blame = vec![UnblamedHunk::new( - 0..num_lines_in_original as u32, + 0..num_lines_in_blamed as u32, suspect, Offset::Added(0), )]; @@ -194,7 +194,7 @@ where out.sort_by(|a, b| a.range_in_blamed_file.start.cmp(&b.range_in_blamed_file.start)); Ok(Outcome { entries: coalesce_blame_entries(out), - blob: original_file_blob, + blob: blamed_file_blob, statistics: stats, }) } @@ -218,7 +218,7 @@ fn unblamed_to_out(hunks_to_blame: &mut Vec, out: &mut Vec) -> Vec { if previous_entry.commit_id == entry.commit_id && previous_entry.range_in_blamed_file.end == entry.range_in_blamed_file.start // As of 2024-09-19, the check below only is in `git`, but not in `libgit2`. - && previous_entry.range_in_original_file.end == entry.range_in_original_file.start + && previous_entry.range_in_source_file.end == entry.range_in_source_file.start { let coalesced_entry = BlameEntry { range_in_blamed_file: previous_entry.range_in_blamed_file.start..entry.range_in_blamed_file.end, - range_in_original_file: previous_entry.range_in_original_file.start - ..entry.range_in_original_file.end, + range_in_source_file: previous_entry.range_in_source_file.start..entry.range_in_source_file.end, commit_id: previous_entry.commit_id, }; @@ -304,7 +303,7 @@ fn blob_changes( file_path: &BStr, stats: &mut Statistics, ) -> Result, Error> { - /// Record all [`Change`]s to learn about additions, deletions and unchanged portions of a *Blamed File*. + /// Record all [`Change`]s to learn about additions, deletions and unchanged portions of a *Source File*. struct ChangeRecorder { last_seen_after_end: u32, hunks: Vec, diff --git a/gix-blame/src/file/mod.rs b/gix-blame/src/file/mod.rs index 52a5f67a6f1..24953ba8784 100644 --- a/gix-blame/src/file/mod.rs +++ b/gix-blame/src/file/mod.rs @@ -8,11 +8,11 @@ use crate::types::{Change, Offset, UnblamedHunk}; pub(super) mod function; -/// Compare a section from the *Original File* (`hunk`) with a change from a diff and see if there +/// Compare a section from the *Blamed File* (`hunk`) with a change from a diff and see if there /// is an intersection with `change`. Based on that intersection, we may generate a [`BlameEntry`] for `out` /// and/or split the `hunk` into multiple. /// -/// This is the core of the blame implementation as it matches regions in *Blamed Files* to the *Original File*. +/// This is the core of the blame implementation as it matches regions in *Source File* to the *Blamed File*. fn process_change( out: &mut Vec, new_hunks_to_blame: &mut Vec, @@ -407,45 +407,44 @@ impl UnblamedHunk { } impl BlameEntry { - /// Create a new instance by creating `range_in_blamed_file` after applying `offset` to `range_in_original_file`. - fn with_offset(range_in_original_file: Range, commit_id: ObjectId, offset: Offset) -> Self { + /// Create a new instance by creating `range_in_blamed_file` after applying `offset` to `range_in_source_file`. + fn with_offset(range_in_source_file: Range, commit_id: ObjectId, offset: Offset) -> Self { debug_assert!( - range_in_original_file.end > range_in_original_file.start, - "{range_in_original_file:?}" + range_in_source_file.end > range_in_source_file.start, + "{range_in_source_file:?}" ); match offset { Offset::Added(added) => Self { - range_in_blamed_file: (range_in_original_file.start + added)..(range_in_original_file.end + added), - range_in_original_file, + range_in_blamed_file: (range_in_source_file.start + added)..(range_in_source_file.end + added), + range_in_source_file, commit_id, }, Offset::Deleted(deleted) => { debug_assert!( - range_in_original_file.start >= deleted, - "{range_in_original_file:?} {offset:?}" + range_in_source_file.start >= deleted, + "{range_in_source_file:?} {offset:?}" ); Self { - range_in_blamed_file: (range_in_original_file.start - deleted) - ..(range_in_original_file.end - deleted), - range_in_original_file, + range_in_blamed_file: (range_in_source_file.start - deleted)..(range_in_source_file.end - deleted), + range_in_source_file, commit_id, } } } } - /// Create an offset from a portion of the *Original File*. + /// Create an offset from a portion of the *Blamed File*. fn from_unblamed_hunk(mut unblamed_hunk: UnblamedHunk, commit_id: ObjectId) -> Self { - let range_in_original_file = unblamed_hunk + let range_in_source_file = unblamed_hunk .suspects .remove(&commit_id) .expect("Private and only called when we now `commit_id` is in the suspect list"); Self { range_in_blamed_file: unblamed_hunk.range_in_blamed_file, - range_in_original_file, + range_in_source_file, commit_id, } } diff --git a/gix-blame/src/file/tests.rs b/gix-blame/src/file/tests.rs index 35e63d6edd4..f01e7c8034f 100644 --- a/gix-blame/src/file/tests.rs +++ b/gix-blame/src/file/tests.rs @@ -70,7 +70,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 0..3, - range_in_original_file: 0..3, + range_in_source_file: 0..3, commit_id: suspect }] ); @@ -106,7 +106,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 2..3, - range_in_original_file: 2..3, + range_in_source_file: 2..3, commit_id: suspect }] ); @@ -148,7 +148,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 12..13, - range_in_original_file: 12..13, + range_in_source_file: 12..13, commit_id: suspect }] ); @@ -191,7 +191,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 14..15, - range_in_original_file: 9..10, + range_in_source_file: 9..10, commit_id: suspect }] ); @@ -233,7 +233,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 0..3, - range_in_original_file: 0..3, + range_in_source_file: 0..3, commit_id: suspect }] ); @@ -270,7 +270,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 1..4, - range_in_original_file: 0..3, + range_in_source_file: 0..3, commit_id: suspect }] ); @@ -307,7 +307,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 4..6, - range_in_original_file: 3..5, + range_in_source_file: 3..5, commit_id: suspect }] ); @@ -344,7 +344,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 23..24, - range_in_original_file: 25..26, + range_in_source_file: 25..26, commit_id: suspect }] ); @@ -375,7 +375,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 23..24, - range_in_original_file: 21..22, + range_in_source_file: 21..22, commit_id: suspect }] ); @@ -406,7 +406,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 107..109, - range_in_original_file: 106..108, + range_in_source_file: 106..108, commit_id: suspect }] ); @@ -443,7 +443,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 155..156, - range_in_original_file: 143..144, + range_in_source_file: 143..144, commit_id: suspect }] ); @@ -660,7 +660,7 @@ mod process_change { lines_blamed, [BlameEntry { range_in_blamed_file: 2..5, - range_in_original_file: 5..8, + range_in_source_file: 5..8, commit_id: suspect }] ); @@ -1011,7 +1011,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 0..4, - range_in_original_file: 0..4, + range_in_source_file: 0..4, commit_id: suspect }] ); @@ -1030,7 +1030,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 0..4, - range_in_original_file: 0..4, + range_in_source_file: 0..4, commit_id: suspect }] ); @@ -1049,7 +1049,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 2..4, - range_in_original_file: 2..4, + range_in_source_file: 2..4, commit_id: suspect }] ); @@ -1075,12 +1075,12 @@ mod process_changes { [ BlameEntry { range_in_blamed_file: 0..1, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect }, BlameEntry { range_in_blamed_file: 1..4, - range_in_original_file: 1..4, + range_in_source_file: 1..4, commit_id: suspect } ] @@ -1100,7 +1100,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 0..1, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect }] ); @@ -1113,7 +1113,7 @@ mod process_changes { let suspect_2 = ObjectId::from_hex(b"2222222222222222222222222222222222222222").unwrap(); let mut lines_blamed: Vec = vec![BlameEntry { range_in_blamed_file: 0..2, - range_in_original_file: 0..2, + range_in_source_file: 0..2, commit_id: suspect, }]; let hunks_to_blame = vec![new_unblamed_hunk(2..6, suspect_2, Offset::Added(2))]; @@ -1125,12 +1125,12 @@ mod process_changes { [ BlameEntry { range_in_blamed_file: 0..2, - range_in_original_file: 0..2, + range_in_source_file: 0..2, commit_id: suspect }, BlameEntry { range_in_blamed_file: 2..3, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect_2 } ] @@ -1153,7 +1153,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 0..4, - range_in_original_file: 0..4, + range_in_source_file: 0..4, commit_id: suspect }] ); @@ -1178,7 +1178,7 @@ mod process_changes { let suspect_2 = ObjectId::from_hex(b"2222222222222222222222222222222222222222").unwrap(); let mut lines_blamed: Vec = vec![BlameEntry { range_in_blamed_file: 0..1, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect, }]; let hunks_to_blame = vec![new_unblamed_hunk(1..3, suspect_2, Offset::Added(1))]; @@ -1190,12 +1190,12 @@ mod process_changes { [ BlameEntry { range_in_blamed_file: 0..1, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect }, BlameEntry { range_in_blamed_file: 1..2, - range_in_original_file: 0..1, + range_in_source_file: 0..1, commit_id: suspect_2 } ] @@ -1219,12 +1219,12 @@ mod process_changes { [ BlameEntry { range_in_blamed_file: 0..2, - range_in_original_file: 0..2, + range_in_source_file: 0..2, commit_id: suspect }, BlameEntry { range_in_blamed_file: 3..4, - range_in_original_file: 3..4, + range_in_source_file: 3..4, commit_id: suspect } ] @@ -1237,7 +1237,7 @@ mod process_changes { let suspect = ObjectId::null(gix_hash::Kind::Sha1); let mut lines_blamed: Vec = vec![BlameEntry { range_in_blamed_file: 30..31, - range_in_original_file: 30..31, + range_in_source_file: 30..31, commit_id: suspect, }]; let hunks_to_blame = vec![ @@ -1264,12 +1264,12 @@ mod process_changes { [ BlameEntry { range_in_blamed_file: 16..17, - range_in_original_file: 16..17, + range_in_source_file: 16..17, commit_id: suspect }, BlameEntry { range_in_blamed_file: 30..31, - range_in_original_file: 30..31, + range_in_source_file: 30..31, commit_id: suspect } ] @@ -1308,7 +1308,7 @@ mod process_changes { lines_blamed, [BlameEntry { range_in_blamed_file: 0..4, - range_in_original_file: 0..4, + range_in_source_file: 0..4, commit_id: suspect }] ); diff --git a/gix-blame/src/lib.rs b/gix-blame/src/lib.rs index c504835e50e..489434b5b3d 100644 --- a/gix-blame/src/lib.rs +++ b/gix-blame/src/lib.rs @@ -2,15 +2,15 @@ //! //! ### Terminology //! -//! * **Original File** +//! * **Source File** //! - The file as it exists in `HEAD`. -//! - the initial state with all lines that we need to associate with a *Blamed File*. +//! - the initial state with all lines that we need to associate with a *Source File*. //! * **Blamed File** //! - A file at a version (i.e. commit) that introduces hunks into the final 'image'. //! * **Suspects** //! - The versions of the files that can contain hunks that we could use in the final 'image' //! - multiple at the same time as the commit-graph may split up. -//! - turns into *Blamed File* once we have found an association into the *Original File*. +//! - turns into *Source File* once we have found an association into the *Blamed File*. #![deny(rust_2018_idioms, missing_docs)] #![forbid(unsafe_code)] diff --git a/gix-blame/src/types.rs b/gix-blame/src/types.rs index 6dea55be399..af1c693e681 100644 --- a/gix-blame/src/types.rs +++ b/gix-blame/src/types.rs @@ -10,10 +10,10 @@ use gix_object::bstr::BString; /// The outcome of [`file()`](crate::file()). #[derive(Debug, Clone)] pub struct Outcome { - /// One entry in sequential order, to associate a hunk in the original file with the commit (and its lines) + /// One entry in sequential order, to associate a hunk in the blamed file with the source commit (and its lines) /// that introduced it. pub entries: Vec, - /// A buffer with the file content of the *Original File*, ready for tokenization. + /// A buffer with the file content of the *Blamed File*, ready for tokenization. pub blob: Vec, /// Additional information about the amount of work performed to produce the blame. pub statistics: Statistics, @@ -60,7 +60,7 @@ impl Outcome { } } -/// Describes the offset of a particular hunk relative to the *Original File*. +/// Describes the offset of a particular hunk relative to the *Blamed File*. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Offset { /// The amount of lines to add. @@ -118,7 +118,7 @@ impl SubAssign for Offset { } } -/// A mapping of a section of the *Original File* to the section in a *Blamed File* that introduced it. +/// A mapping of a section of the *Blamed File* to the section in a *Source File* that introduced it. /// /// Both ranges are of the same size, but may use different [starting points](Range::start). Naturally, /// they have the same content, which is the reason they are in what is returned by [`file()`](crate::file()). @@ -127,29 +127,28 @@ impl SubAssign for Offset { pub struct BlameEntry { /// The section of tokens in the tokenized version of the *Blamed File* (typically lines). pub range_in_blamed_file: Range, - /// The section of tokens in the tokenized version of the *Original File* (typically lines). - // TODO: figure out why this is basically inverted. Probably that's just it - would make sense with `UnblamedHunk` then. - pub range_in_original_file: Range, - /// The commit that introduced the section into the *Blamed File*. + /// The section of tokens in the tokenized version of the *Source File* (typically lines). + pub range_in_source_file: Range, + /// The commit that introduced the section into the *Source File*. pub commit_id: ObjectId, } impl BlameEntry { /// Create a new instance. - pub fn new(range_in_blamed_file: Range, range_in_original_file: Range, commit_id: ObjectId) -> Self { + pub fn new(range_in_blamed_file: Range, range_in_source_file: Range, commit_id: ObjectId) -> Self { debug_assert!( range_in_blamed_file.end > range_in_blamed_file.start, "{range_in_blamed_file:?}" ); debug_assert!( - range_in_original_file.end > range_in_original_file.start, - "{range_in_original_file:?}" + range_in_source_file.end > range_in_source_file.start, + "{range_in_source_file:?}" ); - debug_assert_eq!(range_in_original_file.len(), range_in_blamed_file.len()); + debug_assert_eq!(range_in_source_file.len(), range_in_blamed_file.len()); Self { range_in_blamed_file: range_in_blamed_file.clone(), - range_in_original_file: range_in_original_file.clone(), + range_in_source_file: range_in_source_file.clone(), commit_id, } } @@ -171,7 +170,7 @@ impl LineRange for Range { pub struct UnblamedHunk { /// TODO: figure out how this works. pub range_in_blamed_file: Range, - /// Maps a commit to the range in the *Original File* that `range_in_blamed_file` refers to. + /// Maps a commit to the range in the *Blamed File* that `range_in_blamed_file` refers to. pub suspects: BTreeMap>, } diff --git a/gix-blame/tests/blame.rs b/gix-blame/tests/blame.rs index 73c2597933f..258a3457c4a 100644 --- a/gix-blame/tests/blame.rs +++ b/gix-blame/tests/blame.rs @@ -79,7 +79,7 @@ mod baseline { Err(_) => continue, }; - let line_number_in_original_file = fields[1].parse::().unwrap(); + let line_number_in_source_file = fields[1].parse::().unwrap(); let line_number_in_final_file = fields[2].parse::().unwrap(); // The last field indicates the number of lines this group contains info for // (this is not equal to the number of lines in git blame’s porcelain output). @@ -87,22 +87,22 @@ mod baseline { skip_lines = number_of_lines_in_group; - let original_range = (line_number_in_original_file - 1) - ..(line_number_in_original_file + number_of_lines_in_group - 1); + let source_range = + (line_number_in_source_file - 1)..(line_number_in_source_file + number_of_lines_in_group - 1); let blame_range = (line_number_in_final_file - 1)..(line_number_in_final_file + number_of_lines_in_group - 1); assert!(ranges.is_none(), "should not overwrite existing ranges"); - ranges = Some((blame_range, original_range)); + ranges = Some((blame_range, source_range)); } else if !is_known_header_field(&fields[0]) && ObjectId::from_hex(fields[0].as_bytes()).is_err() { panic!("unexpected line: '{:?}'", line.as_bstr()); } } - let Some((range_in_blamed_file, range_in_original_file)) = ranges else { + let Some((range_in_blamed_file, range_in_source_file)) = ranges else { // No new lines were parsed, so we assume the iterator is finished. return None; }; - Some(BlameEntry::new(range_in_blamed_file, range_in_original_file, commit_id)) + Some(BlameEntry::new(range_in_blamed_file, range_in_source_file, commit_id)) } } }