diff src/org/tmatesoft/hg/internal/Internals.java @ 378:9fb990c8a724

Investigate approaches to alter Mercurial configuration files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 09 Feb 2012 04:15:17 +0100
parents 5abba41751e6
children fa2be7a05af6
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Internals.java	Thu Feb 02 16:16:19 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/Internals.java	Thu Feb 09 04:15:17 2012 +0100
@@ -122,6 +122,7 @@
 			//
 			// XXX perhaps, makes sense to compare getenv(USERPROFILE) and getenv(HOME) and use 
 			// them if set (and use both if their values do not match). Only if both not set, rely to user.home?
+			// Also respect #getUserConfigurationFileToWrite() below
 			configFile.addLocation(new File(System.getProperty("user.home"), "Mercurial.ini"));
 		} else {
 			// FIXME read from install-root
@@ -143,4 +144,33 @@
 		configFile.addLocation(new File(repoRoot, "hgrc"));
 		return configFile;
 	}
+
+	/**
+	 * @return
+	 */
+	public static File getInstallationConfigurationFileToWrite() {
+		// TODO Auto-generated method stub
+		// FIXME find out install-root 
+		throw new UnsupportedOperationException();
+	}
+
+	/**
+	 * @return
+	 */
+	public static File getUserConfigurationFileToWrite() {
+		final File rv = new File(System.getProperty("user.home"), ".hgrc");
+		if (rv.exists() && rv.canWrite()) {
+			return rv;
+		}
+		if (runningOnWindows()) {
+			// try another well-known location
+			// TODO comment above regarding USERPROFILE and HOME variables applies here as well
+			File f = new File(System.getProperty("user.home"), "Mercurial.ini");
+			if (f.exists() && f.canWrite()) {
+				return f;
+			}
+		}
+		// fallback to default value
+		return rv; 
+	}
 }