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
/// Compute and renders an emulated `git range-diff` between two pushes (old and new).
25
29
///
26
30
/// `basehead` is `OLDHEAD..NEWHEAD`, both `OLDHEAD` and `NEWHEAD` must be SHAs or branch names.
@@ -183,8 +187,13 @@ pub async fn gh_range_diff(
183
187
) ?;
184
188
185
189
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
+
186
195
// Prepare input
187
- let input: InternedInput < & str > = InternedInput :: new ( old_patch, new_patch) ;
196
+ let input: InternedInput < & str > = InternedInput :: new ( & * old_patch, & * new_patch) ;
188
197
189
198
// Compute the diff
190
199
let mut diff = Diff :: compute ( Algorithm :: Histogram , & input) ;
0 commit comments