Mercurial > jhg
comparison src/org/tmatesoft/hg/core/HgUpdateConfigCommand.java @ 483:e31e85cf4d4c
Handle include and unset directives in config files
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Tue, 07 Aug 2012 19:14:53 +0200 |
| parents | 31a89587eb04 |
| children | b3c16d1aede0 |
comparison
equal
deleted
inserted
replaced
| 482:6c67debed07e | 483:e31e85cf4d4c |
|---|---|
| 41 private final File configFile; | 41 private final File configFile; |
| 42 | 42 |
| 43 private Map<String,List<String>> toRemove; | 43 private Map<String,List<String>> toRemove; |
| 44 private Map<String,Map<String,String>> toSet; | 44 private Map<String,Map<String,String>> toSet; |
| 45 | 45 |
| 46 private HgUpdateConfigCommand(File configurationFile) { | 46 private final SessionContext sessionCtx; |
| 47 | |
| 48 private HgUpdateConfigCommand(SessionContext sessionContext, File configurationFile) { | |
| 49 sessionCtx = sessionContext; | |
| 47 configFile = configurationFile; | 50 configFile = configurationFile; |
| 48 } | 51 } |
| 49 | 52 |
| 50 public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) { | 53 public static HgUpdateConfigCommand forRepository(HgRepository hgRepo) { |
| 51 // XXX HgRepository to implement SessionContextProvider (with getContext())? | 54 // XXX HgRepository to implement SessionContextProvider (with getContext())? |
| 52 return new HgUpdateConfigCommand(new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); | 55 return new HgUpdateConfigCommand(HgInternals.getContext(hgRepo), new File(HgInternals.getRepositoryDir(hgRepo), "hgrc")); |
| 53 } | 56 } |
| 54 | 57 |
| 55 public static HgUpdateConfigCommand forUser(SessionContext ctx) { | 58 public static HgUpdateConfigCommand forUser(SessionContext ctx) { |
| 56 return new HgUpdateConfigCommand(Internals.getUserConfigurationFileToWrite(ctx)); | 59 return new HgUpdateConfigCommand(ctx, Internals.getUserConfigurationFileToWrite(ctx)); |
| 57 } | 60 } |
| 58 | 61 |
| 59 public static HgUpdateConfigCommand forInstallation(SessionContext ctx) { | 62 public static HgUpdateConfigCommand forInstallation(SessionContext ctx) { |
| 60 return new HgUpdateConfigCommand(Internals.getInstallationConfigurationFileToWrite(ctx)); | 63 return new HgUpdateConfigCommand(ctx, Internals.getInstallationConfigurationFileToWrite(ctx)); |
| 61 } | 64 } |
| 62 | 65 |
| 63 /** | 66 /** |
| 64 * Remove a property altogether | 67 * Remove a property altogether |
| 65 * @return <code>this</code> for convenience | 68 * @return <code>this</code> for convenience |
| 116 * | 119 * |
| 117 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state | 120 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state |
| 118 */ | 121 */ |
| 119 public void execute() throws HgException { | 122 public void execute() throws HgException { |
| 120 try { | 123 try { |
| 121 ConfigFile cfg = new ConfigFile(); | 124 ConfigFile cfg = new ConfigFile(sessionCtx); |
| 122 cfg.addLocation(configFile); | 125 cfg.addLocation(configFile); |
| 123 if (toRemove != null) { | 126 if (toRemove != null) { |
| 124 for (Map.Entry<String,List<String>> s : toRemove.entrySet()) { | 127 for (Map.Entry<String,List<String>> s : toRemove.entrySet()) { |
| 125 for (String e : s.getValue()) { | 128 for (String e : s.getValue()) { |
| 126 cfg.putString(s.getKey(), e, null); | 129 cfg.putString(s.getKey(), e, null); |
