1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.BufferedReader;
20 import java.io.BufferedWriter;
21 import java.io.File;
22 import java.io.FileReader;
23 import java.io.FileWriter;
24 import java.util.HashSet;
25 import java.util.regex.Pattern;
26
27 public class PartialMergeHelper {
28
29 static final Pattern fileBreakPattern = Pattern.compile("^Index: ");
30
31 public static void main(String[] args) throws Exception {
32 String partialMergeDiffFileName = args[0];
33 String completeMergeDiffFileName = args[1];
34 String mergeRemainderDiffFileName = args[2];
35
36 HashSet<String> filesInPartialMerge = new HashSet<String>();
37
38
39
40 File partialMergeFile = new File( partialMergeDiffFileName );
41 System.out.println( "Partial Merge file: " + partialMergeFile.getAbsolutePath() );
42 BufferedReader r = new BufferedReader(new FileReader( partialMergeFile ) );
43 String line;
44 while ( (line = r.readLine()) != null ) {
45 if ( fileBreakPattern.matcher(line).find() ) {
46 System.out.println( "Adding to partial merge file list: " + line );
47 filesInPartialMerge.add(line);
48 }
49 }
50
51
52
53 File inputFile = new File( completeMergeDiffFileName );
54 System.out.println( "Attemping to read from file: " + inputFile.getAbsolutePath() );
55 File outputFile = new File ( mergeRemainderDiffFileName );
56 System.out.println( "Output file: " + outputFile.getAbsolutePath() );
57 r = new BufferedReader(new FileReader( inputFile ) );
58 BufferedWriter w = new BufferedWriter( new FileWriter(outputFile) );
59 boolean inFileSuppressionMode = false;
60 int suppressionLineCount = 0;
61 while ( (line = r.readLine()) != null ) {
62 if ( fileBreakPattern.matcher(line).find() ) {
63
64
65
66 inFileSuppressionMode = false;
67 System.out.println( "Found File Break: " + line );
68 if ( filesInPartialMerge.contains(line) ) {
69 System.out.println( " HAS ALREADY BEEN MERGED - SUPPRESSING OUTPUT" );
70 inFileSuppressionMode = true;
71 suppressionLineCount = 0;
72 }
73 }
74 if ( !inFileSuppressionMode ) {
75 w.write(line);
76 w.newLine();
77 } else {
78 suppressionLineCount++;
79 }
80 }
81 if ( inFileSuppressionMode ) {
82 System.out.println( "Completing File Suppression. Lines Removed: " + suppressionLineCount );
83 }
84 r.close();
85 w.close();
86 }
87
88 }