Skip to content

Commit b7f1468

Browse files
committed
swap blamed-file and original-file variable names.
They are used with inverse meaning compared to the current documentation. It's easier to adjust the variable names.
1 parent b736ace commit b7f1468

File tree

7 files changed

+82
-85
lines changed

7 files changed

+82
-85
lines changed

gitoxide-core/src/repository/blame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn write_blame_entries(mut out: impl std::io::Write, outcome: gix::blame::Outcom
3131
for (entry, lines_in_hunk) in outcome.entries_with_lines() {
3232
for ((actual_lno, source_lno), line) in entry
3333
.range_in_blamed_file
34-
.zip(entry.range_in_original_file)
34+
.zip(entry.range_in_source_file)
3535
.zip(lines_in_hunk)
3636
{
3737
write!(

gix-blame/src/file/function.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use std::ops::Range;
2929
/// *For brevity, `HEAD` denotes the starting point of the blame operation. It could be any commit, or even commits that
3030
/// represent the worktree state.
3131
/// We begin with a single *Unblamed Hunk* and a single suspect, usually the `HEAD` commit as the commit containing the
32-
/// *Original File*, so that it contains the entire file, with the first commit being a candidate for the entire *Original File*.
32+
/// *Blamed File*, so that it contains the entire file, with the first commit being a candidate for the entire *Blamed File*.
3333
/// We traverse the commit graph starting at the first suspect, and see if there have been changes to `file_path`.
34-
/// If so, we have found a *Blamed File* and a *Suspect* commit, and have hunks that represent these changes.
34+
/// If so, we have found a *Source File* and a *Suspect* commit, and have hunks that represent these changes.
3535
/// Now the *Unblamed Hunk* is split at the boundaries of each matching change, creating a new *Unblamed Hunk* on each side,
3636
/// along with a [`BlameEntry`] to represent the match.
3737
/// This is repeated until there are no non-empty *Unblamed Hunk*s left.
@@ -69,22 +69,22 @@ where
6969

7070
let mut stats = Statistics::default();
7171
let (mut buf, mut buf2, mut buf3) = (Vec::new(), Vec::new(), Vec::new());
72-
let original_file_entry = find_path_entry_in_commit(&odb, &suspect, file_path, &mut buf, &mut buf2, &mut stats)?
72+
let blamed_file_entry = find_path_entry_in_commit(&odb, &suspect, file_path, &mut buf, &mut buf2, &mut stats)?
7373
.ok_or_else(|| Error::FileMissing {
7474
file_path: file_path.to_owned(),
7575
commit_id: suspect,
7676
})?;
77-
let original_file_blob = odb.find_blob(&original_file_entry.oid, &mut buf)?.data.to_vec();
78-
let num_lines_in_original = {
79-
let mut interner = gix_diff::blob::intern::Interner::new(original_file_blob.len() / 100);
80-
tokens_for_diffing(&original_file_blob)
77+
let blamed_file_blob = odb.find_blob(&blamed_file_entry.oid, &mut buf)?.data.to_vec();
78+
let num_lines_in_blamed = {
79+
let mut interner = gix_diff::blob::intern::Interner::new(blamed_file_blob.len() / 100);
80+
tokens_for_diffing(&blamed_file_blob)
8181
.tokenize()
8282
.map(|token| interner.intern(token))
8383
.count()
8484
};
8585

8686
let mut hunks_to_blame = vec![UnblamedHunk::new(
87-
0..num_lines_in_original as u32,
87+
0..num_lines_in_blamed as u32,
8888
suspect,
8989
Offset::Added(0),
9090
)];
@@ -194,7 +194,7 @@ where
194194
out.sort_by(|a, b| a.range_in_blamed_file.start.cmp(&b.range_in_blamed_file.start));
195195
Ok(Outcome {
196196
entries: coalesce_blame_entries(out),
197-
blob: original_file_blob,
197+
blob: blamed_file_blob,
198198
statistics: stats,
199199
})
200200
}
@@ -218,7 +218,7 @@ fn unblamed_to_out(hunks_to_blame: &mut Vec<UnblamedHunk>, out: &mut Vec<BlameEn
218218
}
219219

220220
/// This function merges adjacent blame entries. It merges entries that are adjacent both in the
221-
/// blamed file and in the original file that introduced them. This follows `git`’s
221+
/// blamed file and in the source file that introduced them. This follows `git`’s
222222
/// behaviour. `libgit2`, as of 2024-09-19, only checks whether two entries are adjacent in the
223223
/// blamed file which can result in different blames in certain edge cases. See [the commit][1]
224224
/// that introduced the extra check into `git` for context. See [this commit][2] for a way to test
@@ -237,12 +237,11 @@ fn coalesce_blame_entries(lines_blamed: Vec<BlameEntry>) -> Vec<BlameEntry> {
237237
if previous_entry.commit_id == entry.commit_id
238238
&& previous_entry.range_in_blamed_file.end == entry.range_in_blamed_file.start
239239
// As of 2024-09-19, the check below only is in `git`, but not in `libgit2`.
240-
&& previous_entry.range_in_original_file.end == entry.range_in_original_file.start
240+
&& previous_entry.range_in_source_file.end == entry.range_in_source_file.start
241241
{
242242
let coalesced_entry = BlameEntry {
243243
range_in_blamed_file: previous_entry.range_in_blamed_file.start..entry.range_in_blamed_file.end,
244-
range_in_original_file: previous_entry.range_in_original_file.start
245-
..entry.range_in_original_file.end,
244+
range_in_source_file: previous_entry.range_in_source_file.start..entry.range_in_source_file.end,
246245
commit_id: previous_entry.commit_id,
247246
};
248247

@@ -304,7 +303,7 @@ fn blob_changes(
304303
file_path: &BStr,
305304
stats: &mut Statistics,
306305
) -> Result<Vec<Change>, Error> {
307-
/// Record all [`Change`]s to learn about additions, deletions and unchanged portions of a *Blamed File*.
306+
/// Record all [`Change`]s to learn about additions, deletions and unchanged portions of a *Source File*.
308307
struct ChangeRecorder {
309308
last_seen_after_end: u32,
310309
hunks: Vec<Change>,

gix-blame/src/file/mod.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::types::{Change, Offset, UnblamedHunk};
88

99
pub(super) mod function;
1010

11-
/// Compare a section from the *Original File* (`hunk`) with a change from a diff and see if there
11+
/// Compare a section from the *Blamed File* (`hunk`) with a change from a diff and see if there
1212
/// is an intersection with `change`. Based on that intersection, we may generate a [`BlameEntry`] for `out`
1313
/// and/or split the `hunk` into multiple.
1414
///
15-
/// This is the core of the blame implementation as it matches regions in *Blamed Files* to the *Original File*.
15+
/// This is the core of the blame implementation as it matches regions in *Source File* to the *Blamed File*.
1616
fn process_change(
1717
out: &mut Vec<BlameEntry>,
1818
new_hunks_to_blame: &mut Vec<UnblamedHunk>,
@@ -407,45 +407,44 @@ impl UnblamedHunk {
407407
}
408408

409409
impl BlameEntry {
410-
/// Create a new instance by creating `range_in_blamed_file` after applying `offset` to `range_in_original_file`.
411-
fn with_offset(range_in_original_file: Range<u32>, commit_id: ObjectId, offset: Offset) -> Self {
410+
/// Create a new instance by creating `range_in_blamed_file` after applying `offset` to `range_in_source_file`.
411+
fn with_offset(range_in_source_file: Range<u32>, commit_id: ObjectId, offset: Offset) -> Self {
412412
debug_assert!(
413-
range_in_original_file.end > range_in_original_file.start,
414-
"{range_in_original_file:?}"
413+
range_in_source_file.end > range_in_source_file.start,
414+
"{range_in_source_file:?}"
415415
);
416416

417417
match offset {
418418
Offset::Added(added) => Self {
419-
range_in_blamed_file: (range_in_original_file.start + added)..(range_in_original_file.end + added),
420-
range_in_original_file,
419+
range_in_blamed_file: (range_in_source_file.start + added)..(range_in_source_file.end + added),
420+
range_in_source_file,
421421
commit_id,
422422
},
423423
Offset::Deleted(deleted) => {
424424
debug_assert!(
425-
range_in_original_file.start >= deleted,
426-
"{range_in_original_file:?} {offset:?}"
425+
range_in_source_file.start >= deleted,
426+
"{range_in_source_file:?} {offset:?}"
427427
);
428428

429429
Self {
430-
range_in_blamed_file: (range_in_original_file.start - deleted)
431-
..(range_in_original_file.end - deleted),
432-
range_in_original_file,
430+
range_in_blamed_file: (range_in_source_file.start - deleted)..(range_in_source_file.end - deleted),
431+
range_in_source_file,
433432
commit_id,
434433
}
435434
}
436435
}
437436
}
438437

439-
/// Create an offset from a portion of the *Original File*.
438+
/// Create an offset from a portion of the *Blamed File*.
440439
fn from_unblamed_hunk(mut unblamed_hunk: UnblamedHunk, commit_id: ObjectId) -> Self {
441-
let range_in_original_file = unblamed_hunk
440+
let range_in_source_file = unblamed_hunk
442441
.suspects
443442
.remove(&commit_id)
444443
.expect("Private and only called when we now `commit_id` is in the suspect list");
445444

446445
Self {
447446
range_in_blamed_file: unblamed_hunk.range_in_blamed_file,
448-
range_in_original_file,
447+
range_in_source_file,
449448
commit_id,
450449
}
451450
}

0 commit comments

Comments
 (0)