diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-12-13 14:18:05 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-12-15 15:14:05 -0800 |
commit | 013cb8de3824c304645a9c5db87c2e80286872d1 (patch) | |
tree | d620e6700503a34b6da2359d238cbd2fda914ce9 /org.eclipse.jgit.pgm | |
parent | 86847ee3224ac93da478bc5cdb8a79140ee6edac (diff) | |
download | jgit-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.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 0bc72a71e1..8eccdedc3f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -65,6 +65,7 @@ import org.eclipse.jgit.lib.Tree; import org.eclipse.jgit.lib.WorkDirCheckout; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.storage.file.FileRepository; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.RefSpec; @@ -110,8 +111,9 @@ class Clone extends AbstractFetchCommand { dst = new FileRepository(gitdir); dst.create(); - dst.getConfig().setBoolean("core", null, "bare", false); - dst.getConfig().save(); + final FileBasedConfig dstcfg = dst.getConfig(); + dstcfg.setBoolean("core", null, "bare", false); + dstcfg.save(); db = dst; out.print(MessageFormat.format( @@ -128,13 +130,14 @@ class Clone extends AbstractFetchCommand { private void saveRemote(final URIish uri) throws URISyntaxException, IOException { - final RemoteConfig rc = new RemoteConfig(dst.getConfig(), remoteName); + final FileBasedConfig dstcfg = dst.getConfig(); + final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName); rc.addURI(uri); rc.addFetchRefSpec(new RefSpec().setForceUpdate(true) .setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + remoteName + "/*")); - rc.update(dst.getConfig()); - dst.getConfig().save(); + rc.update(dstcfg); + dstcfg.save(); } private FetchResult runFetch() throws NotSupportedException, |