# HG changeset patch # User Artem Tikhomirov # Date 1333039703 -7200 # Node ID d280759c2a3f10b6bc8bc1ce1265781f7841080f # Parent cd658b24a62000c790386fa241f2bec282e1e71a branch information is not directly related to dirstate, clean API from this dependency diff -r cd658b24a620 -r d280759c2a3f src/org/tmatesoft/hg/repo/HgDirstate.java --- a/src/org/tmatesoft/hg/repo/HgDirstate.java Thu Mar 29 18:29:03 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgDirstate.java Thu Mar 29 18:48:23 2012 +0200 @@ -64,7 +64,6 @@ */ private Map canonical2dirstateName; private Pair parents; - private String currentBranch; // canonicalPath may be null if we don't need to check for names other than in dirstate /*package-local*/ HgDirstate(HgRepository hgRepo, File dirstate, PathPool pathPool, PathRewrite canonicalPath) { @@ -192,24 +191,11 @@ } /** - * FIXME move to a better place, e.g. WorkingCopy container that tracks both dirstate and branches (and, perhaps, undo, lastcommit and other similar information) + * TODO [post-1.0] it's really not a proper place for the method, need WorkingCopyContainer or similar * @return branch associated with the working directory */ - public String branch() throws HgInvalidControlFileException { - // XXX is it really proper place for the method? - if (currentBranch == null) { - currentBranch = readBranch(repo); - } - return currentBranch; - } - - /** - * XXX is it really proper place for the method? - * @return branch associated with the working directory - */ - /*package-local*/ static String readBranch(HgRepository repo) throws HgInvalidControlFileException { + /*package-local*/ static String readBranch(HgRepository repo, File branchFile) throws HgInvalidControlFileException { String branch = HgRepository.DEFAULT_BRANCH_NAME; - File branchFile = new File(repo.getRepositoryRoot(), "branch"); if (branchFile.exists()) { try { BufferedReader r = new BufferedReader(new FileReader(branchFile)); diff -r cd658b24a620 -r d280759c2a3f src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Thu Mar 29 18:29:03 2012 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Thu Mar 29 18:48:23 2012 +0200 @@ -116,6 +116,14 @@ private HgIgnore ignore; private HgRepoConfig repoConfig; + /* + * TODO [post-1.0] move to a better place, e.g. WorkingCopy container that tracks both dirstate and branches + * (and, perhaps, undo, lastcommit and other similar information), and is change listener so that we don't need to + * worry about this cached value become stale + */ + private String wcBranch; + + HgRepository(String repositoryPath) { repoDir = null; workingDir = null; @@ -273,7 +281,10 @@ * @throws HgInvalidControlFileException if attempt to read branch name failed. */ public String getWorkingCopyBranchName() throws HgInvalidControlFileException { - return HgDirstate.readBranch(this); + if (wcBranch == null) { + wcBranch = HgDirstate.readBranch(this, new File(repoDir, "branch")); + } + return wcBranch; } /**