1
1
use std:: collections:: HashSet ;
2
2
use std:: fmt:: { self , Write } ;
3
- use std:: sync:: Arc ;
3
+ use std:: sync:: { Arc , LazyLock } ;
4
4
5
5
use anyhow:: Context as _;
6
6
use axum:: {
@@ -18,9 +18,13 @@ use imara_diff::{
18
18
Algorithm , Diff , InternedInput , Interner , Token , UnifiedDiffConfig , UnifiedDiffPrinter ,
19
19
} ;
20
20
use pulldown_cmark_escape:: FmtWriter ;
21
+ use regex:: Regex ;
21
22
22
23
use crate :: { github, handlers:: Context , utils:: AppError } ;
23
24
25
+ static MARKER_RE : LazyLock < Regex > =
26
+ LazyLock :: new ( || Regex :: new ( r"@@ -[\d]+,[\d]+ [+][\d]+,[\d]+ @@" ) . unwrap ( ) ) ;
27
+
24
28
pub async fn gh_range_diff (
25
29
Path ( ( owner, repo, basehead) ) : Path < ( String , String , String ) > ,
26
30
State ( ctx) : State < Arc < Context > > ,
@@ -180,8 +184,13 @@ pub async fn gh_range_diff(
180
184
) ?;
181
185
182
186
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
+
183
192
// Prepare input
184
- let input: InternedInput < & str > = InternedInput :: new ( old_patch, new_patch) ;
193
+ let input: InternedInput < & str > = InternedInput :: new ( & * old_patch, & * new_patch) ;
185
194
186
195
// Compute the diff
187
196
let mut diff = Diff :: compute ( Algorithm :: Histogram , & input) ;
0 commit comments