@@ -59,25 +59,7 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
5959 Matcher m = UNIFIED_DIFF_CHUNK_REGEXP .matcher (line );
6060 if (m .find ()) {
6161 // 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 );
8163 // Parse the @@ header
8264 old_ln = m .group (1 ) == null ? 1 : Integer .parseInt (m .group (1 ));
8365 new_ln = m .group (3 ) == null ? 1 : Integer .parseInt (m .group (3 ));
@@ -102,6 +84,14 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
10284 }
10385
10486 // 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 ;
10595 if (!rawChunk .isEmpty ()) {
10696 List <String > oldChunkLines = new ArrayList <>();
10797 List <String > newChunkLines = new ArrayList <>();
@@ -116,14 +106,11 @@ public static Patch<String> parseUnifiedDiff(List<String> diff) {
116106 newChunkLines .add (rest );
117107 }
118108 }
119-
120109 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 )));
123112 rawChunk .clear ();
124113 }
125-
126- return patch ;
127114 }
128115
129116 /**
0 commit comments