annotate src/org/tmatesoft/hg/internal/ConfigFile.java @ 485:cdd53e5884ae

Do not add anything to exception message in case no details are known
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 09 Aug 2012 15:45:18 +0200
parents e31e85cf4d4c
children db48a77ec8ff
rev   line source
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
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: 73
diff changeset
15 * contact TMate Software at support@hg4j.com
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.internal;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
19 import java.io.ByteArrayOutputStream;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.File;
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
21 import java.io.FileOutputStream;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.io.IOException;
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
23 import java.io.PrintStream;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
24 import java.nio.ByteBuffer;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
25 import java.nio.channels.FileChannel;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
26 import java.nio.channels.FileLock;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.ArrayList;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.Collections;
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
29 import java.util.Iterator;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.LinkedHashMap;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.List;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import java.util.Map;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
34 import org.tmatesoft.hg.core.SessionContext;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
35 import org.tmatesoft.hg.repo.HgInvalidFileException;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
36 import org.tmatesoft.hg.util.LogFacility;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
37
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 /**
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
39 * .ini / .rc file reader
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 * @author Artem Tikhomirov
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 * @author TMate Software Ltd.
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 */
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 public class ConfigFile {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
45 private final SessionContext sessionContext;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 private List<String> sections;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 private List<Map<String,String>> content;
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
49 public ConfigFile(SessionContext ctx) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
50 sessionContext = ctx;
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
53 public void addLocation(File path) throws HgInvalidFileException {
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 read(path);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
57 public boolean hasSection(String sectionName) {
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
58 return sections == null ? false : sections.indexOf(sectionName) != -1;
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
59 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
60
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 public List<String> getSectionNames() {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
62 return sections == null ? Collections.<String>emptyList() : Collections.unmodifiableList(sections);
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public Map<String,String> getSection(String sectionName) {
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
66 if (sections == null) {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
67 return Collections.emptyMap();
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
68 }
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 int x = sections.indexOf(sectionName);
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 if (x == -1) {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 return Collections.emptyMap();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 return Collections.unmodifiableMap(content.get(x));
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
76 public boolean getBoolean(String sectionName, String key, boolean defaultValue) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
77 String value = getSection(sectionName).get(key);
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
78 if (value == null) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
79 return defaultValue;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
80 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
81 for (String s : new String[] { "true", "yes", "on", "1" }) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
82 if (s.equalsIgnoreCase(value)) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
83 return true;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
84 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
85 }
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
86 return false;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
87 }
128
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
88
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
89 public String getString(String sectionName, String key, String defaultValue) {
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
90 String value = getSection(sectionName).get(key);
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
91 return value == null ? defaultValue : value;
44b97930570c Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 114
diff changeset
92 }
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
93
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
94 public void putString(String sectionName, String key, String newValue) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
95 Map<String, String> section = null;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
96 if (sections == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
97 // init, in case we didn't read any file with prev config
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
98 sections = new ArrayList<String>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
99 content = new ArrayList<Map<String,String>>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
100 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
101 int x = sections.indexOf(sectionName);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
102 if (x == -1) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
103 if (newValue == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
104 return;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
105 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
106 sections.add(sectionName);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
107 content.add(section = new LinkedHashMap<String, String>());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
108 } else {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
109 section = content.get(x);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
110 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
111 if (newValue == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
112 section.remove(key);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
113 } else {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
114 section.put(key, newValue);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
115 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
116 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
117
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
118 private void read(File f) throws HgInvalidFileException {
114
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
119 if (f == null || !f.canRead()) {
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
120 return;
46291ec605a0 Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
121 }
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 if (sections == null) {
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 sections = new ArrayList<String>();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 content = new ArrayList<Map<String,String>>();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
126 new Parser().go(f, this);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
127 ((ArrayList<?>) sections).trimToSize();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
128 ((ArrayList<?>) content).trimToSize();
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 assert sections.size() == content.size();
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
131
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
132 public void writeTo(File f) throws IOException {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
133 byte[] data = compose();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
134 if (!f.exists()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
135 f.createNewFile();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
136 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
137 FileChannel fc = new FileOutputStream(f).getChannel();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
138 FileLock fl = fc.lock();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
139 try {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
140 fc.write(ByteBuffer.wrap(data));
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
141 } finally {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
142 fl.release();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
143 fc.close();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
144 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
145 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
146
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
147 private byte[] compose() {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
148 ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
149 PrintStream ps = new PrintStream(bos);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
150 Iterator<String> sectionNames = sections.iterator();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
151 for (Map<String,String> s : content) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
152 final String name = sectionNames.next(); // iterate through names despite section may be empty
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
153 if (s.isEmpty()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
154 continue; // do not write an empty section
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
155 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
156 ps.print('[');
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
157 ps.print(name);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
158 ps.println(']');
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
159 for (Map.Entry<String, String> e : s.entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
160 ps.print(e.getKey());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
161 ps.print('=');
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
162 ps.println(e.getValue());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
163 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
164 ps.println();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
165 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
166 ps.flush();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
167 return bos.toByteArray();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
168 }
483
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
169
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
170 private static class Parser implements LineReader.LineConsumer<ConfigFile> {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
171
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
172 private String sectionName = "";
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
173 private Map<String,String> section = new LinkedHashMap<String, String>();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
174 private File contextFile;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
175
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
176 // TODO "" and lists
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
177 // XXX perhaps, single string to keep whole section with substrings for keys/values to minimize number of arrays (String.value)
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
178 public boolean consume(String line, ConfigFile cfg) throws IOException {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
179 int x;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
180 if ((x = line.indexOf('#')) != -1) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
181 // do not keep comments in memory, get new, shorter string
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
182 line = new String(line.substring(0, x).trim());
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
183 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
184 if (line.length() <= 2) { // a=b or [a] are at least of length 3
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
185 return true;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
186 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
187 if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
188 sectionName = line.substring(1, line.length() - 1);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
189 if (cfg.sections.indexOf(sectionName) == -1) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
190 cfg.sections.add(sectionName);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
191 cfg.content.add(section = new LinkedHashMap<String, String>());
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
192 } else {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
193 section = null; // drop cached value
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
194 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
195 } else if (line.startsWith("%unset")) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
196 if (section != null) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
197 section.remove(line.substring(7).trim());
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
198 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
199 } else if (line.startsWith("%include")) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
200 processInclude(line.substring(9).trim(), cfg);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
201 } else if ((x = line.indexOf('=')) != -1) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
202 // share char[] of the original string
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
203 String key = line.substring(0, x).trim();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
204 String value = line.substring(x+1).trim();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
205 if (section == null) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
206 int i = cfg.sections.indexOf(sectionName);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
207 assert i >= 0;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
208 section = cfg.content.get(i);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
209 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
210 if (sectionName.length() == 0) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
211 // add fake section only if there are any values
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
212 cfg.sections.add(sectionName);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
213 cfg.content.add(section);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
214 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
215 section.put(key, value);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
216 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
217 return true;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
218 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
219
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
220 public void go(File f, ConfigFile cfg) throws HgInvalidFileException {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
221 contextFile = f;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
222 LineReader lr = new LineReader(f, cfg.sessionContext.getLog());
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
223 lr.ignoreLineComments("#");
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
224 lr.read(this, cfg);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
225 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
226
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
227 // include failure doesn't propagate
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
228 private void processInclude(String includeValue, ConfigFile cfg) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
229 File f;
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
230 // TODO handle environment variable expansion
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
231 if (includeValue.startsWith("~/")) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
232 f = new File(System.getProperty("user.home"), includeValue.substring(2));
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
233 } else {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
234 f = new File(contextFile.getParentFile(), includeValue);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
235 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
236 try {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
237 if (f.canRead()) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
238 new Parser().go(f, cfg);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
239 } else {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
240 LogFacility lf = cfg.sessionContext.getLog();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
241 lf.dump(ConfigFile.class, LogFacility.Severity.Debug, "Can't read file to include: %s", f);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
242 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
243 } catch (HgInvalidFileException ex) {
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
244 LogFacility lf = cfg.sessionContext.getLog();
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
245 lf.dump(ConfigFile.class, LogFacility.Severity.Warn, "Can't include %s (%s)", f, includeValue);
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
246 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
247 }
e31e85cf4d4c Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 378
diff changeset
248 }
69
5a69397f0f99 Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 }