Skip to content

Commit 90c2bb8

Browse files
committed
Add index to BlamePathEntry
1 parent b01d624 commit 90c2bb8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

gix-blame/src/file/function.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ pub fn file(
174174
commit_id: suspect,
175175
blob_id: entry.unwrap_or(ObjectId::null(gix_hash::Kind::Sha1)),
176176
previous_blob_id: ObjectId::null(gix_hash::Kind::Sha1),
177+
index: 0,
177178
};
178179
blame_path.push(blame_path_entry);
179180
}
@@ -263,13 +264,13 @@ pub fn file(
263264
}
264265

265266
let more_than_one_parent = parent_ids.len() > 1;
266-
for (parent_id, parent_commit_time) in parent_ids {
267-
queue.insert(parent_commit_time, parent_id);
267+
for (index, (parent_id, parent_commit_time)) in parent_ids.iter().enumerate() {
268+
queue.insert(*parent_commit_time, *parent_id);
268269
let changes_for_file_path = tree_diff_at_file_path(
269270
&odb,
270271
current_file_path.as_ref(),
271272
suspect,
272-
parent_id,
273+
*parent_id,
273274
cache.as_ref(),
274275
&mut stats,
275276
&mut diff_state,
@@ -284,10 +285,10 @@ pub fn file(
284285
// None of the changes affected the file we’re currently blaming.
285286
// Copy blame to parent.
286287
for unblamed_hunk in &mut hunks_to_blame {
287-
unblamed_hunk.clone_blame(suspect, parent_id);
288+
unblamed_hunk.clone_blame(suspect, *parent_id);
288289
}
289290
} else {
290-
pass_blame_from_to(suspect, parent_id, &mut hunks_to_blame);
291+
pass_blame_from_to(suspect, *parent_id, &mut hunks_to_blame);
291292
}
292293
continue;
293294
};
@@ -306,6 +307,7 @@ pub fn file(
306307
commit_id: suspect,
307308
blob_id: id,
308309
previous_blob_id: ObjectId::null(gix_hash::Kind::Sha1),
310+
index,
309311
};
310312
blame_path.push(blame_path_entry);
311313
}
@@ -327,14 +329,15 @@ pub fn file(
327329
options.diff_algorithm,
328330
&mut stats,
329331
)?;
330-
hunks_to_blame = process_changes(hunks_to_blame, changes, suspect, parent_id);
332+
hunks_to_blame = process_changes(hunks_to_blame, changes, suspect, *parent_id);
331333
if let Some(ref mut blame_path) = blame_path {
332334
let blame_path_entry = BlamePathEntry {
333335
source_file_path: current_file_path.clone(),
334336
previous_source_file_path: Some(current_file_path.clone()),
335337
commit_id: suspect,
336338
blob_id: id,
337339
previous_blob_id: previous_id,
340+
index,
338341
};
339342
blame_path.push(blame_path_entry);
340343
}
@@ -354,7 +357,7 @@ pub fn file(
354357
options.diff_algorithm,
355358
&mut stats,
356359
)?;
357-
hunks_to_blame = process_changes(hunks_to_blame, changes, suspect, parent_id);
360+
hunks_to_blame = process_changes(hunks_to_blame, changes, suspect, *parent_id);
358361

359362
let mut has_blame_been_passed = false;
360363

@@ -374,6 +377,7 @@ pub fn file(
374377
commit_id: suspect,
375378
blob_id: id,
376379
previous_blob_id: source_id,
380+
index,
377381
};
378382
blame_path.push(blame_path_entry);
379383
}

gix-blame/src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ pub struct BlamePathEntry {
173173
pub blob_id: ObjectId,
174174
/// The blob id associated with the state before the change.
175175
pub previous_blob_id: ObjectId,
176+
/// When there is more than one `BlamePathEntry` for a commit, this indicates to which parent
177+
/// commit the change is related.
178+
pub index: usize,
176179
}
177180

178181
/// The outcome of [`file()`](crate::file()).

0 commit comments

Comments
 (0)