Skip to content

Commit

Permalink
Fix showDiffs bug [JENKINS-17124]
Browse files Browse the repository at this point in the history
  • Loading branch information
kstutz committed Mar 11, 2013
1 parent d080060 commit 7137e03
Showing 1 changed file with 19 additions and 9 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import javax.servlet.ServletException;

Expand Down Expand Up @@ -388,15 +389,15 @@ public final List<Line> getDiffLines() throws IOException {
} else {
throw new IllegalStateException("Unknown tag pattern: " + tag);
}

line.tag = tag;
view.addLine(line);
previousLeftPos = leftPos;
}
}
view.clearDuplicateLines();
return view.getLines();
}

/**
* Holds information for the SideBySideView.
*/
Expand All @@ -415,6 +416,7 @@ public static class SideBySideView {
public List<Line> getLines() {
return Collections.unmodifiableList(lines);
}

/**
* Adds a line.
*
Expand All @@ -423,26 +425,31 @@ public List<Line> getLines() {
public void addLine(Line line) {
lines.add(line);
}

/**
* Deletes all dupes in the given lines.
*
* TODO: encapsulate the call as we probably always want the
* deduplicated lines only.
*/
public void clearDuplicateLines() {
final TreeMap<Integer, Line> linesByNumbers = new TreeMap<Integer, Line>();
final ArrayList<Line> dupes = new ArrayList<Line>();
final Iterator<Line> iter = lines.iterator();
final Set<String> duplicateLineChecker = new HashSet<String>();
while (iter.hasNext()) {
final Line line = iter.next();
final String lineNum = line.left.getLineNumber();
if (lineNum.length() != 0) {
if (duplicateLineChecker.contains(lineNum)) {
iter.remove();
final int lineNumInt = Integer.parseInt(lineNum);
if (linesByNumbers.containsKey(lineNumInt)) {
if (line.tag == Tag.EQUAL) {
iter.remove();
} else {
dupes.add(linesByNumbers.get(lineNumInt));
}
} else {
duplicateLineChecker.add(lineNum);
linesByNumbers.put(lineNumInt, line);
}
}
}
lines.removeAll(dupes);
}

/**
Expand All @@ -456,6 +463,9 @@ public static class Line {
private final Item right = new Item();
/**True when line should be skipped.*/
private boolean skipping;
/**EQUAL, INSERT, CHANGE or DELETE.*/
private Tag tag;


/**
* Returns the left version of a modificated line.
Expand Down

0 comments on commit 7137e03

Please sign in to comment.