1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::collections::VecDeque;
use log::*;
use patch_rs::Patch;
pub fn combinediff(mut patch_1: Patch, mut patch_2: Patch, context_radius: usize) -> Patch {
let mut combinediff = Patch {
input: patch_1.input.to_owned(),
output: patch_2.output.to_owned(),
contexts: VecDeque::new(),
};
trace!("DRAINING BOTH PATCHES");
while !patch_1.contexts.is_empty() && !patch_2.contexts.is_empty() {
let p1 = patch_1.contexts.front().unwrap();
let p2 = patch_2.contexts.front().unwrap();
if p1.header.file1_l <= p2.header.file1_l {
let context = patch_1.contexts.pop_front().unwrap();
let reduced = context.reduce(context_radius);
for context in reduced.into_iter() {
combinediff.contexts.push_back(context);
}
} else {
let context = patch_2.contexts.pop_front().unwrap();
let reduced = context.reduce(context_radius);
for context in reduced.into_iter() {
combinediff.contexts.push_back(context);
}
}
}
trace!("DRAINING FIRST PATCH");
while !patch_1.contexts.is_empty() {
let context = patch_1.contexts.pop_front().unwrap();
let reduced = context.reduce(context_radius);
for context in reduced.into_iter() {
combinediff.contexts.push_back(context);
}
}
trace!("DRAINING SECOND PATCH");
while !patch_2.contexts.is_empty() {
let context = patch_2.contexts.pop_front().unwrap();
let reduced = context.reduce(context_radius);
for context in reduced.into_iter() {
combinediff.contexts.push_back(context);
}
}
combinediff
}