conflicts: switch to multi-line regex, fix minor bug

The multi-line regex will be used for other purposes soon.
This commit is contained in:
Ilya Grigoriev 2024-07-11 17:58:03 -07:00
parent d095570718
commit e2f12d91cc
2 changed files with 7 additions and 26 deletions

View file

@ -19,7 +19,7 @@ use std::iter::zip;
use futures::{try_join, Stream, StreamExt, TryStreamExt};
use itertools::Itertools;
use regex::bytes::Regex;
use regex::bytes::{Regex, RegexBuilder};
use crate::backend::{BackendError, BackendResult, CommitId, FileId, SymlinkId, TreeId, TreeValue};
use crate::diff::{Diff, DiffHunk};
@ -47,11 +47,10 @@ const CONFLICT_PLUS_LINE_CHAR: u8 = CONFLICT_PLUS_LINE[0];
// separators. This could be useful to make it possible to allow conflict
// markers inside the text of the conflicts.
static CONFLICT_MARKER_REGEX: once_cell::sync::Lazy<Regex> = once_cell::sync::Lazy::new(|| {
Regex::new(
r"(<{7}|>{7}|%{7}|\-{7}|\+{7})( .*)?
",
)
.unwrap()
RegexBuilder::new(r"^(<{7}|>{7}|%{7}|\-{7}|\+{7})( .*)?$")
.multi_line(true)
.build()
.unwrap()
});
fn write_diff_hunks(hunks: &[DiffHunk], file: &mut dyn Write) -> std::io::Result<()> {

View file

@ -611,7 +611,7 @@ fn test_parse_conflict_simple() {
)
"###
);
// BUG: The conflict markers are too long and shouldn't parse (though we may
// The conflict markers are too long and shouldn't parse (though we may
// decide to change this in the future)
insta::assert_debug_snapshot!(
parse_conflict(indoc! {b"
@ -629,25 +629,7 @@ fn test_parse_conflict_simple() {
"},
2
),
@r###"
Some(
[
Resolved(
"line 1\n",
),
Conflicted(
[
"line 2\nleft\nline 4\n",
"line 2\nline 3\nline 4\n",
"right\n",
],
),
Resolved(
"line 5\n",
),
],
)
"###
@"None"
)
}