comparison src/org/tmatesoft/hg/internal/Internals.java @ 382:82336b7c54f4

Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 10 Feb 2012 13:56:24 +0100
parents fa2be7a05af6
children b015f3918120
comparison
equal deleted inserted replaced
381:6e37c7168585 382:82336b7c54f4
26 import java.util.Collections; 26 import java.util.Collections;
27 import java.util.LinkedHashSet; 27 import java.util.LinkedHashSet;
28 import java.util.List; 28 import java.util.List;
29 import java.util.StringTokenizer; 29 import java.util.StringTokenizer;
30 30
31 import org.tmatesoft.hg.core.SessionContext;
31 import org.tmatesoft.hg.repo.HgInternals; 32 import org.tmatesoft.hg.repo.HgInternals;
32 import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection; 33 import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection;
33 import org.tmatesoft.hg.repo.HgRepository; 34 import org.tmatesoft.hg.repo.HgRepository;
34 import org.tmatesoft.hg.util.PathRewrite; 35 import org.tmatesoft.hg.util.PathRewrite;
35 36
122 } 123 }
123 124
124 /** 125 /**
125 * For Unix, returns installation root, which is the parent directory of the hg executable (or symlink) being run. 126 * For Unix, returns installation root, which is the parent directory of the hg executable (or symlink) being run.
126 * For Windows, it's Mercurial installation directory itself 127 * For Windows, it's Mercurial installation directory itself
128 * @param ctx
127 */ 129 */
128 private static File findHgInstallRoot() { 130 private static File findHgInstallRoot(SessionContext ctx) {
129 // let clients to override Hg install location 131 // let clients to override Hg install location
130 String p = System.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT); 132 String p = (String) ctx.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT, null);
131 if (p != null) { 133 if (p != null) {
132 return new File(p); 134 return new File(p);
133 } 135 }
134 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), System.getProperty("path.separator"), false); 136 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), System.getProperty("path.separator"), false);
135 final boolean runsOnWin = runningOnWindows(); 137 final boolean runsOnWin = runningOnWindows();
148 /** 150 /**
149 * @see http://www.selenic.com/mercurial/hgrc.5.html 151 * @see http://www.selenic.com/mercurial/hgrc.5.html
150 */ 152 */
151 public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException { 153 public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException {
152 ConfigFile configFile = new ConfigFile(); 154 ConfigFile configFile = new ConfigFile();
153 File hgInstallRoot = findHgInstallRoot(); // may be null 155 File hgInstallRoot = findHgInstallRoot(HgInternals.getContext(hgRepo)); // may be null
154 // 156 //
155 if (runningOnWindows()) { 157 if (runningOnWindows()) {
156 if (hgInstallRoot != null) { 158 if (hgInstallRoot != null) {
157 for (File f : getWindowsConfigFilesPerInstall(hgInstallRoot)) { 159 for (File f : getWindowsConfigFilesPerInstall(hgInstallRoot)) {
158 configFile.addLocation(f); 160 configFile.addLocation(f);
225 } 227 }
226 } 228 }
227 return rv; 229 return rv;
228 } 230 }
229 231
230 public static File getInstallationConfigurationFileToWrite() { 232 public static File getInstallationConfigurationFileToWrite(SessionContext ctx) {
231 File hgInstallRoot = findHgInstallRoot(); // may be null 233 File hgInstallRoot = findHgInstallRoot(ctx); // may be null
232 // choice of which hgrc to pick here is according to my own pure discretion 234 // choice of which hgrc to pick here is according to my own pure discretion
233 if (hgInstallRoot != null) { 235 if (hgInstallRoot != null) {
234 // use this location only if it's writable 236 // use this location only if it's writable
235 File cfg = new File(hgInstallRoot, runningOnWindows() ? "Mercurial.ini" : "etc/mercurial/hgrc"); 237 File cfg = new File(hgInstallRoot, runningOnWindows() ? "Mercurial.ini" : "etc/mercurial/hgrc");
236 if (cfg.canWrite() || cfg.getParentFile().canWrite()) { 238 if (cfg.canWrite() || cfg.getParentFile().canWrite()) {
249 } else { 251 } else {
250 return new File("/etc/mercurial/hgrc"); 252 return new File("/etc/mercurial/hgrc");
251 } 253 }
252 } 254 }
253 255
254 public static File getUserConfigurationFileToWrite() { 256 public static File getUserConfigurationFileToWrite(SessionContext ctx) {
255 LinkedHashSet<String> locations = new LinkedHashSet<String>(); 257 LinkedHashSet<String> locations = new LinkedHashSet<String>();
256 final boolean runsOnWindows = runningOnWindows(); 258 final boolean runsOnWindows = runningOnWindows();
257 if (runsOnWindows) { 259 if (runsOnWindows) {
258 locations.add(System.getenv("USERPROFILE")); 260 locations.add(System.getenv("USERPROFILE"));
259 } 261 }