changeset 579:36e36b926747

Provide means to read user-specific configuration, with no specific repository selected
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 17 Apr 2013 16:06:10 +0200
parents f97e81d13190
children bd5926e24aa3
files src/org/tmatesoft/hg/internal/Internals.java src/org/tmatesoft/hg/repo/HgRepoConfig.java src/org/tmatesoft/hg/repo/HgRepository.java
diffstat 3 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Internals.java	Wed Apr 17 16:02:52 2013 +0200
+++ b/src/org/tmatesoft/hg/internal/Internals.java	Wed Apr 17 16:06:10 2013 +0200
@@ -293,10 +293,11 @@
 	}
 	
 	/**
+	 * User-specific configuration, from system-wide and user home locations, without any repository-specific data.
+	 * 
 	 * @see http://www.selenic.com/mercurial/hgrc.5.html
 	 */
-	public ConfigFile readConfiguration() throws IOException {
-		SessionContext sessionCtx = repo.getSessionContext();
+	public static ConfigFile readConfiguration(SessionContext sessionCtx) throws IOException {
 		ConfigFile configFile = new ConfigFile(sessionCtx);
 		File hgInstallRoot = findHgInstallRoot(sessionCtx); // may be null
 		//
@@ -335,11 +336,21 @@
 			configFile.addLocation(new File("/etc/mercurial/hgrc"));
 			configFile.addLocation(new File(System.getenv("HOME"), ".hgrc"));
 		}
+		return configFile;
+	}
+
+	/**
+	 * Repository-specific configuration
+	 * @see http://www.selenic.com/mercurial/hgrc.5.html
+	 */
+	public ConfigFile readConfiguration() throws IOException {
+		ConfigFile configFile = readConfiguration(repo.getSessionContext());
 		// last one, overrides anything else
 		// <repo>/.hg/hgrc
 		configFile.addLocation(getFileFromRepoDir("hgrc"));
 		return configFile;
 	}
+
 	
 	private static List<File> getWindowsConfigFilesPerInstall(File hgInstallDir) {
 		File f = new File(hgInstallDir, "Mercurial.ini");
--- a/src/org/tmatesoft/hg/repo/HgRepoConfig.java	Wed Apr 17 16:02:52 2013 +0200
+++ b/src/org/tmatesoft/hg/repo/HgRepoConfig.java	Wed Apr 17 16:06:10 2013 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012 TMate Software Ltd
+ * Copyright (c) 2011-2013 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,12 +26,17 @@
 import org.tmatesoft.hg.util.Pair;
 
 /**
- * Repository-specific configuration. 
+ * Repository configuration. 
  * 
+ * @see http://www.selenic.com/mercurial/hgrc.5.html
  * @author Artem Tikhomirov
  * @author TMate Software Ltd.
  */
 public final class HgRepoConfig /*implements RepoChangeListener, perhaps, also RepoChangeNotifier? */{
+	// TODO [1.2+] The name HgRepoConfig is unfortunate, we could've used this class not only for 
+	// repository configuration but system-wide/global configuration, or user configuration (without repo), too.
+	// Perhaps, rename and deprecate?
+	
 	/*ease access for inner classes*/ final ConfigFile config;
 
 	/*package-local*/HgRepoConfig(ConfigFile configFile) {
--- a/src/org/tmatesoft/hg/repo/HgRepository.java	Wed Apr 17 16:02:52 2013 +0200
+++ b/src/org/tmatesoft/hg/repo/HgRepository.java	Wed Apr 17 16:06:10 2013 +0200
@@ -324,6 +324,10 @@
 	}
 
 	
+	/**
+	 * Repository-specific configuration.
+	 * @return access to configuration options, never <code>null</code>
+	 */
 	public HgRepoConfig getConfiguration() /* XXX throws HgInvalidControlFileException? Description of the exception suggests it is only for files under ./hg/*/ {
 		if (repoConfig == null) {
 			try {