# HG changeset patch # User Artem Tikhomirov # Date 1328878584 -3600 # Node ID 82336b7c54f43e2e1bb5cbbd68c736d1197a59e6 # Parent 6e37c71685853444c4b226dc1e4f2b795874f39c Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation diff -r 6e37c7168585 -r 82336b7c54f4 src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java --- a/src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java Thu Feb 09 19:07:29 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java Fri Feb 10 13:56:24 2012 +0100 @@ -26,6 +26,7 @@ import org.tmatesoft.hg.internal.ConfigFile; import org.tmatesoft.hg.internal.Experimental; import org.tmatesoft.hg.internal.Internals; +import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgRepository; /** @@ -37,27 +38,26 @@ @Experimental(reason="Investigating approaches to alter Hg configuration files") public final class HgUpdateConfigCommand extends HgAbstractCommand { - private final HgRepository repo; private final File configFile; private Map> toRemove; private Map> toSet; - private HgUpdateConfigCommand(HgRepository hgRepo, File configurationFile) { - repo = hgRepo; + private HgUpdateConfigCommand(File configurationFile) { configFile = configurationFile; } public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) { - return new HgUpdateConfigCommand(hgRepo, new File(".hg/hgrc")); + // XXX HgRepository to implement SessionContextProvider (with getContext())? + return new HgUpdateConfigCommand(new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); } - public static HgUpdateConfigCommand forUser(HgRepository hgRepo) { - return new HgUpdateConfigCommand(null, Internals.getUserConfigurationFileToWrite()); + public static HgUpdateConfigCommand forUser(SessionContext ctx) { + return new HgUpdateConfigCommand(Internals.getUserConfigurationFileToWrite(ctx)); } - public static HgUpdateConfigCommand forInstallation() { - return new HgUpdateConfigCommand(null, Internals.getInstallationConfigurationFileToWrite()); + public static HgUpdateConfigCommand forInstallation(SessionContext ctx) { + return new HgUpdateConfigCommand(Internals.getInstallationConfigurationFileToWrite(ctx)); } /** diff -r 6e37c7168585 -r 82336b7c54f4 src/org/tmatesoft/hg/internal/Internals.java --- a/src/org/tmatesoft/hg/internal/Internals.java Thu Feb 09 19:07:29 2012 +0100 +++ b/src/org/tmatesoft/hg/internal/Internals.java Fri Feb 10 13:56:24 2012 +0100 @@ -28,6 +28,7 @@ import java.util.List; import java.util.StringTokenizer; +import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.repo.HgInternals; import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection; import org.tmatesoft.hg.repo.HgRepository; @@ -124,10 +125,11 @@ /** * For Unix, returns installation root, which is the parent directory of the hg executable (or symlink) being run. * For Windows, it's Mercurial installation directory itself + * @param ctx */ - private static File findHgInstallRoot() { + private static File findHgInstallRoot(SessionContext ctx) { // let clients to override Hg install location - String p = System.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT); + String p = (String) ctx.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT, null); if (p != null) { return new File(p); } @@ -150,7 +152,7 @@ */ public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException { ConfigFile configFile = new ConfigFile(); - File hgInstallRoot = findHgInstallRoot(); // may be null + File hgInstallRoot = findHgInstallRoot(HgInternals.getContext(hgRepo)); // may be null // if (runningOnWindows()) { if (hgInstallRoot != null) { @@ -227,8 +229,8 @@ return rv; } - public static File getInstallationConfigurationFileToWrite() { - File hgInstallRoot = findHgInstallRoot(); // may be null + public static File getInstallationConfigurationFileToWrite(SessionContext ctx) { + File hgInstallRoot = findHgInstallRoot(ctx); // may be null // choice of which hgrc to pick here is according to my own pure discretion if (hgInstallRoot != null) { // use this location only if it's writable @@ -251,7 +253,7 @@ } } - public static File getUserConfigurationFileToWrite() { + public static File getUserConfigurationFileToWrite(SessionContext ctx) { LinkedHashSet locations = new LinkedHashSet(); final boolean runsOnWindows = runningOnWindows(); if (runsOnWindows) { diff -r 6e37c7168585 -r 82336b7c54f4 src/org/tmatesoft/hg/repo/HgInternals.java --- a/src/org/tmatesoft/hg/repo/HgInternals.java Thu Feb 09 19:07:29 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/HgInternals.java Fri Feb 10 13:56:24 2012 +0100 @@ -83,8 +83,8 @@ return rv; } - public File getRepositoryDir() { - return repo.getRepositoryRoot(); + public static File getRepositoryDir(HgRepository hgRepo) { + return hgRepo.getRepositoryRoot(); } public static HgIgnore newHgIgnore(Reader source) throws IOException {