comparison src/org/tmatesoft/hg/internal/Internals.java @ 388:b015f3918120

Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 15 Feb 2012 22:57:56 +0100
parents 82336b7c54f4
children 30922c728341 7f27122011c3
comparison
equal deleted inserted replaced
387:cdea37239b01 388:b015f3918120
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
38 * Fields/members that shall not be visible 38 * Fields/members that shall not be visible
39 * 39 *
40 * @author Artem Tikhomirov 40 * @author Artem Tikhomirov
41 * @author TMate Software Ltd. 41 * @author TMate Software Ltd.
42 */ 42 */
43 public class Internals { 43 public final class Internals {
44 44
45 /**
46 * Allows to specify Mercurial installation directory to detect installation-wide configurations.
47 * Without this property set, hg4j would attempt to deduce this value locating hg executable.
48 */
45 public static final String CFG_PROPERTY_HG_INSTALL_ROOT = "hg4j.hg.install_root"; 49 public static final String CFG_PROPERTY_HG_INSTALL_ROOT = "hg4j.hg.install_root";
50
51 /**
52 * Tells repository not to cache files/revlogs
53 * XXX perhaps, need to respect this property not only for data files, but for manifest and changelog as well?
54 * (@see HgRepository#getChangelog and #getManifest())
55 */
56 public static final String CFG_PROPERTY_REVLOG_STREAM_CACHE = "hg4j.repo.disable_revlog_cache";
46 57
47 private int requiresFlags = 0; 58 private int requiresFlags = 0;
48 private List<Filter.Factory> filterFactories; 59 private List<Filter.Factory> filterFactories;
49 60 private final boolean isCaseSensitiveFileSystem;
50 61 private final boolean shallCacheRevlogsInRepo;
51 public Internals() { 62
63
64 public Internals(SessionContext ctx) {
65 isCaseSensitiveFileSystem = !runningOnWindows();
66 Object p = ctx.getProperty(CFG_PROPERTY_REVLOG_STREAM_CACHE, true);
67 shallCacheRevlogsInRepo = p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p));
52 } 68 }
53 69
54 public void parseRequires(HgRepository hgRepo, File requiresFile) { 70 public void parseRequires(HgRepository hgRepo, File requiresFile) {
55 try { 71 try {
56 new RequiresFile().parse(this, requiresFile); 72 new RequiresFile().parse(this, requiresFile);
60 } 76 }
61 } 77 }
62 78
63 public/*for tests, otherwise pkg*/ void setStorageConfig(int version, int flags) { 79 public/*for tests, otherwise pkg*/ void setStorageConfig(int version, int flags) {
64 requiresFlags = flags; 80 requiresFlags = flags;
81 }
82
83 public PathRewrite buildNormalizePathRewrite() {
84 if (runningOnWindows()) {
85 return new PathRewrite() {
86
87 public CharSequence rewrite(CharSequence p) {
88 // TODO handle . and .. (although unlikely to face them from GUI client)
89 String path = p.toString();
90 path = path.replace('\\', '/').replace("//", "/");
91 if (path.startsWith("/")) {
92 path = path.substring(1);
93 }
94 return path;
95 }
96 };
97 } else {
98 return new PathRewrite.Empty(); // or strip leading slash, perhaps?
99 }
65 } 100 }
66 101
67 // XXX perhaps, should keep both fields right here, not in the HgRepository 102 // XXX perhaps, should keep both fields right here, not in the HgRepository
68 public PathRewrite buildDataFilesHelper() { 103 public PathRewrite buildDataFilesHelper() {
69 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0); 104 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0);
114 sb.append("dotencode\n"); 149 sb.append("dotencode\n");
115 } 150 }
116 requiresFile.write(sb.toString().getBytes()); 151 requiresFile.write(sb.toString().getBytes());
117 requiresFile.close(); 152 requiresFile.close();
118 new File(hgDir, "store").mkdir(); // with that, hg verify says ok. 153 new File(hgDir, "store").mkdir(); // with that, hg verify says ok.
154 }
155
156 public boolean isCaseSensitiveFileSystem() {
157 return isCaseSensitiveFileSystem;
119 } 158 }
120 159
121 public static boolean runningOnWindows() { 160 public static boolean runningOnWindows() {
122 return System.getProperty("os.name").indexOf("Windows") != -1; 161 return System.getProperty("os.name").indexOf("Windows") != -1;
123 } 162 }
275 } 314 }
276 } 315 }
277 // fallback to default, let calling code fail with Exception if can't write 316 // fallback to default, let calling code fail with Exception if can't write
278 return new File(System.getProperty("user.home"), ".hgrc"); 317 return new File(System.getProperty("user.home"), ".hgrc");
279 } 318 }
319
320 public boolean shallCacheRevlogs() {
321 return shallCacheRevlogsInRepo;
322 }
280 } 323 }