Skip to content

Commit e6c8e8d

Browse files
committed
Remove diff marker to avoid false-positives
1 parent ac70dd9 commit e6c8e8d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/gh_range_diff.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashSet;
22
use std::fmt::{self, Write};
3-
use std::sync::Arc;
3+
use std::sync::{Arc, LazyLock};
44

55
use anyhow::Context as _;
66
use axum::{
@@ -18,9 +18,13 @@ use imara_diff::{
1818
Algorithm, Diff, InternedInput, Interner, Token, UnifiedDiffConfig, UnifiedDiffPrinter,
1919
};
2020
use pulldown_cmark_escape::FmtWriter;
21+
use regex::Regex;
2122

2223
use crate::{github, handlers::Context, utils::AppError};
2324

25+
static MARKER_RE: LazyLock<Regex> =
26+
LazyLock::new(|| Regex::new(r"@@ -[\d]+,[\d]+ [+][\d]+,[\d]+ @@").unwrap());
27+
2428
pub async fn gh_range_diff(
2529
Path((owner, repo, basehead)): Path<(String, String, String)>,
2630
State(ctx): State<Arc<Context>>,
@@ -180,8 +184,13 @@ pub async fn gh_range_diff(
180184
)?;
181185

182186
let mut process_diffs = |filename, old_patch, new_patch| -> anyhow::Result<()> {
187+
// Removes diff markers to avoid false-positives
188+
let new_marker = format!("@@ {filename}:");
189+
let old_patch = MARKER_RE.replace_all(old_patch, &*new_marker);
190+
let new_patch = MARKER_RE.replace_all(new_patch, &*new_marker);
191+
183192
// Prepare input
184-
let input: InternedInput<&str> = InternedInput::new(old_patch, new_patch);
193+
let input: InternedInput<&str> = InternedInput::new(&*old_patch, &*new_patch);
185194

186195
// Compute the diff
187196
let mut diff = Diff::compute(Algorithm::Histogram, &input);

0 commit comments

Comments
 (0)