changeset 504:bf352ce2b97f

Allow to override lock timeout from within Hg4J
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 30 Nov 2012 21:58:00 +0100
parents 0bd2d0441d8f
children 3cd3c3d37432
files src/org/tmatesoft/hg/internal/Internals.java src/org/tmatesoft/hg/repo/HgRepository.java
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/Internals.java	Wed Oct 31 15:17:21 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/Internals.java	Fri Nov 30 21:58:00 2012 +0100
@@ -73,6 +73,19 @@
 	 */
 	public static final String CFG_PROPERTY_FS_FILENAME_ENCODING = "hg.fs.filename.encoding";
 	
+	/**
+	 * Timeout, in seconds, to acquire filesystem {@link HgRepositoryLock lock}.
+	 * 
+	 * Mercurial provides 'ui.timeout' in hgrc (defaults to 600 seconds) to specify how long 
+	 * it shall try to acquire a lock for storage or working directory prior to fail.
+	 *  
+	 * This configuration property allows to override timeout value from Mercurial's configuration
+	 * file and use Hg4J-specific value instead. 
+	 * 
+	 * Integer value, use negative for attempts to acquire lock until success, and zero to try once and fail immediately. 
+	 */
+	public static final String CFG_PROPERTY_FS_LOCK_TIMEOUT = "hg4j.fs.lock.timeout";
+	
 	private List<Filter.Factory> filterFactories;
 	private final HgRepository repo;
 	private final File repoDir;
--- a/src/org/tmatesoft/hg/repo/HgRepository.java	Wed Oct 31 15:17:21 2012 +0100
+++ b/src/org/tmatesoft/hg/repo/HgRepository.java	Fri Nov 30 21:58:00 2012 +0100
@@ -37,6 +37,7 @@
 import org.tmatesoft.hg.internal.Experimental;
 import org.tmatesoft.hg.internal.Filter;
 import org.tmatesoft.hg.internal.Internals;
+import org.tmatesoft.hg.internal.PropertyMarshal;
 import org.tmatesoft.hg.internal.RevlogStream;
 import org.tmatesoft.hg.internal.SubrepoManager;
 import org.tmatesoft.hg.repo.ext.HgExtensionsManager;
@@ -558,6 +559,10 @@
 	}
 
 	private int getLockTimeout() {
-		return getConfiguration().getIntegerValue("ui", "timeout", 600);
+		int cfgValue = getConfiguration().getIntegerValue("ui", "timeout", 600);
+		if (getSessionContext().getConfigurationProperty(Internals.CFG_PROPERTY_FS_LOCK_TIMEOUT, null) != null) {
+			return new PropertyMarshal(sessionContext).getInt(Internals.CFG_PROPERTY_FS_LOCK_TIMEOUT, cfgValue);
+		}
+		return cfgValue;
 	}
 }