Remove some unused methods from diff related code
Change-Id: Iea897a5ed10d44eddc47ae27e6f472369fcdc5be
This commit is contained in:
parent
2ae3b327d6
commit
c449f4da32
@ -16,7 +16,6 @@ package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||
import com.google.gerrit.prettify.common.EditList;
|
||||
import com.google.gerrit.prettify.common.SparseFileContent;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
@ -211,14 +210,6 @@ public class PatchScript {
|
||||
return edits;
|
||||
}
|
||||
|
||||
public Iterable<EditList.Hunk> getHunks() {
|
||||
int ctx = diffPrefs.context;
|
||||
if (ctx == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
|
||||
ctx = Math.max(a.size(), b.size());
|
||||
}
|
||||
return new EditList(edits, ctx, a.size(), b.size()).getHunks();
|
||||
}
|
||||
|
||||
public boolean isBinary() {
|
||||
return binary;
|
||||
}
|
||||
|
@ -16,13 +16,10 @@ package com.google.gerrit.prettify.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.diff.Edit;
|
||||
|
||||
public class SparseFileContent {
|
||||
protected String path;
|
||||
protected List<Range> ranges;
|
||||
protected int size;
|
||||
protected boolean missingNewlineAtEnd;
|
||||
|
||||
private transient int currentRangeIdx;
|
||||
|
||||
@ -38,35 +35,6 @@ public class SparseFileContent {
|
||||
size = s;
|
||||
}
|
||||
|
||||
public boolean isMissingNewlineAtEnd() {
|
||||
return missingNewlineAtEnd;
|
||||
}
|
||||
|
||||
public void setMissingNewlineAtEnd(final boolean missing) {
|
||||
missingNewlineAtEnd = missing;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String filePath) {
|
||||
path = filePath;
|
||||
}
|
||||
|
||||
public boolean isWholeFile() {
|
||||
if (size == 0) {
|
||||
return true;
|
||||
|
||||
} else if (1 == ranges.size()) {
|
||||
Range r = ranges.get(0);
|
||||
return r.base == 0 && r.end() == size;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String get(final int idx) {
|
||||
final String line = getLine(idx);
|
||||
if (line == null) {
|
||||
@ -138,17 +106,6 @@ public class SparseFileContent {
|
||||
return size();
|
||||
}
|
||||
|
||||
public int mapIndexToLine(int arrayIndex) {
|
||||
final int origIndex = arrayIndex;
|
||||
for (Range r : ranges) {
|
||||
if (arrayIndex < r.lines.size()) {
|
||||
return r.base + arrayIndex;
|
||||
}
|
||||
arrayIndex -= r.lines.size();
|
||||
}
|
||||
throw new ArrayIndexOutOfBoundsException(origIndex);
|
||||
}
|
||||
|
||||
private String getLine(final int idx) {
|
||||
// Most requests are sequential in nature, fetching the next
|
||||
// line from the current range, or the next range.
|
||||
@ -206,58 +163,6 @@ public class SparseFileContent {
|
||||
return ranges.get(ranges.size() - 1);
|
||||
}
|
||||
|
||||
public String asString() {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
for (Range r : ranges) {
|
||||
for (String l : r.lines) {
|
||||
b.append(l);
|
||||
b.append('\n');
|
||||
}
|
||||
}
|
||||
if (0 < b.length() && isMissingNewlineAtEnd()) {
|
||||
b.setLength(b.length() - 1);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public SparseFileContent apply(SparseFileContent a, List<Edit> edits) {
|
||||
EditList list = new EditList(edits, size, a.size(), size);
|
||||
ArrayList<String> lines = new ArrayList<>(size);
|
||||
for (final EditList.Hunk hunk : list.getHunks()) {
|
||||
while (hunk.next()) {
|
||||
if (hunk.isContextLine()) {
|
||||
if (contains(hunk.getCurB())) {
|
||||
lines.add(get(hunk.getCurB()));
|
||||
} else {
|
||||
lines.add(a.get(hunk.getCurA()));
|
||||
}
|
||||
hunk.incBoth();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hunk.isDeletedA()) {
|
||||
hunk.incA();
|
||||
}
|
||||
|
||||
if (hunk.isInsertedB()) {
|
||||
lines.add(get(hunk.getCurB()));
|
||||
hunk.incB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Range range = new Range();
|
||||
range.lines = lines;
|
||||
|
||||
SparseFileContent r = new SparseFileContent();
|
||||
r.setSize(lines.size());
|
||||
r.setMissingNewlineAtEnd(isMissingNewlineAtEnd());
|
||||
r.setPath(getPath());
|
||||
r.ranges.add(range);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder b = new StringBuilder();
|
||||
|
@ -534,11 +534,7 @@ class PatchScriptBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (srcContent.length > 0 && srcContent[srcContent.length - 1] != '\n') {
|
||||
dst.setMissingNewlineAtEnd(true);
|
||||
}
|
||||
dst.setSize(size());
|
||||
dst.setPath(path);
|
||||
|
||||
if (mode == FileMode.SYMLINK) {
|
||||
fileMode = PatchScript.FileMode.SYMLINK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user