Skip to content

Commit 976ee58

Browse files
author
fossdd
committed
Update pijul
1 parent 4592157 commit 976ee58

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

libpijul/src/change/parse.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ fn parse_edit_hunk(i: &str) -> IResult<&str, PrintableHunk> {
140140
let (i, encoding) = preceded(space0, parse_encoding)(i)?;
141141
let (i, _) = tuple((space0, newline))(i)?;
142142
let (i, change) = parse_atom(i)?;
143-
let (i, contents) = parse_contents('+', encoding.clone(), i)?;
143+
let (i, contents) = if let Ok(s) = parse_contents('+', encoding.clone(), i) {
144+
s
145+
} else {
146+
parse_contents('-', encoding.clone(), i)?
147+
};
144148
Ok((
145149
i,
146150
Edit {
@@ -352,13 +356,14 @@ fn parse_contents(
352356
if backslash.is_some() && vec[vec.len() - 1] == b'\n' {
353357
vec.pop();
354358
}
355-
Ok((i, vec))
356-
} else {
357-
Err(nom::Err::Error(nom::error::Error::new(
358-
i,
359-
nom::error::ErrorKind::Verify,
360-
)))
359+
if !vec.is_empty() {
360+
return Ok((i, vec))
361+
}
361362
}
363+
Err(nom::Err::Error(nom::error::Error::new(
364+
i,
365+
nom::error::ErrorKind::Verify,
366+
)))
362367
}
363368

364369
fn encode(encoding: Option<Encoding>, contents: &str) -> Result<Vec<u8>, String> {

libpijul/src/change/printable.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,16 @@ impl PrintableHunk {
452452
Escaped(encoding_label(encoding))
453453
)?;
454454
writeln!(w, "{}", change)?;
455-
print_contents(w, "+", contents, encoding)?;
455+
let sign = if let PrintableAtom::Edges(ref e) = change {
456+
if e[0].flag.deleted {
457+
"-"
458+
} else {
459+
"+"
460+
}
461+
} else {
462+
"+"
463+
};
464+
print_contents(w, sign, contents, encoding)?;
456465
}
457466

458467
Replace {

libpijul/src/diff/bin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ pub(super) fn make_new_chunks<'a>(
5151
let mut j = 0;
5252
let mut lines = Vec::new();
5353
while j < b.len() {
54+
debug!("processing {:?}", j);
5455
let h = ad.hash();
56+
let mut found = false;
5557
if let Some(v) = a_h.get(&h) {
5658
// We've found a match from the old version.
59+
debug!("matched {:?}", h);
5760
for &(v, old) in v.iter() {
58-
if old == &b[j..i] {
61+
found = old == &b[j..i];
62+
if found {
63+
debug!("old matched from {:?}-{:?}", j, i);
5964
bb.push(Chunk::Old {
6065
start: j,
6166
end: i,
@@ -77,7 +82,9 @@ pub(super) fn make_new_chunks<'a>(
7782
break;
7883
}
7984
}
80-
} else {
85+
}
86+
if !found {
87+
debug!("new {:?}", h);
8188
if let Some(Chunk::New { ref mut len, .. }) = bb.last_mut() {
8289
*len += 1
8390
} else {

0 commit comments

Comments
 (0)