11use std:: collections:: HashSet ;
22use std:: fmt:: { self , Write } ;
3- use std:: sync:: Arc ;
3+ use std:: sync:: { Arc , LazyLock } ;
44
55use anyhow:: Context as _;
66use axum:: {
@@ -18,9 +18,13 @@ use imara_diff::{
1818 Algorithm , Diff , InternedInput , Interner , Token , UnifiedDiffConfig , UnifiedDiffPrinter ,
1919} ;
2020use pulldown_cmark_escape:: FmtWriter ;
21+ use regex:: Regex ;
2122
2223use 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/// Compute and renders an emulated `git range-diff` between two pushes (old and new).
2529///
2630/// `basehead` is `OLDHEAD..NEWHEAD`, both `OLDHEAD` and `NEWHEAD` must be SHAs or branch names.
@@ -183,8 +187,13 @@ pub async fn gh_range_diff(
183187 ) ?;
184188
185189 let mut process_diffs = |filename, old_patch, new_patch| -> anyhow:: Result < ( ) > {
190+ // Removes diff markers to avoid false-positives
191+ let new_marker = format ! ( "@@ {filename}:" ) ;
192+ let old_patch = MARKER_RE . replace_all ( old_patch, & * new_marker) ;
193+ let new_patch = MARKER_RE . replace_all ( new_patch, & * new_marker) ;
194+
186195 // Prepare input
187- let input: InternedInput < & str > = InternedInput :: new ( old_patch, new_patch) ;
196+ let input: InternedInput < & str > = InternedInput :: new ( & * old_patch, & * new_patch) ;
188197
189198 // Compute the diff
190199 let mut diff = Diff :: compute ( Algorithm :: Histogram , & input) ;
0 commit comments