summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-12-13 14:18:05 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-12-15 15:14:05 -0800
commit013cb8de3824c304645a9c5db87c2e80286872d1 (patch)
treed620e6700503a34b6da2359d238cbd2fda914ce9 /org.eclipse.jgit
parent86847ee3224ac93da478bc5cdb8a79140ee6edac (diff)
downloadjgit-013cb8de3824c304645a9c5db87c2e80286872d1.tar.gz
jgit-013cb8de3824c304645a9c5db87c2e80286872d1.zip
Reduce calls to Repository.getConfig
Each time getConfig() is called on FileRepository, it checks the last modified time of both ~/.gitconfig and $GIT_DIR?config. If $GIT_DIR/config appears to have been modified, it is read back in from disk and the current config is wiped out. When mutating a configuration file, this may cause in-memory edits to disappear. To avoid that callers need to avoid calling getConfig until after the configuration has been saved to disk. Unfortunately the API is still horribly broken. Configuration should be modified only while a lock is held on the configuration file, very similar to the way a ref is updated via its locking protocol. But our existing API is really broken for that so we'll have to defer cleaning up the edit path for a future change. Change-Id: I5888dd97bac20ddf60456c81ffc1eb8df04ef410 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java2
4 files changed, 14 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
index fa00581d07..a88dd2a7e0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
@@ -59,6 +59,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -156,10 +157,11 @@ public class DeleteBranchCommand extends GitCommand<List<String>> {
String shortenedName = fullName
.substring(Constants.R_HEADS.length());
// remove upstream configuration if any
- repo.getConfig().unsetSection(
+ final StoredConfig cfg = repo.getConfig();
+ cfg.unsetSection(
ConfigConstants.CONFIG_BRANCH_SECTION,
shortenedName);
- repo.getConfig().save();
+ cfg.save();
}
} else
throw new JGitInternalException(MessageFormat.format(
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
index 4fe050b2a3..adcea90f56 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
@@ -186,7 +186,7 @@ public class PullCommand extends GitCommand<PullResult> {
String remoteUri;
FetchResult fetchRes;
if (isRemote) {
- remoteUri = repo.getConfig().getString("remote", remote,
+ remoteUri = repoConfig.getString("remote", remote,
ConfigConstants.CONFIG_KEY_URL);
if (remoteUri == null) {
String missingKey = ConfigConstants.CONFIG_REMOTE_SECTION + DOT
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
index 4654981329..04b7791d66 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
@@ -58,6 +58,7 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefRename;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.lib.RefUpdate.Result;
/**
@@ -144,27 +145,28 @@ public class RenameBranchCommand extends GitCommand<Ref> {
// move the upstream configuration over to the new branch
String shortOldName = fullOldName
.substring(Constants.R_HEADS.length());
- String oldRemote = repo.getConfig().getString(
+ final StoredConfig repoConfig = repo.getConfig();
+ String oldRemote = repoConfig.getString(
ConfigConstants.CONFIG_BRANCH_SECTION,
shortOldName, ConfigConstants.CONFIG_KEY_REMOTE);
if (oldRemote != null) {
- repo.getConfig().setString(
+ repoConfig.setString(
ConfigConstants.CONFIG_BRANCH_SECTION, newName,
ConfigConstants.CONFIG_KEY_REMOTE, oldRemote);
}
- String oldMerge = repo.getConfig().getString(
+ String oldMerge = repoConfig.getString(
ConfigConstants.CONFIG_BRANCH_SECTION,
shortOldName, ConfigConstants.CONFIG_KEY_MERGE);
if (oldMerge != null) {
- repo.getConfig().setString(
+ repoConfig.setString(
ConfigConstants.CONFIG_BRANCH_SECTION, newName,
ConfigConstants.CONFIG_KEY_MERGE, oldMerge);
}
- repo.getConfig()
+ repoConfig
.unsetSection(
ConfigConstants.CONFIG_BRANCH_SECTION,
shortOldName);
- repo.getConfig().save();
+ repoConfig.save();
}
} else
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
index a145e7725c..417fa4b53e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java
@@ -160,7 +160,7 @@ public class FileRepository extends Repository {
loadUserConfig();
loadRepoConfig();
- getConfig().addChangeListener(new ConfigChangedListener() {
+ repoConfig.addChangeListener(new ConfigChangedListener() {
public void onConfigChanged(ConfigChangedEvent event) {
fireEvent(event);
}