Skip to content

Commit

Permalink
Add file and hunk deletion filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tapishr committed Nov 1, 2023
1 parent 9da8060 commit 650f6ed
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions vibi-dpu/src/utils/gitops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,22 @@ pub fn get_excluded_files(review: &Review) -> Option<(Vec<StatItem>, Vec<StatIte

fn process_statoutput(statstr: &str) -> Option<(Vec<StatItem>, Vec<StatItem>)>{
let statvec = process_statitems(statstr);
let mut bigfiles = Vec::<StatItem>::new();
let mut smallfiles = Vec::<StatItem>::new();
let mut excluded_files = Vec::<StatItem>::new();
let mut filtered_files = Vec::<StatItem>::new();
let line_threshold = 500;
for item in statvec {
// logic for exclusion
if (item.additions > line_threshold) ||
(item.deletions > line_threshold) ||
(item.additions + item.deletions > line_threshold) {
bigfiles.push(item);
(item.additions + item.deletions > line_threshold) ||
(item.deletions < 1) {
excluded_files.push(item);
}
else {
smallfiles.push(item);
filtered_files.push(item);
}
}
return Some((bigfiles, smallfiles));
return Some((excluded_files, filtered_files));
}

fn generate_statitem(statitems: &Vec<&str>) -> StatItem {
Expand Down Expand Up @@ -253,7 +254,9 @@ fn process_diff(filepath: &str, diff: &str, linemap: &mut HashMap<String, Vec<St
let mut limiterpos = Vec::new();
let delimitter = "@@";
for (idx, _) in diff.match_indices(delimitter) {
limiterpos.push(idx);
if has_deletions(&diff[idx..]) {
limiterpos.push(idx);
}
}
let mut idx: usize = 0;
let len = limiterpos.len();
Expand Down Expand Up @@ -320,6 +323,20 @@ fn process_diff(filepath: &str, diff: &str, linemap: &mut HashMap<String, Vec<St
return linemap.to_owned();
}

fn has_deletions(hunk: &str) -> bool {
// Split the hunk into lines
let lines = hunk.split('\n').collect::<Vec<&str>>();

// Iterate through the lines to check for deletions
for line in lines.iter() {
if line.starts_with('-') && !line.starts_with("---") {
return true;
}
}

return false;
}

pub fn process_diffmap(diffmap: &HashMap<String, String>) -> HashMap<String, Vec<String>> {
let mut linemap: HashMap<String, Vec<String>> = HashMap::new();
for (filepath, diff) in diffmap {
Expand Down

0 comments on commit 650f6ed

Please sign in to comment.