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+
2428pub 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