# HG changeset patch # User Artem Tikhomirov # Date 1331898663 -3600 # Node ID 30922c728341f84f09184f7bfe6515c6238f557a # Parent 31a719b9f95e670477509a542b4dd652deadb695 Better multiline log printout; options to tune default log output diff -r 31a719b9f95e -r 30922c728341 src/org/tmatesoft/hg/internal/BasicSessionContext.java --- a/src/org/tmatesoft/hg/internal/BasicSessionContext.java Mon Mar 05 15:15:49 2012 +0100 +++ b/src/org/tmatesoft/hg/internal/BasicSessionContext.java Fri Mar 16 12:51:03 2012 +0100 @@ -32,7 +32,7 @@ public class BasicSessionContext implements SessionContext { private PathPool pathPool; - private final LogFacility logFacility; + private LogFacility logFacility; private final Map properties; public BasicSessionContext(PathPool pathFactory, LogFacility log) { @@ -42,7 +42,7 @@ @SuppressWarnings("unchecked") public BasicSessionContext(Map propertyOverrides, PathPool pathFactory, LogFacility log) { pathPool = pathFactory; - logFacility = log != null ? log : new StreamLogFacility(true, true, true, System.out); + logFacility = log; properties = propertyOverrides == null ? Collections.emptyMap() : (Map) propertyOverrides; } @@ -55,10 +55,24 @@ public LogFacility getLog() { // e.g. for exceptions that we can't handle but log (e.g. FileNotFoundException when we've checked beforehand file.canRead() + if (logFacility == null) { + boolean needDebug = _getBooleanProperty("hg.consolelog.debug", false); + boolean needInfo = needDebug || _getBooleanProperty("hg.consolelog.info", false); + logFacility = new StreamLogFacility(needDebug, needInfo, true, System.out); + } return logFacility; } + + private boolean _getBooleanProperty(String name, boolean defaultValue) { + // can't use and unchecked cast because got no confidence passed properties are strictly of the kind of my default values, + // i.e. if boolean from outside comes as "true", while I pass default as Boolean or vice versa. + Object p = getProperty(name, defaultValue); + return p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p)); + } + // TODO specific helpers for boolean and int values public Object getProperty(String name, Object defaultValue) { + // NOTE, this method is invoked from getLog(), hence do not call getLog from here unless changed appropriately Object value = properties.get(name); if (value != null) { return value; diff -r 31a719b9f95e -r 30922c728341 src/org/tmatesoft/hg/internal/Internals.java --- a/src/org/tmatesoft/hg/internal/Internals.java Mon Mar 05 15:15:49 2012 +0100 +++ b/src/org/tmatesoft/hg/internal/Internals.java Fri Mar 16 12:51:03 2012 +0100 @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.StringTokenizer; @@ -320,4 +321,22 @@ public boolean shallCacheRevlogs() { return shallCacheRevlogsInRepo; } + + public static CharSequence join(Iterable col, CharSequence separator) { + if (col == null) { + return String.valueOf(col); + } + Iterator it = col.iterator(); + if (!it.hasNext()) { + return "[]"; + } + String v = String.valueOf(it.next()); + StringBuilder sb = new StringBuilder(v); + while (it.hasNext()) { + sb.append(separator); + v = String.valueOf(it.next()); + sb.append(v); + } + return sb; + } } diff -r 31a719b9f95e -r 30922c728341 src/org/tmatesoft/hg/repo/HgRemoteRepository.java --- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Mon Mar 05 15:15:49 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java Fri Mar 16 12:51:03 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ private final URL url; private final SSLContext sslContext; private final String authInfo; - private final boolean debug = Boolean.parseBoolean(System.getProperty("hg4j.remote.debug")); + private final boolean debug; private HgLookup lookupHelper; private final SessionContext sessionContext; @@ -76,6 +76,8 @@ } this.url = url; sessionContext = ctx; + Object debugProp = ctx.getProperty("hg4j.remote.debug", false); + debug = debugProp instanceof Boolean ? ((Boolean) debugProp).booleanValue() : Boolean.parseBoolean(String.valueOf(debugProp)); if ("https".equals(url.getProtocol())) { try { sslContext = SSLContext.getInstance("SSL"); diff -r 31a719b9f95e -r 30922c728341 src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Mon Mar 05 15:15:49 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Fri Mar 16 12:51:03 2012 +0100 @@ -34,6 +34,7 @@ import org.tmatesoft.hg.internal.DataAccessProvider; import org.tmatesoft.hg.internal.Experimental; import org.tmatesoft.hg.internal.Filter; +import org.tmatesoft.hg.internal.Internals; import org.tmatesoft.hg.internal.RevlogStream; import org.tmatesoft.hg.internal.SubrepoManager; import org.tmatesoft.hg.util.CancelledException; @@ -323,7 +324,7 @@ try { final List errors = ignore.read(ignoreFile); if (errors != null) { - getContext().getLog().warn(getClass(), "Syntax errors parsing .hgignore:\n%s", errors); + getContext().getLog().warn(getClass(), "Syntax errors parsing .hgignore:\n%s", Internals.join(errors, ",\n")); } } catch (IOException ex) { final String m = "Error reading .hgignore file";