@@ -59,25 +59,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
59
59
Matcher m = UNIFIED_DIFF_CHUNK_REGEXP .matcher (line );
60
60
if (m .find ()) {
61
61
// Process the lines in the previous chunk
62
- if (!rawChunk .isEmpty ()) {
63
- List <String > oldChunkLines = new ArrayList <>();
64
- List <String > newChunkLines = new ArrayList <>();
65
-
66
- for (String [] raw_line : rawChunk ) {
67
- tag = raw_line [0 ];
68
- rest = raw_line [1 ];
69
- if (" " .equals (tag ) || "-" .equals (tag )) {
70
- oldChunkLines .add (rest );
71
- }
72
- if (" " .equals (tag ) || "+" .equals (tag )) {
73
- newChunkLines .add (rest );
74
- }
75
- }
76
- patch .addDelta (new ChangeDelta <>(new Chunk <>(
77
- old_ln - 1 , oldChunkLines ), new Chunk <>(
78
- new_ln - 1 , newChunkLines )));
79
- rawChunk .clear ();
80
- }
62
+ processLinesInPrevChunk (rawChunk , patch , old_ln , new_ln );
81
63
// Parse the @@ header
82
64
old_ln = m .group (1 ) == null ? 1 : Integer .parseInt (m .group (1 ));
83
65
new_ln = m .group (3 ) == null ? 1 : Integer .parseInt (m .group (3 ));
@@ -102,6 +84,14 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
102
84
}
103
85
104
86
// Process the lines in the last chunk
87
+ processLinesInPrevChunk (rawChunk , patch , old_ln , new_ln );
88
+
89
+ return patch ;
90
+ }
91
+
92
+ private static void processLinesInPrevChunk (List <String []> rawChunk , Patch <String > patch , int old_ln , int new_ln ) {
93
+ String tag ;
94
+ String rest ;
105
95
if (!rawChunk .isEmpty ()) {
106
96
List <String > oldChunkLines = new ArrayList <>();
107
97
List <String > newChunkLines = new ArrayList <>();
@@ -116,14 +106,11 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
116
106
newChunkLines .add (rest );
117
107
}
118
108
}
119
-
120
109
patch .addDelta (new ChangeDelta <>(new Chunk <>(
121
- old_ln - 1 , oldChunkLines ), new Chunk <>(new_ln - 1 ,
122
- newChunkLines )));
110
+ old_ln - 1 , oldChunkLines ), new Chunk <>(
111
+ new_ln - 1 , newChunkLines )));
123
112
rawChunk .clear ();
124
113
}
125
-
126
- return patch ;
127
114
}
128
115
129
116
/**
0 commit comments