git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 4/5] Add no fallback constructor to FileBasedConfig

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 29, 2009, 15:50 UTC
Message-ID
<1248882627-7285-5-git-send-email-spearce@spearce.org>
In-Reply-To
<1248882627-7285-4-git-send-email-spearce@spearce.org>

Sometimes when reading a FileBasedConfig the caller does not want any fallback lookup. Instead always passing a null first parameter to the constructor, we can use a 1-arg constructor that takes only the File path for this file. This simplifies a number of cases within the JGit library and test cases, as well as some application code.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../tst/org/spearce/jgit/lib/MockSystemReader.java |    2 +-
 .../org/spearce/jgit/lib/RepositoryTestCase.java   |    2 +-
 .../src/org/spearce/jgit/lib/FileBasedConfig.java  |   10 ++++++++++
 .../src/org/spearce/jgit/util/SystemReader.java    |    3 +--
 4 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MockSystemReader.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MockSystemReader.java
index 62862d1..7a65f99 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MockSystemReader.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/MockSystemReader.java
@@ -53,7 +53,7 @@
 		init(Constants.GIT_AUTHOR_EMAIL_KEY);
 		init(Constants.GIT_COMMITTER_NAME_KEY);
 		init(Constants.GIT_COMMITTER_EMAIL_KEY);
-		userGitConfig = new FileBasedConfig(null, null);
+		userGitConfig = new FileBasedConfig(null);
 	}
 
 	private void init(final String n) {
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index 24a99ca..6de9afe 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -237,7 +237,7 @@ public void run() {
 		}
 
 		final MockSystemReader mockSystemReader = new MockSystemReader();
-		mockSystemReader.userGitConfig = new FileBasedConfig(null, new File(
+		mockSystemReader.userGitConfig = new FileBasedConfig(new File(
 				trash_git, "usergitconfig"));
 		SystemReader.setInstance(mockSystemReader);
 
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/FileBasedConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/FileBasedConfig.java
index a419e7f..adf85c6 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/FileBasedConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/FileBasedConfig.java
@@ -55,6 +55,16 @@
 	private final File configFile;
 
 	/**
+	 * Create a configuration with no default fallback.
+	 *
+	 * @param cfgLocation
+	 *            the location of the configuration file on the file system
+	 */
+	public FileBasedConfig(File cfgLocation) {
+		this(null, cfgLocation);
+	}
+
+	/**
 	 * The constructor
 	 *
 	 * @param base
diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/SystemReader.java b/org.spearce.jgit/src/org/spearce/jgit/util/SystemReader.java
index a30dfef..51a0d29 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/SystemReader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/SystemReader.java
@@ -42,7 +42,6 @@
 import java.net.UnknownHostException;
 
 import org.spearce.jgit.lib.FileBasedConfig;
-import org.spearce.jgit.lib.RepositoryConfig;
 
 /**
  * Interface to read values from the system.
@@ -66,7 +65,7 @@ public String getProperty(String key) {
 
 		public FileBasedConfig openUserConfig() {
 			final File home = FS.userHome();
-			return new RepositoryConfig(null, new File(home, ".gitconfig"));
+			return new FileBasedConfig(new File(home, ".gitconfig"));
 		}
 
 		public String getHostname() {
-- 
1.6.4.rc3.201.gd9d59
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 5 of 6 in “Some minor bug fixes”
  1. 0/5 Some minor bug fixesShawn O. Pearce, Jul 29, 2009
  2. 1/5 Don't dispose of RevFlag used to advertise objects in ReceivePackShawn O. Pearce, Jul 29, 2009
  3. 2/5 Allow RemoteConfig.getAllRemoteConfigs on any Config objectShawn O. Pearce, Jul 29, 2009
  4. 3/5 Add ConfigInvalidException constructor to take ThrowableShawn O. Pearce, Jul 29, 2009
  5. 4/5 Add no fallback constructor to FileBasedConfigShawn O. Pearce, Jul 29, 2009
  6. 5/5 Include the file path when FileBasedConfig.load throws an exceptionShawn O. Pearce, Jul 29, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.