Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/Internals.java @ 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 | fa2be7a05af6 |
children | b015f3918120 |
rev | line source |
---|---|
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
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; |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
24 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
|
25 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
|
26 import java.util.Collections; |
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.LinkedHashSet; |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
28 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
|
29 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
|
30 |
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
|
31 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
|
32 import org.tmatesoft.hg.repo.HgInternals; |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
33 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
|
34 import org.tmatesoft.hg.repo.HgRepository; |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import org.tmatesoft.hg.util.PathRewrite; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 /** |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * Fields/members that shall not be visible |
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 * @author Artem Tikhomirov |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @author TMate Software Ltd. |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 */ |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 public class Internals { |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
45 public static final String CFG_PROPERTY_HG_INSTALL_ROOT = "hg4j.hg.install_root"; |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
46 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 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
|
48 private List<Filter.Factory> filterFactories; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
49 |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
50 |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
51 public Internals() { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
52 } |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
292
diff
changeset
|
53 |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
292
diff
changeset
|
54 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
|
55 try { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
292
diff
changeset
|
56 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
|
57 } catch (IOException ex) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
292
diff
changeset
|
58 // 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
|
59 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
|
60 } |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
292
diff
changeset
|
61 } |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 |
83
a5275143664c
Complete path hash calculation of fncache requirement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
63 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
|
64 requiresFlags = flags; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 } |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 // 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
|
68 public PathRewrite buildDataFilesHelper() { |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0); |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 public PathRewrite buildRepositoryFilesHelper() { |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 if ((requiresFlags & STORE) != 0) { |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 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
|
75 public CharSequence rewrite(CharSequence path) { |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 return "store/" + path; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 }; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } else { |
292
a415fe296a50
Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
80 return new PathRewrite.Empty(); |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
83 |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
84 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
|
85 if (filterFactories == null) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
86 filterFactories = new ArrayList<Filter.Factory>(); |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
87 ExtensionsSection cfg = hgRepo.getConfiguration().getExtensions(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
88 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
|
89 NewlineFilter.Factory ff = new NewlineFilter.Factory(); |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
90 ff.initialize(hgRepo); |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
91 filterFactories.add(ff); |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
92 } |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
93 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
|
94 KeywordFilter.Factory ff = new KeywordFilter.Factory(); |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
95 ff.initialize(hgRepo); |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
96 filterFactories.add(ff); |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
97 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
98 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
99 return filterFactories; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
100 } |
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
|
101 |
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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 } |
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
|
110 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
|
111 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
|
112 } |
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
|
113 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
|
114 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
|
115 } |
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
|
116 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
|
117 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
|
118 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
|
119 } |
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
|
120 |
292
a415fe296a50
Refactor PathRewrite to accept any char sequence, not only string
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
202
diff
changeset
|
121 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
|
122 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
|
123 } |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
124 |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
125 /** |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
126 * 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
|
127 * 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
|
128 * @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
|
129 */ |
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
|
130 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
|
131 // 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
|
132 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
|
133 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
|
134 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
|
135 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 // 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
|
144 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
|
145 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
146 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
147 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
|
148 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
149 |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
150 /** |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
151 * @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
|
152 */ |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
153 public ConfigFile readConfiguration(HgRepository hgRepo, File repoRoot) throws IOException { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
154 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
|
155 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
|
156 // |
351
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 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
|
161 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
162 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 } |
351
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
172 } 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 configFile.addLocation(f); |
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
178 } |
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
179 } |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
180 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
|
181 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
182 // 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 } |
351
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
188 } |
5abba41751e6
Read extra predefined locations with mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
189 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
|
190 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
|
191 } |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
192 // last one, overrides anything else |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
193 // <repo>/.hg/hgrc |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
194 configFile.addLocation(new File(repoRoot, "hgrc")); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
195 return configFile; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
196 } |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
197 |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 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
|
202 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
203 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
|
204 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
|
205 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
|
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 // 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
|
208 // 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
|
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 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
|
211 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
|
212 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
|
213 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
214 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
|
215 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
216 |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 // 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
228 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
229 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
|
230 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
231 |
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
|
232 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
|
233 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
|
234 // 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
|
235 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
|
236 // 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
|
237 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
|
238 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
|
239 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
|
240 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
241 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
242 // fallback |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 } else { |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
247 // 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
|
248 // 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
|
249 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
|
250 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
251 } else { |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
252 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
|
253 } |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
351
diff
changeset
|
254 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
351
diff
changeset
|
255 |
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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 locations.add(System.getenv("USERPROFILE")); |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
351
diff
changeset
|
261 } |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 } |
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 } |
378
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
351
diff
changeset
|
275 } |
9fb990c8a724
Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
351
diff
changeset
|
276 } |
379
fa2be7a05af6
Implement discovery of mercurial installation, use it to read/write configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
378
diff
changeset
|
277 // 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
|
278 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
|
279 } |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
280 } |