Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/authorship/attribution_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ pub fn attributions_to_line_attributions(
let mut line_authors: Vec<Option<(String, bool)>> = Vec::with_capacity(line_count as usize);

for line_num in 1..=line_count {
let (author, overridden) = find_dominant_author_for_line(line_num, &boundaries, attributions, content);
let (author, overridden) =
find_dominant_author_for_line(line_num, &boundaries, attributions, content);
line_authors.push(Some((author, overridden)));
}

Expand Down Expand Up @@ -979,23 +980,25 @@ fn find_dominant_author_for_line(
.collect::<Vec<String>>();
let last_ai_edit_ts = candidate_attrs
.iter()
.filter(|a | a.author_id != CheckpointKind::Human.to_str())
.filter(|a| a.author_id != CheckpointKind::Human.to_str())
.map(|a| a.ts)
.last();
let last_human_edit_ts = candidate_attrs
.iter()
.filter(|a | a.author_id == CheckpointKind::Human.to_str())
.filter(|a| a.author_id == CheckpointKind::Human.to_str())
.map(|a| a.ts)
.last();
let overridden = match(last_ai_edit_ts, last_human_edit_ts) {
let overridden = match (last_ai_edit_ts, last_human_edit_ts) {
(Some(ai_ts), Some(h_ts)) => h_ts > ai_ts,
_ => false
_ => false,
};
return (latest_author[0].clone(), overridden);
}

/// Merge consecutive lines with the same author into LineAttribution ranges
fn merge_consecutive_line_attributions(line_authorship: Vec<Option<(String, bool)>>) -> Vec<LineAttribution> {
fn merge_consecutive_line_attributions(
line_authorship: Vec<Option<(String, bool)>>,
) -> Vec<LineAttribution> {
let mut result = Vec::new();
let line_count = line_authorship.len();

Expand All @@ -1017,7 +1020,12 @@ fn merge_consecutive_line_attributions(line_authorship: Vec<Option<(String, bool
(Some(_), None) => {
// End current attribution
if let Some(authorship) = current_authorship.take() {
result.push(LineAttribution::new(current_start, line_num - 1, authorship.0, authorship.1));
result.push(LineAttribution::new(
current_start,
line_num - 1,
authorship.0,
authorship.1,
));
}
}
(Some(curr), Some(new_authorship)) => {
Expand All @@ -1029,7 +1037,7 @@ fn merge_consecutive_line_attributions(line_authorship: Vec<Option<(String, bool
current_start,
line_num - 1,
curr.0.clone(),
curr.1.clone()
curr.1.clone(),
));
current_authorship = Some(new_authorship);
current_start = line_num;
Expand Down
1 change: 1 addition & 0 deletions src/authorship/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pub mod range_authorship;
pub mod rebase_authorship;
pub mod stats;
pub mod transcript;
pub mod virtual_attribution;
pub mod working_log;
Loading
Loading