aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChangcheng Xiao <xchangcheng@google.com>2017-07-21 09:58:37 +0200
committerChangcheng Xiao <xchangcheng@google.com>2017-07-22 21:51:12 +0200
commit1baf86d4d21df6cf2c10f3592df90044834d93af (patch)
treec746ebfccf337e4eb9561be663e7ce9cd1d1c103
parenta1e4825c4e6233be3aa3ed78d4bc18635698515e (diff)
downloadjgit-1baf86d4d21df6cf2c10f3592df90044834d93af.tar.gz
jgit-1baf86d4d21df6cf2c10f3592df90044834d93af.zip
Make 'inCoreLimit' of LocalFile used in ResolveMerger configurable
This change makes it possible to configure the 'inCoreLimit' of LocalFile used in ResolveMerger#insertMergeResult. Since LocalFile itself has some risks, e.g. it may be left behind as garbage in case of failure. It should be good to be able to control the size limit for using LocalFile. Change-Id: I3dc545ade370b2bbdb7c610ed45d5dd4d39b9e8e Signed-off-by: Changcheng Xiao <xchangcheng@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java18
2 files changed, 23 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
index 20744b628f..ad5b106aa2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigConstants.java
@@ -371,6 +371,13 @@ public class ConfigConstants {
public static final String CONFIG_KEY_RENAMES = "renames";
/**
+ * The "inCoreLimit" key in the "merge section". It's a size limit (bytes) used to
+ * control a file to be stored in {@code Heap} or {@code LocalFile} during the merge.
+ * @since 4.9
+ */
+ public static final String CONFIG_KEY_IN_CORE_LIMIT = "inCoreLimit";
+
+ /**
* The "prune" key
* @since 3.3
*/
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index e77ad953dc..92c2bb35a1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
@@ -85,6 +85,7 @@ import org.eclipse.jgit.errors.IndexWriteException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -272,6 +273,12 @@ public class ResolveMerger extends ThreeWayMerger {
*/
protected MergeAlgorithm mergeAlgorithm;
+ /**
+ * The size limit (bytes) which controls a file to be stored in {@code Heap} or
+ * {@code LocalFile} during the merge.
+ */
+ private int inCoreLimit;
+
private static MergeAlgorithm getMergeAlgorithm(Config config) {
SupportedAlgorithm diffAlg = config.getEnum(
CONFIG_DIFF_SECTION, null, CONFIG_KEY_ALGORITHM,
@@ -279,6 +286,11 @@ public class ResolveMerger extends ThreeWayMerger {
return new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg));
}
+ private static int getInCoreLimit(Config config) {
+ return config.getInt(
+ ConfigConstants.CONFIG_MERGE_SECTION, ConfigConstants.CONFIG_KEY_IN_CORE_LIMIT, 10 << 20);
+ }
+
private static String[] defaultCommitNames() {
return new String[] { "BASE", "OURS", "THEIRS" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@@ -289,7 +301,9 @@ public class ResolveMerger extends ThreeWayMerger {
*/
protected ResolveMerger(Repository local, boolean inCore) {
super(local);
- mergeAlgorithm = getMergeAlgorithm(local.getConfig());
+ Config config = local.getConfig();
+ mergeAlgorithm = getMergeAlgorithm(config);
+ inCoreLimit = getInCoreLimit(config);
commitNames = defaultCommitNames();
this.inCore = inCore;
@@ -835,7 +849,7 @@ public class ResolveMerger extends ThreeWayMerger {
private ObjectId insertMergeResult(MergeResult<RawText> result)
throws IOException {
TemporaryBuffer.LocalFile buf = new TemporaryBuffer.LocalFile(
- db != null ? nonNullRepo().getDirectory() : null, 10 << 20);
+ db != null ? nonNullRepo().getDirectory() : null, inCoreLimit);
try {
new MergeFormatter().formatMerge(buf, result,
Arrays.asList(commitNames), CHARACTER_ENCODING);