aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2010-04-13 04:16:58 -0400
committerCode Review <codereview-daemon@eclipse.org>2010-04-13 04:16:58 -0400
commitd29618dd41d1dd52972524b4e25679bcf7baa39c (patch)
tree93d41ecf48fd4b2c2815a82c7c3f1faad5c973ae
parent333a0536a7668684c5ce28e9876b1e8566ffdb53 (diff)
parentcc905e7d4be2334cdea984cf478901e904770292 (diff)
downloadjgit-d29618dd41d1dd52972524b4e25679bcf7baa39c.tar.gz
jgit-d29618dd41d1dd52972524b4e25679bcf7baa39c.zip
Merge "Make Repository.getConfig aware of changed config"
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/FileBasedConfig.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java58
2 files changed, 53 insertions, 17 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileBasedConfig.java
index 72dfec6e01..315c4670ad 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileBasedConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileBasedConfig.java
@@ -62,6 +62,7 @@ import org.eclipse.jgit.util.RawParseUtils;
*/
public class FileBasedConfig extends Config {
private final File configFile;
+ private volatile long lastModified;
/**
* Create a configuration with no default fallback.
@@ -103,6 +104,7 @@ public class FileBasedConfig extends Config {
* the file is not a properly formatted configuration file.
*/
public void load() throws IOException, ConfigInvalidException {
+ lastModified = getFile().lastModified();
try {
fromText(RawParseUtils.decode(IO.readFully(getFile())));
} catch (FileNotFoundException noFile) {
@@ -134,16 +136,26 @@ public class FileBasedConfig extends Config {
if (!lf.lock())
throw new IOException("Cannot lock " + getFile());
try {
+ lf.setNeedStatInformation(true);
lf.write(out);
if (!lf.commit())
throw new IOException("Cannot commit write to " + getFile());
} finally {
lf.unlock();
}
+ lastModified = lf.getCommitLastModified();
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + getFile().getPath() + "]";
}
+
+ /**
+ * @return returns true if the currently loaded configuration file is older
+ * than the file on disk
+ */
+ public boolean isOutdated() {
+ return getFile().lastModified() != lastModified;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index c00d81dcd1..e2d3da6bc2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -96,6 +96,8 @@ public class Repository {
private final File gitDir;
+ private final FileBasedConfig userConfig;
+
private final RepositoryConfig config;
private final RefDatabase refs;
@@ -191,26 +193,11 @@ public class Repository {
throw new IllegalArgumentException("Either GIT_DIR or GIT_WORK_TREE must be passed to Repository constructor");
}
- final FileBasedConfig userConfig;
userConfig = SystemReader.getInstance().openUserConfig();
- try {
- userConfig.load();
- } catch (ConfigInvalidException e1) {
- IOException e2 = new IOException("User config file "
- + userConfig.getFile().getAbsolutePath() + " invalid: "
- + e1);
- e2.initCause(e1);
- throw e2;
- }
config = new RepositoryConfig(userConfig, FS.resolve(gitDir, "config"));
- try {
- getConfig().load();
- } catch (ConfigInvalidException e1) {
- IOException e2 = new IOException("Unknown repository format");
- e2.initCause(e1);
- throw e2;
- }
+ loadUserConfig();
+ loadConfig();
if (workDir == null) {
String workTreeConfig = getConfig().getString("core", null, "worktree");
@@ -244,6 +231,29 @@ public class Repository {
}
}
+ private void loadUserConfig() throws IOException {
+ try {
+ userConfig.load();
+ } catch (ConfigInvalidException e1) {
+ IOException e2 = new IOException("User config file "
+ + userConfig.getFile().getAbsolutePath() + " invalid: "
+ + e1);
+ e2.initCause(e1);
+ throw e2;
+ }
+ }
+
+ private void loadConfig() throws IOException {
+ try {
+ config.load();
+ } catch (ConfigInvalidException e1) {
+ IOException e2 = new IOException("Unknown repository format");
+ e2.initCause(e1);
+ throw e2;
+ }
+ }
+
+
/**
* Create a new Git repository initializing the necessary files and
* directories. Repository with working tree is created using this method.
@@ -320,6 +330,20 @@ public class Repository {
* @return the configuration of this repository
*/
public RepositoryConfig getConfig() {
+ if (userConfig.isOutdated()) {
+ try {
+ loadUserConfig();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (config.isOutdated()) {
+ try {
+ loadConfig();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
return config;
}