annotate src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java @ 378:9fb990c8a724

Investigate approaches to alter Mercurial configuration files
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 09 Feb 2012 04:15:17 +0100
parents
children 82336b7c54f4
rev   line source
378
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012 TMate Software Ltd
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.File;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.IOException;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.ArrayList;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.LinkedHashMap;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.List;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.Map;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.ConfigFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.Experimental;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.internal.Internals;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgRepository;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * WORK IN PROGRESS, DO NOT USE
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 *
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * @author Artem Tikhomirov
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 * @author TMate Software Ltd.
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 @Experimental(reason="Investigating approaches to alter Hg configuration files")
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 public final class HgUpdateConfigCommand extends HgAbstractCommand<HgUpdateConfigCommand> {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private final HgRepository repo;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 private final File configFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private Map<String,List<String>> toRemove;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 private Map<String,Map<String,String>> toSet;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 private HgUpdateConfigCommand(HgRepository hgRepo, File configurationFile) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 repo = hgRepo;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 configFile = configurationFile;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 return new HgUpdateConfigCommand(hgRepo, new File(".hg/hgrc"));
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 public static HgUpdateConfigCommand forUser(HgRepository hgRepo) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 return new HgUpdateConfigCommand(null, Internals.getUserConfigurationFileToWrite());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 public static HgUpdateConfigCommand forInstallation() {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 return new HgUpdateConfigCommand(null, Internals.getInstallationConfigurationFileToWrite());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 * Remove a property altogether
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 public HgUpdateConfigCommand remove(String section, String key) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 if (toRemove == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 toRemove = new LinkedHashMap<String, List<String>>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 List<String> s = toRemove.get(section);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 if (s == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 toRemove.put(section, s = new ArrayList<String>(5));
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 s.add(key);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 if (toSet != null && toSet.containsKey(section)) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 toSet.get(section).remove(key);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 return this;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 * Delete single attribute in a multi-valued property
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 public HgUpdateConfigCommand remove(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 throw new UnsupportedOperationException();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 * Set single-valued properties or update multi-valued with a single value
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 public HgUpdateConfigCommand put(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 if (toSet == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 toSet = new LinkedHashMap<String, Map<String,String>>();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 Map<String,String> s = toSet.get(section);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 if (s == null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 toSet.put(section, s = new LinkedHashMap<String, String>());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 s.put(key, value);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 return this;
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 /**
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 * Multi-valued properties
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 * @return <code>this</code> for convenience
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 */
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 public HgUpdateConfigCommand add(String section, String key, String value) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 throw new UnsupportedOperationException();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 public void execute() throws HgException {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 try {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 ConfigFile cfg = new ConfigFile();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 cfg.addLocation(configFile);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 if (toRemove != null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 for (Map.Entry<String,List<String>> s : toRemove.entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 for (String e : s.getValue()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 cfg.putString(s.getKey(), e, null);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 if (toSet != null) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 for (Map.Entry<String,Map<String,String>> s : toSet.entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 for (Map.Entry<String, String> e : s.getValue().entrySet()) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 cfg.putString(s.getKey(), e.getKey(), e.getValue());
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 cfg.writeTo(configFile);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 } catch (IOException ex) {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 throw new HgInvalidFileException("Failed to update configuration file", ex, configFile);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 public static void main(String[] args) throws Exception {
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 HgUpdateConfigCommand cmd = HgUpdateConfigCommand.forUser(null);
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 cmd.remove("test1", "sample1");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 cmd.put("test2", "sample2", "value2");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 cmd.put("ui", "user-name", "Another User <email@domain.com>");
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 cmd.execute();
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 }
9fb990c8a724 Investigate approaches to alter Mercurial configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 }