Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgRepoConfig.java @ 709:497e697636fc
Report merged lines as changed block if possible, not as a sequence of added/deleted blocks. To facilitate access to merge parent lines AddBlock got mergeLineAt() method that reports index of the line in the second parent (if any), while insertedAt() has been changed to report index in the first parent always
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 21 Aug 2013 16:23:27 +0200 |
parents | 36e36b926747 |
children |
rev | line source |
---|---|
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
579
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
2 * Copyright (c) 2011-2013 TMate Software Ltd |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.util.ArrayList; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.Collections; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.util.Iterator; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.List; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.Map; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import org.tmatesoft.hg.internal.ConfigFile; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import org.tmatesoft.hg.util.Pair; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 /** |
579
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
29 * Repository configuration. |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * |
579
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
31 * @see http://www.selenic.com/mercurial/hgrc.5.html |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * @author Artem Tikhomirov |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * @author TMate Software Ltd. |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 public final class HgRepoConfig /*implements RepoChangeListener, perhaps, also RepoChangeNotifier? */{ |
579
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
36 // TODO [1.2+] The name HgRepoConfig is unfortunate, we could've used this class not only for |
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
37 // repository configuration but system-wide/global configuration, or user configuration (without repo), too. |
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
38 // Perhaps, rename and deprecate? |
36e36b926747
Provide means to read user-specific configuration, with no specific repository selected
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
487
diff
changeset
|
39 |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 /*ease access for inner classes*/ final ConfigFile config; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 /*package-local*/HgRepoConfig(ConfigFile configFile) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 config = configFile; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 public Section getSection(String name) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 if (name == null) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 throw new IllegalArgumentException(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 if ("paths".equals(name)) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 return new PathsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 if ("extensions".equals(name)) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 return new ExtensionsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 return new Section(name); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 public boolean hasSection(String name) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 return config.hasSection(name); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 public boolean getBooleanValue(String section, String key, boolean defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 return config.getBoolean(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 public String getStringValue(String section, String key, String defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 return config.getString(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 } |
487
db48a77ec8ff
Access to reposiotry lock mechanism via HgRepositoryLock
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
70 |
db48a77ec8ff
Access to reposiotry lock mechanism via HgRepositoryLock
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
71 public int getIntegerValue(String section, String key, int defaultValue) { |
db48a77ec8ff
Access to reposiotry lock mechanism via HgRepositoryLock
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
72 return config.getInteger(section, key, defaultValue); |
db48a77ec8ff
Access to reposiotry lock mechanism via HgRepositoryLock
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
467
diff
changeset
|
73 } |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 // |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 // |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 public PathsSection getPaths() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 Section s = getSection("paths"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 if (s.exists()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 return (PathsSection) s; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 return new PathsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 public ExtensionsSection getExtensions() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 Section s = getSection("extensions"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 if (s.exists()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 return (ExtensionsSection) s; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 return new ExtensionsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 /* |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 * IMPLEMENTATION NOTE: Section is merely a view to configuration file, without any state. |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 * In case I need to sync access to config (i.e. write) or refresh it later - can be easily done |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 public class Section implements Iterable<Pair<String,String>> { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 protected final String section; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 /*package-local*/Section(String sectionName) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 section = sectionName; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 public String getName() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 return section; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 * Whether this is real section or a bare non-null instance |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 public boolean exists() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 return hasSection(section); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 * @return defined keys, in the order they appear in the section |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 public List<String> getKeys() { |
333
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
122 // PathsSection depends on return value being modifiable |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 return new ArrayList<String>(config.getSection(section).keySet()); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 * Find out whether key is present and got any value |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 * @param key identifies an entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 * @return true if key is present in the section and has non-empty value |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 public boolean isKeySet(String key) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 String value = getStringValue(section, key, null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 return value != null && value.length() > 0; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 * Value of a key as boolean |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 * @param key identifies an entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 * @param defaultValue optional value to return if no entry for the key found in this section |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 * @return value corresponding to the key, or defaultValue if key not found |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 public boolean getBoolean(String key, boolean defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 return getBooleanValue(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 * Value of a key as regular string |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 * @param key identifies entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 * @param defaultValue optional value to return if no entry for the key found in this section |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 * @return value corresponding to the key, or defaultValue if key not found |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 public String getString(String key, String defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 return getStringValue(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 public Iterator<Pair<String, String>> iterator() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 final Map<String, String> m = config.getSection(section); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 if (m.isEmpty()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 return Collections.<Pair<String,String>>emptyList().iterator(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 ArrayList<Pair<String, String>> rv = new ArrayList<Pair<String,String>>(m.size()); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 for (Map.Entry<String, String> e : m.entrySet()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 rv.add(new Pair<String,String>(e.getKey(), e.getValue())); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 return rv.iterator(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
167 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 /* |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 * Few well-known sections may get their specific subclasses |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 * Section [paths] |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 public class PathsSection extends Section { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 PathsSection() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 super("paths"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 } |
333
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
180 |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
181 /** |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
182 * Similar to {@link #getKeys()}, but without entries for <b>default</b> and <b>default-push</b> paths |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
183 * @return list of path symbolic names |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
184 */ |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
185 public List<String> getPathSymbolicNames() { |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
186 final List<String> rv = getKeys(); |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
187 rv.remove("default"); |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
188 rv.remove("default-push"); |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
189 return rv; |
467fd379b653
Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
331
diff
changeset
|
190 } |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 public boolean hasDefault() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 return isKeySet("default"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 public String getDefault() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 return super.getString("default", null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 public boolean hasDefaultPush() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 return isKeySet("default-push"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 public String getDefaultPush() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 return super.getString("default-push", null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
206 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
207 * Section [extensions] |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
208 * |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
209 * @author Artem Tikhomirov |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
210 * @author TMate Software Ltd. |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
211 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
212 public class ExtensionsSection extends Section { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
213 ExtensionsSection() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
214 super("extensions"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
215 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
216 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
217 public boolean isEnabled(String extensionName) { |
369
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
218 final Map<String, String> sect = config.getSection(section); |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
219 String value = sect.get(extensionName); |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
220 if (value == null) { |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
221 value = sect.get("hgext." + extensionName); |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
222 } |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
223 if (value == null) { |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
224 value = sect.get("hgext/" + extensionName); |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
225 } |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
226 if (value != null) { |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
227 // empty line, just "extension =" is valid way to enable it |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
228 return value.length() == 0 || '!' != value.charAt(0); |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
229 } |
091666b87f62
Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
349
diff
changeset
|
230 return false; |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
231 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
232 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
233 } |