Merge "Permit cache.diff.intraline to disable MyersDiff"
This commit is contained in:
commit
4a25883456
@ -354,6 +354,20 @@ this cache is approximately 248 bytes, depending on the JVM.
|
||||
|
||||
See also link:cmd-flush-caches.html[gerrit flush-caches].
|
||||
|
||||
[[cache_options]]Cache Options
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
cache.diff.intraline::
|
||||
+
|
||||
Boolean to enable or disable the computation of intraline differences
|
||||
when populating a diff cache entry. Changing this setting in the
|
||||
server configuration requires flushing the "diff" cache after a
|
||||
restart, otherwise older cache entries stored on disk may not reflect
|
||||
the current server setting. This flag is provided primarily as a
|
||||
backdoor to disable the intraline difference feature if necessary.
|
||||
+
|
||||
Default is true, enabled.
|
||||
|
||||
|
||||
[[commentlink]]Section commentlink
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -50,12 +50,14 @@ public class PatchScript {
|
||||
protected CommentDetail comments;
|
||||
protected List<Patch> history;
|
||||
protected boolean hugeFile;
|
||||
protected boolean intralineDifference;
|
||||
|
||||
public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
|
||||
final String nn, final List<String> h, final PatchScriptSettings s,
|
||||
final SparseFileContent ca, final SparseFileContent cb,
|
||||
final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb,
|
||||
final CommentDetail cd, final List<Patch> hist, final boolean hf) {
|
||||
final CommentDetail cd, final List<Patch> hist, final boolean hf,
|
||||
final boolean id) {
|
||||
changeId = ck;
|
||||
changeType = ct;
|
||||
oldName = on;
|
||||
@ -70,6 +72,7 @@ public class PatchScript {
|
||||
comments = cd;
|
||||
history = hist;
|
||||
hugeFile = hf;
|
||||
intralineDifference = id;
|
||||
}
|
||||
|
||||
protected PatchScript() {
|
||||
@ -127,6 +130,10 @@ public class PatchScript {
|
||||
return settings.getWhitespace() != Whitespace.IGNORE_NONE;
|
||||
}
|
||||
|
||||
public boolean hasIntralineDifference() {
|
||||
return intralineDifference;
|
||||
}
|
||||
|
||||
public SparseFileContent getA() {
|
||||
return a;
|
||||
}
|
||||
|
@ -448,6 +448,7 @@ public abstract class PatchScreen extends Screen implements
|
||||
}
|
||||
showPatch(hasDifferences);
|
||||
settingsPanel.setEnableSmallFileFeatures(!script.isHugeFile());
|
||||
settingsPanel.setEnableIntralineDifference(script.hasIntralineDifference());
|
||||
settingsPanel.setEnabled(true);
|
||||
lastScript = script;
|
||||
|
||||
|
@ -54,6 +54,7 @@ public class PatchScriptSettingsPanel extends Composite implements
|
||||
}
|
||||
|
||||
private PatchScriptSettings value;
|
||||
private boolean enableIntralineDifference = true;
|
||||
private boolean enableSmallFileFeatures = true;
|
||||
|
||||
@UiField
|
||||
@ -144,11 +145,21 @@ public class PatchScriptSettingsPanel extends Composite implements
|
||||
toggleEnabledStatus(update.isEnabled());
|
||||
}
|
||||
|
||||
private void toggleEnabledStatus(boolean on) {
|
||||
on &= enableSmallFileFeatures;
|
||||
public void setEnableIntralineDifference(final boolean on) {
|
||||
enableIntralineDifference = on;
|
||||
if (enableIntralineDifference) {
|
||||
final PrettySettings p = getValue().getPrettySettings();
|
||||
intralineDifference.setValue(p.isIntralineDifference());
|
||||
} else {
|
||||
intralineDifference.setValue(false);
|
||||
}
|
||||
toggleEnabledStatus(update.isEnabled());
|
||||
}
|
||||
|
||||
syntaxHighlighting.setEnabled(on);
|
||||
showFullFile.setEnabled(on);
|
||||
private void toggleEnabledStatus(final boolean on) {
|
||||
intralineDifference.setEnabled(on & enableIntralineDifference);
|
||||
syntaxHighlighting.setEnabled(on & enableSmallFileFeatures);
|
||||
showFullFile.setEnabled(on & enableSmallFileFeatures);
|
||||
|
||||
final String title =
|
||||
enableSmallFileFeatures ? null : PatchUtil.C.disabledOnLargeFiles();
|
||||
|
@ -74,6 +74,9 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
||||
final SparseHtmlFile b = script.getSparseHtmlFileB();
|
||||
final ArrayList<PatchLine> lines = new ArrayList<PatchLine>();
|
||||
final SafeHtmlBuilder nc = new SafeHtmlBuilder();
|
||||
final boolean intraline =
|
||||
script.getSettings().getPrettySettings().isIntralineDifference()
|
||||
&& script.hasIntralineDifference();
|
||||
|
||||
appendHeader(script, nc);
|
||||
lines.add(null);
|
||||
@ -105,8 +108,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
|
||||
final boolean del = hunk.isDeletedA();
|
||||
final boolean ins = hunk.isInsertedB();
|
||||
final boolean full =
|
||||
script.getSettings().getPrettySettings().isIntralineDifference()
|
||||
&& hunk.getCurEdit().getType() != Edit.Type.REPLACE;
|
||||
intraline && hunk.getCurEdit().getType() != Edit.Type.REPLACE;
|
||||
openLine(nc);
|
||||
|
||||
if (del) {
|
||||
|
@ -109,8 +109,8 @@ class PatchScriptBuilder {
|
||||
}
|
||||
|
||||
PatchScript toPatchScript(final PatchListEntry content,
|
||||
final CommentDetail comments, final List<Patch> history)
|
||||
throws IOException {
|
||||
final boolean intralineDifference, final CommentDetail comments,
|
||||
final List<Patch> history) throws IOException {
|
||||
if (content.getPatchType() == PatchType.N_WAY) {
|
||||
// For a diff --cc format we don't support converting it into
|
||||
// a patch script. Instead treat everything as a file header.
|
||||
@ -118,7 +118,7 @@ class PatchScriptBuilder {
|
||||
return new PatchScript(change.getKey(), content.getChangeType(), content
|
||||
.getOldName(), content.getNewName(), content.getHeaderLines(),
|
||||
settings, a.dst, b.dst, Collections.<Edit> emptyList(),
|
||||
a.displayMethod, b.displayMethod, comments, history, false);
|
||||
a.displayMethod, b.displayMethod, comments, history, false, false);
|
||||
}
|
||||
|
||||
a.path = oldName(content);
|
||||
@ -168,7 +168,7 @@ class PatchScriptBuilder {
|
||||
return new PatchScript(change.getKey(), content.getChangeType(), content
|
||||
.getOldName(), content.getNewName(), content.getHeaderLines(),
|
||||
settings, a.dst, b.dst, edits, a.displayMethod, b.displayMethod,
|
||||
comments, history, hugeFile);
|
||||
comments, history, hugeFile, intralineDifference);
|
||||
}
|
||||
|
||||
private static String oldName(final PatchListEntry entry) {
|
||||
|
@ -144,6 +144,7 @@ class PatchScriptFactory extends Handler<PatchScript> {
|
||||
}
|
||||
try {
|
||||
final PatchList list = listFor(keyFor(settings.getWhitespace()));
|
||||
final boolean intraline = list.hasIntralineDifference();
|
||||
final PatchScriptBuilder b = newBuilder(list, git);
|
||||
final PatchListEntry content = list.get(patchKey.getFileName());
|
||||
|
||||
@ -152,7 +153,7 @@ class PatchScriptFactory extends Handler<PatchScript> {
|
||||
content.getNewName());
|
||||
|
||||
try {
|
||||
return b.toPatchScript(content, comments, history);
|
||||
return b.toPatchScript(content, intraline, comments, history);
|
||||
} catch (IOException e) {
|
||||
log.error("File content unavailable", e);
|
||||
throw new NoSuchChangeException(changeId, e);
|
||||
|
@ -59,12 +59,14 @@ public class PatchList implements Serializable {
|
||||
@Nullable
|
||||
private transient ObjectId oldId;
|
||||
private transient ObjectId newId;
|
||||
private transient boolean intralineDifference;
|
||||
private transient PatchListEntry[] patches;
|
||||
|
||||
PatchList(@Nullable final AnyObjectId oldId, final AnyObjectId newId,
|
||||
final PatchListEntry[] patches) {
|
||||
final boolean intralineDifference, final PatchListEntry[] patches) {
|
||||
this.oldId = oldId != null ? oldId.copy() : null;
|
||||
this.newId = newId.copy();
|
||||
this.intralineDifference = intralineDifference;
|
||||
|
||||
Arrays.sort(patches, PATCH_CMP);
|
||||
this.patches = patches;
|
||||
@ -86,6 +88,11 @@ public class PatchList implements Serializable {
|
||||
return Collections.unmodifiableList(Arrays.asList(patches));
|
||||
}
|
||||
|
||||
/** @return true if this list was computed with intraline difference enabled. */
|
||||
public boolean hasIntralineDifference() {
|
||||
return intralineDifference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sorted, modifiable list of all files in this list.
|
||||
* <p>
|
||||
@ -136,6 +143,7 @@ public class PatchList implements Serializable {
|
||||
try {
|
||||
writeCanBeNull(out, oldId);
|
||||
writeNotNull(out, newId);
|
||||
writeVarInt32(out, intralineDifference ? 1 : 0);
|
||||
writeVarInt32(out, patches.length);
|
||||
for (PatchListEntry p : patches) {
|
||||
p.writeTo(out);
|
||||
@ -152,6 +160,7 @@ public class PatchList implements Serializable {
|
||||
try {
|
||||
oldId = readCanBeNull(in);
|
||||
newId = readNotNull(in);
|
||||
intralineDifference = readVarInt32(in) != 0;
|
||||
final int cnt = readVarInt32(in);
|
||||
final PatchListEntry[] all = new PatchListEntry[cnt];
|
||||
for (int i = 0; i < all.length; i++) {
|
||||
|
@ -24,6 +24,7 @@ import com.google.gerrit.server.cache.Cache;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
import com.google.gerrit.server.cache.EvictionPolicy;
|
||||
import com.google.gerrit.server.cache.SelfPopulatingCache;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Module;
|
||||
@ -37,6 +38,7 @@ import org.eclipse.jgit.diff.ReplaceEdit;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.MissingObjectException;
|
||||
import org.eclipse.jgit.lib.AnyObjectId;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.FileMode;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@ -86,11 +88,14 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final SelfPopulatingCache<PatchListKey, PatchList> self;
|
||||
private final boolean computeIntraline;
|
||||
|
||||
@Inject
|
||||
PatchListCacheImpl(final GitRepositoryManager grm,
|
||||
@GerritServerConfig final Config config,
|
||||
@Named(CACHE_NAME) final Cache<PatchListKey, PatchList> raw) {
|
||||
repoManager = grm;
|
||||
computeIntraline = config.getBoolean("cache", "diff", "intraline", true);
|
||||
self = new SelfPopulatingCache<PatchListKey, PatchList>(raw) {
|
||||
@Override
|
||||
protected PatchList createEntry(final PatchListKey key) throws Exception {
|
||||
@ -197,10 +202,10 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
entries[i] = newEntry(repo, aTree, bTree, p.getFiles().get(i));
|
||||
}
|
||||
return new PatchList(a, b, entries);
|
||||
return new PatchList(a, b, computeIntraline, entries);
|
||||
}
|
||||
|
||||
private static PatchListEntry newEntry(Repository repo, RevTree aTree,
|
||||
private PatchListEntry newEntry(Repository repo, RevTree aTree,
|
||||
RevTree bTree, FileHeader fileHeader) throws IOException {
|
||||
final FileMode oldMode = fileHeader.getOldMode();
|
||||
final FileMode newMode = fileHeader.getNewMode();
|
||||
@ -219,6 +224,9 @@ public class PatchListCacheImpl implements PatchListCache {
|
||||
if (edits.isEmpty()) {
|
||||
return new PatchListEntry(fileHeader, Collections.<Edit> emptyList());
|
||||
}
|
||||
if (!computeIntraline) {
|
||||
return new PatchListEntry(fileHeader, edits);
|
||||
}
|
||||
|
||||
switch (fileHeader.getChangeType()) {
|
||||
case ADD:
|
||||
|
@ -35,7 +35,7 @@ import java.io.Serializable;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class PatchListKey implements Serializable {
|
||||
static final long serialVersionUID = 12L;
|
||||
static final long serialVersionUID = 13L;
|
||||
|
||||
private transient ObjectId oldId;
|
||||
private transient ObjectId newId;
|
||||
|
Loading…
Reference in New Issue
Block a user