Mercurial > hg4j
changeset 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 | 6e37c7168585 |
children | 994b5813a925 |
files | src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java src/org/tmatesoft/hg/internal/Internals.java src/org/tmatesoft/hg/repo/HgInternals.java |
diffstat | 3 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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<HgUpdateConfigCommand> { - private final HgRepository repo; private final File configFile; private Map<String,List<String>> toRemove; private Map<String,Map<String,String>> 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)); } /**
--- 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<String> locations = new LinkedHashSet<String>(); final boolean runsOnWindows = runningOnWindows(); if (runsOnWindows) {
--- 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 {