File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,11 @@ fn parse_edit_hunk(i: &str) -> IResult<&str, PrintableHunk> {
140
140
let ( i, encoding) = preceded ( space0, parse_encoding) ( i) ?;
141
141
let ( i, _) = tuple ( ( space0, newline) ) ( i) ?;
142
142
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
+ } ;
144
148
Ok ( (
145
149
i,
146
150
Edit {
@@ -352,13 +356,14 @@ fn parse_contents(
352
356
if backslash. is_some ( ) && vec[ vec. len ( ) - 1 ] == b'\n' {
353
357
vec. pop ( ) ;
354
358
}
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
+ }
361
362
}
363
+ Err ( nom:: Err :: Error ( nom:: error:: Error :: new (
364
+ i,
365
+ nom:: error:: ErrorKind :: Verify ,
366
+ ) ) )
362
367
}
363
368
364
369
fn encode ( encoding : Option < Encoding > , contents : & str ) -> Result < Vec < u8 > , String > {
Original file line number Diff line number Diff line change @@ -452,7 +452,16 @@ impl PrintableHunk {
452
452
Escaped ( encoding_label( encoding) )
453
453
) ?;
454
454
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) ?;
456
465
}
457
466
458
467
Replace {
Original file line number Diff line number Diff line change @@ -51,11 +51,16 @@ pub(super) fn make_new_chunks<'a>(
51
51
let mut j = 0 ;
52
52
let mut lines = Vec :: new ( ) ;
53
53
while j < b. len ( ) {
54
+ debug ! ( "processing {:?}" , j) ;
54
55
let h = ad. hash ( ) ;
56
+ let mut found = false ;
55
57
if let Some ( v) = a_h. get ( & h) {
56
58
// We've found a match from the old version.
59
+ debug ! ( "matched {:?}" , h) ;
57
60
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) ;
59
64
bb. push ( Chunk :: Old {
60
65
start : j,
61
66
end : i,
@@ -77,7 +82,9 @@ pub(super) fn make_new_chunks<'a>(
77
82
break ;
78
83
}
79
84
}
80
- } else {
85
+ }
86
+ if !found {
87
+ debug ! ( "new {:?}" , h) ;
81
88
if let Some ( Chunk :: New { ref mut len, .. } ) = bb. last_mut ( ) {
82
89
* len += 1
83
90
} else {
You can’t perform that action at this time.
0 commit comments