Support patches without a prelude.

This commit is contained in:
md_5 2014-12-24 09:32:10 +11:00
parent 7954aca0ff
commit 9d9ebf6ce5

View file

@ -246,7 +246,24 @@ public class Builder
System.out.println( "Patching with " + file.getName() );
Patch parsedPatch = DiffUtils.parseUnifiedDiff( Files.readLines( file, Charsets.UTF_8 ) );
List<String> readFile = Files.readLines( file, Charsets.UTF_8 );
// Manually append prelude if it is not found in the first few lines.
boolean preludeFound = false;
for ( int i = 0; i < Math.min( 3, readFile.size() ); i++ )
{
if ( readFile.get( i ).startsWith( "+++" ) )
{
preludeFound = true;
break;
}
}
if ( !preludeFound )
{
readFile.add( 0, "+++" );
}
Patch parsedPatch = DiffUtils.parseUnifiedDiff( readFile );
List<?> modifiedLines = DiffUtils.patch( Files.readLines( clean, Charsets.UTF_8 ), parsedPatch );
BufferedWriter bw = new BufferedWriter( new FileWriter( t ) );