changeset 430:d280759c2a3f

branch information is not directly related to dirstate, clean API from this dependency
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 29 Mar 2012 18:48:23 +0200
parents cd658b24a620
children 12f668401613
files src/org/tmatesoft/hg/repo/HgDirstate.java src/org/tmatesoft/hg/repo/HgRepository.java
diffstat 2 files changed, 14 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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<Path, Path> canonical2dirstateName; 
 	private Pair<Nodeid, Nodeid> 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));
--- 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;
 	}
 
 	/**