Skip to content

Feature/handle dashes in content #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repositories {

// run gradle with "-Dsnapshot=true" to automatically append "-SNAPSHOT" to the version
version = '1.5' + (Boolean.valueOf(System.getProperty("snapshot")) ? "-SNAPSHOT" : "")
group = 'io.reflectoring.diffparser'
sourceCompatibility = 1.8

ext{
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'diffparser'
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum ParserState {
@Override
public ParserState nextState(ParseWindow window) {
String line = window.getFocusLine();
if (matchesFromFilePattern(line)) {
if (matchesFromFilePattern(line, window.getFutureLine(1))) {
logTransition(line, INITIAL, FROM_FILE);
return FROM_FILE;
} else {
Expand All @@ -51,7 +51,7 @@ public ParserState nextState(ParseWindow window) {
@Override
public ParserState nextState(ParseWindow window) {
String line = window.getFocusLine();
if (matchesFromFilePattern(line)) {
if (matchesFromFilePattern(line, window.getFutureLine(1))) {
logTransition(line, HEADER, FROM_FILE);
return FROM_FILE;
} else {
Expand Down Expand Up @@ -237,8 +237,8 @@ protected void logTransition(String currentLine, ParserState fromState, ParserSt
logger.debug(String.format("%12s -> %12s: %s", fromState, toState, currentLine));
}

protected boolean matchesFromFilePattern(String line) {
return line.startsWith("---");
protected boolean matchesFromFilePattern(String line, String nextLine) {
return line.startsWith("---") && nextLine.startsWith("+++");
}

protected boolean matchesToFilePattern(String line) {
Expand All @@ -264,7 +264,7 @@ protected boolean matchesEndPattern(String line, ParseWindow window) {
int i = 1;
String futureLine;
while ((futureLine = window.getFutureLine(i)) != null) {
if (matchesFromFilePattern(futureLine)) {
if (matchesFromFilePattern(futureLine, window.getFutureLine(i + 1))) {
// We found the start of a new diff without another newline in between. That makes the current line the delimiter
// between this diff and the next.
return true;
Expand All @@ -282,7 +282,7 @@ protected boolean matchesEndPattern(String line, ParseWindow window) {
// some diff tools like "svn diff" do not put an empty line between two diffs
// we add that empty line and call the method again
String nextFromFileLine = window.getFutureLine(3);
if(nextFromFileLine != null && matchesFromFilePattern(nextFromFileLine)){
if(nextFromFileLine != null && matchesFromFilePattern(nextFromFileLine, window.getFutureLine(4))){
window.addLine(1, "");
return matchesEndPattern(line, window);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public void testParse() {
assertEquals(7, hunk1.getToFileRange().getLineCount());

List<Line> lines = hunk1.getLines();
assertEquals(8, lines.size());
assertEquals(10, lines.size());
assertEquals(Line.LineType.FROM, lines.get(3).getLineType());
assertEquals(Line.LineType.TO, lines.get(4).getLineType());
assertEquals(Line.LineType.NEUTRAL, lines.get(5).getLineType());
assertEquals(Line.LineType.FROM, lines.get(6).getLineType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ index 5809534..4f4147a 100644
<artifactId>diffparser</artifactId>
- <version>1.1-SNAPSHOT</version>
+ <version>1.0</version>
---
----
<packaging>jar</packaging>
<name>diffparser</name>
<description>Parse textual diffs with Java.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Index: UnifiedDiffParserTest.java
DiffParser parser = new UnifiedDiffParser();
- InputStream in = getClass().getResourceAsStream("svnlog.diff");
-
+
+
----
// when
List<Diff> diffs = parser.parse(in);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Modified: trunk/test1.txt
@@ -1,4 +1,5 @@
-test1
-test1
----
+aösdhasd
+asdasd

Expand Down