Mercurial > hg4j
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/DirstateReader.java Tue Jan 15 17:07:19 2013 +0100 +++ b/src/org/tmatesoft/hg/internal/DirstateReader.java Tue Jan 15 19:46:19 2013 +0100 @@ -17,14 +17,16 @@ package org.tmatesoft.hg.internal; import static org.tmatesoft.hg.core.Nodeid.NULL; +import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch; import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate; import static org.tmatesoft.hg.util.LogFacility.Severity.Debug; import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.repo.HgDirstate; @@ -158,11 +160,17 @@ * @return branch associated with the working directory */ public static String readBranch(Internals internalRepo) throws HgInvalidControlFileException { - File branchFile = internalRepo.getFileFromRepoDir("branch"); // FIXME constant in the HgRepositoryFiles + File branchFile = internalRepo.getRepositoryFile(Branch); String branch = HgRepository.DEFAULT_BRANCH_NAME; if (branchFile.exists()) { try { - BufferedReader r = new BufferedReader(new FileReader(branchFile)); + // branch file is UTF-8 encoded, see http://mercurial.selenic.com/wiki/EncodingStrategy#UTF-8_strings + // shall not use system-default encoding (FileReader) when reading it! + // Perhaps, shall use EncodingHelper.fromBranch and InputStream instead, for uniformity? + // Since whole file is in UTF8, InputStreamReader is a convenience over InputStream, + // which we use elsewhere (together with EncodingHelper) - other files are usually a mix of binary data + // and encoded text (hence, InputStreamReader with charset is not an option there) + BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(branchFile), EncodingHelper.getUTF8())); String b = r.readLine(); if (b != null) { b = b.trim().intern();