Permalink
Browse files

Fix showDiffs bug [JENKINS-17124]

  • Loading branch information...
kstutz committed Mar 11, 2013
1 parent d080060 commit 7137e0367286571f32f7fe81e54a47e315f8882a
Showing with 19 additions and 9 deletions.
  1. +19 −9 src/main/java/hudson/plugins/jobConfigHistory/JobConfigHistoryBaseAction.java
@@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeMap;

import javax.servlet.ServletException;

@@ -388,15 +389,15 @@ public final String getDiffFile() 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.
*/
@@ -415,6 +416,7 @@ public final String getDiffFile() throws IOException {
public List<Line> getLines() {
return Collections.unmodifiableList(lines);
}

/**
* Adds a line.
*
@@ -423,26 +425,31 @@ public final String getDiffFile() throws IOException {
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);
}

/**
@@ -456,6 +463,9 @@ public void clearDuplicateLines() {
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.

0 comments on commit 7137e03

Please sign in to comment.