Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/Internals.java @ 412:63c5a9d7ca3f smartgit3
Follow-up for Issue 29: unify path translation for manifest and dirstate
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 21 Mar 2012 14:54:02 +0100 |
parents | 464b4404e75d |
children | bb278ccf9866 |
comparison
equal
deleted
inserted
replaced
411:464b4404e75d | 412:63c5a9d7ca3f |
---|---|
69 * | 69 * |
70 * <p>E.g. Eclipse defaults to project encoding (Launch config, Common page) when launching an application, | 70 * <p>E.g. Eclipse defaults to project encoding (Launch config, Common page) when launching an application, |
71 * and if your project happen to use anything but filesystem default (say, UTF8 on cp1251 system), | 71 * and if your project happen to use anything but filesystem default (say, UTF8 on cp1251 system), |
72 * native storage paths won't match | 72 * native storage paths won't match |
73 */ | 73 */ |
74 public static final String CFG_PROPERT_FS_FILENAME_ENCODING = "hg.fs.filename.encoding"; | 74 public static final String CFG_PROPERTY_FS_FILENAME_ENCODING = "hg.fs.filename.encoding"; |
75 | 75 |
76 private int requiresFlags = 0; | 76 private int requiresFlags = 0; |
77 private List<Filter.Factory> filterFactories; | 77 private List<Filter.Factory> filterFactories; |
78 private final SessionContext sessionContext; | 78 private final SessionContext sessionContext; |
79 private final boolean isCaseSensitiveFileSystem; | 79 private final boolean isCaseSensitiveFileSystem; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 // XXX perhaps, should keep both fields right here, not in the HgRepository | 110 // XXX perhaps, should keep both fields right here, not in the HgRepository |
111 public PathRewrite buildDataFilesHelper() { | 111 public PathRewrite buildDataFilesHelper() { |
112 Object altEncoding = sessionContext.getProperty(CFG_PROPERT_FS_FILENAME_ENCODING, null); | 112 // Note, tests in TestStorePath depend on the encoding not being cached |
113 Charset cs; | 113 Charset cs = getFileEncoding(); |
114 if (altEncoding == null) { | 114 // StoragePathHelper needs fine-grained control over char encoding, hence doesn't use EncodingHelper |
115 cs = Charset.defaultCharset(); | |
116 } else { | |
117 try { | |
118 cs = Charset.forName(altEncoding.toString()); | |
119 } catch (IllegalArgumentException ex) { | |
120 // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too | |
121 // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it | |
122 sessionContext.getLog().error(getClass(), ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); | |
123 cs = Charset.defaultCharset(); | |
124 } | |
125 } | |
126 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs); | 115 return new StoragePathHelper((requiresFlags & STORE) != 0, (requiresFlags & FNCACHE) != 0, (requiresFlags & DOTENCODE) != 0, cs); |
127 } | 116 } |
128 | 117 |
129 public PathRewrite buildRepositoryFilesHelper() { | 118 public PathRewrite buildRepositoryFilesHelper() { |
130 if ((requiresFlags & STORE) != 0) { | 119 if ((requiresFlags & STORE) != 0) { |
175 new File(hgDir, "store").mkdir(); // with that, hg verify says ok. | 164 new File(hgDir, "store").mkdir(); // with that, hg verify says ok. |
176 } | 165 } |
177 | 166 |
178 public boolean isCaseSensitiveFileSystem() { | 167 public boolean isCaseSensitiveFileSystem() { |
179 return isCaseSensitiveFileSystem; | 168 return isCaseSensitiveFileSystem; |
169 } | |
170 | |
171 public EncodingHelper buildFileNameEncodingHelper() { | |
172 return new EncodingHelper(getFileEncoding()); | |
173 } | |
174 | |
175 private Charset getFileEncoding() { | |
176 Object altEncoding = sessionContext.getProperty(CFG_PROPERTY_FS_FILENAME_ENCODING, null); | |
177 Charset cs; | |
178 if (altEncoding == null) { | |
179 cs = Charset.defaultCharset(); | |
180 } else { | |
181 try { | |
182 cs = Charset.forName(altEncoding.toString()); | |
183 } catch (IllegalArgumentException ex) { | |
184 // both IllegalCharsetNameException and UnsupportedCharsetException are subclasses of IAE, too | |
185 // not severe enough to throw an exception, imo. Just record the fact it's bad ad we ignore it | |
186 sessionContext.getLog().error(Internals.class, ex, String.format("Bad configuration value for filename encoding %s", altEncoding)); | |
187 cs = Charset.defaultCharset(); | |
188 } | |
189 } | |
190 return cs; | |
180 } | 191 } |
181 | 192 |
182 public static boolean runningOnWindows() { | 193 public static boolean runningOnWindows() { |
183 return System.getProperty("os.name").indexOf("Windows") != -1; | 194 return System.getProperty("os.name").indexOf("Windows") != -1; |
184 } | 195 } |