annotate src/org/tmatesoft/hg/internal/Internals.java @ 411:464b4404e75d smartgit3

Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 20 Mar 2012 17:56:50 +0100
parents 0f5696623512
children 63c5a9d7ca3f
rev   line source
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 83
diff changeset
15 * contact TMate Software at support@hg4j.com
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
19 import static org.tmatesoft.hg.internal.RequiresFile.*;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
21 import java.io.File;
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
22 import java.io.FileOutputStream;
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
23 import java.io.IOException;
411
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
24 import java.nio.charset.Charset;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
25 import java.util.ArrayList;
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
26 import java.util.Arrays;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
27 import java.util.Collections;
407
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
28 import java.util.Iterator;
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
29 import java.util.LinkedHashSet;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
30 import java.util.List;
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
31 import java.util.StringTokenizer;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
32
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
33 import org.tmatesoft.hg.core.SessionContext;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
34 import org.tmatesoft.hg.repo.HgInternals;
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
35 import org.tmatesoft.hg.repo.HgRepoConfig.ExtensionsSection;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
36 import org.tmatesoft.hg.repo.HgRepository;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 import org.tmatesoft.hg.util.PathRewrite;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 /**
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 * Fields/members that shall not be visible
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author TMate Software Ltd.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 */
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
45 public final class Internals {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
47 /**
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
48 * Allows to specify Mercurial installation directory to detect installation-wide configurations.
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
49 * Without this property set, hg4j would attempt to deduce this value locating hg executable.
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
50 */
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
51 public static final String CFG_PROPERTY_HG_INSTALL_ROOT = "hg4j.hg.install_root";
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
52
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
53 /**
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
54 * Tells repository not to cache files/revlogs
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
55 * XXX perhaps, need to respect this property not only for data files, but for manifest and changelog as well?
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
56 * (@see HgRepository#getChangelog and #getManifest())
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
57 */
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
58 public static final String CFG_PROPERTY_REVLOG_STREAM_CACHE = "hg4j.repo.disable_revlog_cache";
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
59
411
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
60 /**
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
61 * Name of charset to use when translating Unicode filenames to Mercurial storage paths, string,
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
62 * to resolve with {@link Charset#forName(String)}.
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
63 * E.g. <code>"cp1251"</code> or <code>"Latin-1"</code>.
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
64 *
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
65 * <p>Mercurial uses system encoding when mangling storage paths. Default value
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
66 * based on 'file.encoding' Java system property is usually fine here, however
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
67 * in certain scenarios it may be desirable to force a different one, and this
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
68 * property is exactly for this purpose.
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
69 *
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
70 * <p>E.g. Eclipse defaults to project encoding (Launch config, Common page) when launching an application,
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
71 * and if your project happen to use anything but filesystem default (say, UTF8 on cp1251 system),
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
72 * native storage paths won't match
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
73 */
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
74 public static final String CFG_PROPERT_FS_FILENAME_ENCODING = "hg.fs.filename.encoding";
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
75
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 private int requiresFlags = 0;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
77 private List<Filter.Factory> filterFactories;
411
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
78 private final SessionContext sessionContext;
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
79 private final boolean isCaseSensitiveFileSystem;
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
80 private final boolean shallCacheRevlogsInRepo;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
81
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
82 public Internals(SessionContext ctx) {
411
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
83 this.sessionContext = ctx;
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
84 isCaseSensitiveFileSystem = !runningOnWindows();
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
85 Object p = ctx.getProperty(CFG_PROPERTY_REVLOG_STREAM_CACHE, true);
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
86 shallCacheRevlogsInRepo = p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p));
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
87 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
88
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
89 public void parseRequires(HgRepository hgRepo, File requiresFile) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
90 try {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
91 new RequiresFile().parse(this, requiresFile);
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
92 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
93 // FIXME not quite sure error reading requires file shall be silently logged only.
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
94 HgInternals.getContext(hgRepo).getLog().error(getClass(), ex, null);
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
95 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 292
diff changeset
96 }
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97
83
a5275143664c Complete path hash calculation of fncache requirement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
98 public/*for tests, otherwise pkg*/ void setStorageConfig(int version, int flags) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 requiresFlags = flags;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
101
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
102 public PathRewrite buildNormalizePathRewrite() {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
103 if (runningOnWindows()) {
409
0f5696623512 Support glob path pattern rewrite to facilitate use of globs with Windows path separator
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 407
diff changeset
104 return new WinToNixPathRewrite();
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
105 } else {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
106 return new PathRewrite.Empty(); // or strip leading slash, perhaps?
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
107 }
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
108 }
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 // XXX perhaps, should keep both fields right here, not in the HgRepository
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 public PathRewrite buildDataFilesHelper() {
411
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
112 Object altEncoding = sessionContext.getProperty(CFG_PROPERT_FS_FILENAME_ENCODING, null);
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
113 Charset cs;
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
114 if (altEncoding == null) {
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
115 cs = Charset.defaultCharset();
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
116 } else {
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
117 try {
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
118 cs = Charset.forName(altEncoding.toString());
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
119 } catch (IllegalArgumentException ex) {
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
120 // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
121 // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
122 sessionContext.getLog().error(getClass(), ex, String.format("Bad configuration value for filename encoding %s", altEncoding));
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
123 cs = Charset.defaultCharset();
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
124 }
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
125 }
464b4404e75d Issue 29: Bad storage path translation - translate Unicode chars to filesystem encoding
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 409
diff changeset
126 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs);
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 public PathRewrite buildRepositoryFilesHelper() {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 if ((requiresFlags & STORE) != 0) {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 return new PathRewrite() {
292
a415fe296a50 Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
132 public CharSequence rewrite(CharSequence path) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 return "store/" + path;
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 };
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 } else {
292
a415fe296a50 Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
137 return new PathRewrite.Empty();
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
140
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
141 public List<Filter.Factory> getFilters(HgRepository hgRepo) {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
142 if (filterFactories == null) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
143 filterFactories = new ArrayList<Filter.Factory>();
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
144 ExtensionsSection cfg = hgRepo.getConfiguration().getExtensions();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
145 if (cfg.isEnabled("eol")) {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
146 NewlineFilter.Factory ff = new NewlineFilter.Factory();
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
147 ff.initialize(hgRepo);
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
148 filterFactories.add(ff);
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
149 }
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
150 if (cfg.isEnabled("keyword")) {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
151 KeywordFilter.Factory ff = new KeywordFilter.Factory();
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
152 ff.initialize(hgRepo);
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
153 filterFactories.add(ff);
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
154 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
155 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
156 return filterFactories;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
157 }
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
158
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
159 public void initEmptyRepository(File hgDir) throws IOException {
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
160 hgDir.mkdir();
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
161 FileOutputStream requiresFile = new FileOutputStream(new File(hgDir, "requires"));
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
162 StringBuilder sb = new StringBuilder(40);
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
163 sb.append("revlogv1\n");
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
164 if ((requiresFlags & STORE) != 0) {
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
165 sb.append("store\n");
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
166 }
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
167 if ((requiresFlags & FNCACHE) != 0) {
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
168 sb.append("fncache\n");
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
169 }
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
170 if ((requiresFlags & DOTENCODE) != 0) {
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
171 sb.append("dotencode\n");
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
172 }
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
173 requiresFile.write(sb.toString().getBytes());
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
174 requiresFile.close();
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
175 new File(hgDir, "store").mkdir(); // with that, hg verify says ok.
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
176 }
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
177
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
178 public boolean isCaseSensitiveFileSystem() {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
179 return isCaseSensitiveFileSystem;
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
180 }
202
706bcc7cfee4 Basic test for HgIncomingCommand. Fix RepositoryComparator for cases when whole repository is unknown. Respect freshly initialized (empty) repositories in general.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 150
diff changeset
181
292
a415fe296a50 Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
182 public static boolean runningOnWindows() {
a415fe296a50 Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
183 return System.getProperty("os.name").indexOf("Windows") != -1;
a415fe296a50 Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 202
diff changeset
184 }
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
185
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
186 /**
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
187 * For Unix, returns installation root, which is the parent directory of the hg executable (or symlink) being run.
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
188 * For Windows, it's Mercurial installation directory itself
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
189 * @param ctx
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
190 */
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
191 private static File findHgInstallRoot(SessionContext ctx) {
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
192 // let clients to override Hg install location
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
193 String p = (String) ctx.getProperty(CFG_PROPERTY_HG_INSTALL_ROOT, null);
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
194 if (p != null) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
195 return new File(p);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
196 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
197 StringTokenizer st = new StringTokenizer(System.getenv("PATH"), System.getProperty("path.separator"), false);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
198 final boolean runsOnWin = runningOnWindows();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
199 while (st.hasMoreTokens()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
200 String pe = st.nextToken();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
201 File execCandidate = new File(pe, runsOnWin ? "hg.exe" : "hg");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
202 if (execCandidate.exists() && execCandidate.isFile()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
203 File execDir = execCandidate.getParentFile();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
204 // e.g. on Unix runs "/shared/tools/bin/hg", directory of interest is "/shared/tools/"
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
205 return runsOnWin ? execDir : execDir.getParentFile();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
206 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
207 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
208 return null;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
209 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
210
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
211 /**
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
212 * @see http://www.selenic.com/mercurial/hgrc.5.html
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
213 */
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
214 public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
215 ConfigFile configFile = new ConfigFile();
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
216 File hgInstallRoot = findHgInstallRoot(HgInternals.getContext(hgRepo)); // may be null
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
217 //
351
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
218 if (runningOnWindows()) {
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
219 if (hgInstallRoot != null) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
220 for (File f : getWindowsConfigFilesPerInstall(hgInstallRoot)) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
221 configFile.addLocation(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
222 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
223 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
224 LinkedHashSet<String> locations = new LinkedHashSet<String>();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
225 locations.add(System.getenv("USERPROFILE"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
226 locations.add(System.getenv("HOME"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
227 locations.remove(null);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
228 for (String loc : locations) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
229 File location = new File(loc);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
230 configFile.addLocation(new File(location, "Mercurial.ini"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
231 configFile.addLocation(new File(location, ".hgrc"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
232 }
351
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
233 } else {
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
234 if (hgInstallRoot != null) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
235 File d = new File(hgInstallRoot, "etc/mercurial/hgrc.d/");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
236 if (d.isDirectory() && d.canRead()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
237 for (File f : listConfigFiles(d)) {
351
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
238 configFile.addLocation(f);
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
239 }
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
240 }
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
241 configFile.addLocation(new File(hgInstallRoot, "etc/mercurial/hgrc"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
242 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
243 // same, but with absolute paths
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
244 File d = new File("/etc/mercurial/hgrc.d/");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
245 if (d.isDirectory() && d.canRead()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
246 for (File f : listConfigFiles(d)) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
247 configFile.addLocation(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
248 }
351
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
249 }
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
250 configFile.addLocation(new File("/etc/mercurial/hgrc"));
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
251 configFile.addLocation(new File(System.getenv("HOME"), ".hgrc"));
351
5abba41751e6 Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
252 }
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
253 // last one, overrides anything else
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
254 // <repo>/.hg/hgrc
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
255 configFile.addLocation(new File(repoRoot, "hgrc"));
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
256 return configFile;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
257 }
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
258
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
259 private static List<File> getWindowsConfigFilesPerInstall(File hgInstallDir) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
260 File f = new File(hgInstallDir, "Mercurial.ini");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
261 if (f.exists()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
262 return Collections.singletonList(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
263 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
264 f = new File(hgInstallDir, "hgrc.d/");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
265 if (f.canRead() && f.isDirectory()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
266 return listConfigFiles(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
267 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
268 // FIXME query registry, e.g. with
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
269 // Runtime.exec("reg query HKLM\Software\Mercurial")
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
270 //
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
271 f = new File("C:\\Mercurial\\Mercurial.ini");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
272 if (f.exists()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
273 return Collections.singletonList(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
274 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
275 return Collections.emptyList();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
276 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
277
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
278 private static List<File> listConfigFiles(File dir) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
279 assert dir.canRead();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
280 assert dir.isDirectory();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
281 final File[] allFiles = dir.listFiles();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
282 // File is Comparable, lexicographically by default
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
283 Arrays.sort(allFiles);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
284 ArrayList<File> rv = new ArrayList<File>(allFiles.length);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
285 for (File f : allFiles) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
286 if (f.getName().endsWith(".rc")) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
287 rv.add(f);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
288 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
289 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
290 return rv;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
291 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
292
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
293 public static File getInstallationConfigurationFileToWrite(SessionContext ctx) {
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
294 File hgInstallRoot = findHgInstallRoot(ctx); // may be null
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
295 // choice of which hgrc to pick here is according to my own pure discretion
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
296 if (hgInstallRoot != null) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
297 // use this location only if it's writable
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
298 File cfg = new File(hgInstallRoot, runningOnWindows() ? "Mercurial.ini" : "etc/mercurial/hgrc");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
299 if (cfg.canWrite() || cfg.getParentFile().canWrite()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
300 return cfg;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
301 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
302 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
303 // fallback
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
304 if (runningOnWindows()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
305 if (hgInstallRoot == null) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
306 return new File("C:\\Mercurial\\Mercurial.ini");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
307 } else {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
308 // yes, we tried this file already (above) and found it non-writable
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
309 // let caller fail with can't write
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
310 return new File(hgInstallRoot, "Mercurial.ini");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
311 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
312 } else {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
313 return new File("/etc/mercurial/hgrc");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
314 }
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
315 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
316
382
82336b7c54f4 Per-repository UpdateConfigCommand completed. Access to system properties through SessionContext to ease alternation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 379
diff changeset
317 public static File getUserConfigurationFileToWrite(SessionContext ctx) {
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
318 LinkedHashSet<String> locations = new LinkedHashSet<String>();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
319 final boolean runsOnWindows = runningOnWindows();
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
320 if (runsOnWindows) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
321 locations.add(System.getenv("USERPROFILE"));
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
322 }
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
323 locations.add(System.getenv("HOME"));
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
324 locations.remove(null);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
325 for (String loc : locations) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
326 File location = new File(loc);
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
327 File rv = new File(location, ".hgrc");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
328 if (rv.exists() && rv.canWrite()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
329 return rv;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
330 }
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
331 if (runsOnWindows) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
332 rv = new File(location, "Mercurial.ini");
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
333 if (rv.exists() && rv.canWrite()) {
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
334 return rv;
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
335 }
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
336 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
337 }
379
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
338 // fallback to default, let calling code fail with Exception if can't write
fa2be7a05af6 Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
339 return new File(System.getProperty("user.home"), ".hgrc");
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 351
diff changeset
340 }
388
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
341
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
342 public boolean shallCacheRevlogs() {
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
343 return shallCacheRevlogsInRepo;
b015f3918120 Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 382
diff changeset
344 }
407
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
345
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
346 public static <T> CharSequence join(Iterable<T> col, CharSequence separator) {
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
347 if (col == null) {
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
348 return String.valueOf(col);
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
349 }
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
350 Iterator<T> it = col.iterator();
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
351 if (!it.hasNext()) {
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
352 return "[]";
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
353 }
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
354 String v = String.valueOf(it.next());
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
355 StringBuilder sb = new StringBuilder(v);
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
356 while (it.hasNext()) {
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
357 sb.append(separator);
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
358 v = String.valueOf(it.next());
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
359 sb.append(v);
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
360 }
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
361 return sb;
30922c728341 Better multiline log printout; options to tune default log output
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 388
diff changeset
362 }
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
363 }