@@ -72,26 +72,45 @@ public final class UnifiedDiffReader {
7272// [/^---\s/, from_file], [/^\+\+\+\s/, to_file], [/^@@\s+\-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk],
7373// [/^-/, del], [/^\+/, add], [/^\\ No newline at end of file$/, eof]];
7474private UnifiedDiff parse ()throws IOException ,UnifiedDiffParserException {
75- String headerTxt ="" ;
76- LOG .log (Level .FINE ,"header parsing" );
77- String line =null ;
78- while (READER .ready ()) {
79- line =READER .readLine ();
80- LOG .log (Level .FINE ,"parsing line {0}" ,line );
81- if (DIFF_COMMAND .validLine (line ) ||INDEX .validLine (line )
82- ||FROM_FILE .validLine (line ) ||TO_FILE .validLine (line )
83- ||NEW_FILE_MODE .validLine (line )) {
84- break ;
85- }else {
86- headerTxt +=line +"\n " ;
87- }
88- }
89- if (!"" .equals (headerTxt )) {
90- data .setHeader (headerTxt );
91- }
92-
75+ // String headerTxt = "";
76+ // LOG.log(Level.FINE, "header parsing");
77+ // String line = null;
78+ // while (READER.ready()) {
79+ // line = READER.readLine();
80+ // LOG.log(Level.FINE, "parsing line {0}", line);
81+ // if (DIFF_COMMAND.validLine(line) || INDEX.validLine(line)
82+ // || FROM_FILE.validLine(line) || TO_FILE.validLine(line)
83+ // || NEW_FILE_MODE.validLine(line)) {
84+ // break;
85+ // } else {
86+ // headerTxt += line + "\n";
87+ // }
88+ // }
89+ // if (!"".equals(headerTxt)) {
90+ // data.setHeader(headerTxt);
91+ // }
92+
93+ String line =READER .readLine ();
9394while (line !=null ) {
94- if (!CHUNK .validLine (line )) {
95+ String headerTxt ="" ;
96+ LOG .log (Level .FINE ,"header parsing" );
97+ while (line !=null ) {
98+ LOG .log (Level .FINE ,"parsing line {0}" ,line );
99+ if (validLine (line ,DIFF_COMMAND ,SIMILARITY_INDEX ,INDEX ,
100+ FROM_FILE ,TO_FILE ,
101+ RENAME_FROM ,RENAME_TO ,
102+ NEW_FILE_MODE ,DELETED_FILE_MODE ,
103+ CHUNK )) {
104+ break ;
105+ }else {
106+ headerTxt +=line +"\n " ;
107+ }
108+ line =READER .readLine ();
109+ }
110+ if (!"" .equals (headerTxt )) {
111+ data .setHeader (headerTxt );
112+ }
113+ if (line !=null && !CHUNK .validLine (line )) {
95114initFileIfNecessary ();
96115while (line !=null && !CHUNK .validLine (line )) {
97116if (!processLine (line ,DIFF_COMMAND ,SIMILARITY_INDEX ,INDEX ,
@@ -107,7 +126,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
107126processLine (line ,CHUNK );
108127while ((line =READER .readLine ()) !=null ) {
109128line =checkForNoNewLineAtTheEndOfTheFile (line );
110-
129+
111130if (!processLine (line ,LINE_NORMAL ,LINE_ADD ,LINE_DEL )) {
112131throw new UnifiedDiffParserException ("expected data line not found" );
113132 }
@@ -186,6 +205,19 @@ private boolean processLine(String line, UnifiedDiffLine... rules) throws Unifie
186205return false ;
187206//throw new UnifiedDiffParserException("parsing error at line " + line);
188207 }
208+
209+ private boolean validLine (String line ,UnifiedDiffLine ...rules ) {
210+ if (line ==null ) {
211+ return false ;
212+ }
213+ for (UnifiedDiffLine rule :rules ) {
214+ if (rule .validLine (line )) {
215+ LOG .fine (" >>> accepted rule " +rule .toString ());
216+ return true ;
217+ }
218+ }
219+ return false ;
220+ }
189221
190222private void initFileIfNecessary () {
191223if (!originalTxt .isEmpty () || !revisedTxt .isEmpty ()) {