Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/DirstateReader.java @ 527:47b7bedf0569
Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 15 Jan 2013 19:46:19 +0100 |
parents | 2f9ed6bcefa2 |
children | 243202f1bda5 |
comparison
equal
deleted
inserted
replaced
526:2f9ed6bcefa2 | 527:47b7bedf0569 |
---|---|
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import static org.tmatesoft.hg.core.Nodeid.NULL; | 19 import static org.tmatesoft.hg.core.Nodeid.NULL; |
20 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch; | |
20 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate; | 21 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate; |
21 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; | 22 import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; |
22 | 23 |
23 import java.io.BufferedReader; | 24 import java.io.BufferedReader; |
24 import java.io.File; | 25 import java.io.File; |
26 import java.io.FileInputStream; | |
25 import java.io.FileNotFoundException; | 27 import java.io.FileNotFoundException; |
26 import java.io.FileReader; | |
27 import java.io.IOException; | 28 import java.io.IOException; |
29 import java.io.InputStreamReader; | |
28 | 30 |
29 import org.tmatesoft.hg.core.Nodeid; | 31 import org.tmatesoft.hg.core.Nodeid; |
30 import org.tmatesoft.hg.repo.HgDirstate; | 32 import org.tmatesoft.hg.repo.HgDirstate; |
31 import org.tmatesoft.hg.repo.HgDirstate.EntryKind; | 33 import org.tmatesoft.hg.repo.HgDirstate.EntryKind; |
32 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 34 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
156 /** | 158 /** |
157 * TODO [post-1.0] it's really not a proper place for the method, need WorkingCopyContainer or similar | 159 * TODO [post-1.0] it's really not a proper place for the method, need WorkingCopyContainer or similar |
158 * @return branch associated with the working directory | 160 * @return branch associated with the working directory |
159 */ | 161 */ |
160 public static String readBranch(Internals internalRepo) throws HgInvalidControlFileException { | 162 public static String readBranch(Internals internalRepo) throws HgInvalidControlFileException { |
161 File branchFile = internalRepo.getFileFromRepoDir("branch"); // FIXME constant in the HgRepositoryFiles | 163 File branchFile = internalRepo.getRepositoryFile(Branch); |
162 String branch = HgRepository.DEFAULT_BRANCH_NAME; | 164 String branch = HgRepository.DEFAULT_BRANCH_NAME; |
163 if (branchFile.exists()) { | 165 if (branchFile.exists()) { |
164 try { | 166 try { |
165 BufferedReader r = new BufferedReader(new FileReader(branchFile)); | 167 // branch file is UTF-8 encoded, see http://mercurial.selenic.com/wiki/EncodingStrategy#UTF-8_strings |
168 // shall not use system-default encoding (FileReader) when reading it! | |
169 // Perhaps, shall use EncodingHelper.fromBranch and InputStream instead, for uniformity? | |
170 // Since whole file is in UTF8, InputStreamReader is a convenience over InputStream, | |
171 // which we use elsewhere (together with EncodingHelper) - other files are usually a mix of binary data | |
172 // and encoded text (hence, InputStreamReader with charset is not an option there) | |
173 BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(branchFile), EncodingHelper.getUTF8())); | |
166 String b = r.readLine(); | 174 String b = r.readLine(); |
167 if (b != null) { | 175 if (b != null) { |
168 b = b.trim().intern(); | 176 b = b.trim().intern(); |
169 } | 177 } |
170 branch = b == null || b.length() == 0 ? HgRepository.DEFAULT_BRANCH_NAME : b; | 178 branch = b == null || b.length() == 0 ? HgRepository.DEFAULT_BRANCH_NAME : b; |