diff options
author | Tor Norbye <tnorbye@google.com> | 2014-07-16 18:07:37 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2014-07-16 18:09:03 -0700 |
commit | 65f60eb9011bb2c549a6d83ae31257480368ddc5 (patch) | |
tree | de0dca03bec460e8797332e5f460400f5cf6485f /plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java | |
parent | 9ea67227e8fdcf8ed37e65bb96e32767291d0f4f (diff) | |
download | idea-65f60eb9011bb2c549a6d83ae31257480368ddc5.tar.gz |
Snapshot idea/138.1029 from git://git.jetbrains.org/idea/community.git
Update from idea/138.538 to idea/138.1029
Change-Id: I828f829a968439a99ec67640990c18ff7c9b58ce
Diffstat (limited to 'plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java')
-rw-r--r-- | plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index 7c0c37a84c8a..923087d0b3b2 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -19,8 +19,10 @@ import com.intellij.dvcs.repo.RepoStateException; import com.intellij.dvcs.repo.Repository; import com.intellij.dvcs.repo.RepositoryUtil; import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.vcs.log.Hash; import com.intellij.vcs.log.VcsLogObjectsFactory; +import org.apache.commons.codec.binary.Hex; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.zmlx.hg4idea.HgNameWithHashInfo; @@ -28,6 +30,9 @@ import org.zmlx.hg4idea.HgVcs; import org.zmlx.hg4idea.util.HgVersion; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -53,6 +58,7 @@ public class HgRepositoryReader { @NotNull private final File myCurrentBookmark; //.hg/bookmarks.current @NotNull private final File myTagsFile; //.hgtags - not in .hg directory!!! @NotNull private final File myLocalTagsFile; // .hg/localtags + @NotNull private final File myDirStateFile; // .hg/dirstate @NotNull private final VcsLogObjectsFactory myVcsObjectsFactory; private final boolean myStatusInBranchFile; @NotNull final HgVcs myVcs; @@ -70,6 +76,7 @@ public class HgRepositoryReader { myCurrentBookmark = new File(myHgDir, "bookmarks.current"); myLocalTagsFile = new File(myHgDir, "localtags"); myTagsFile = new File(myHgDir.getParentFile(), ".hgtags"); + myDirStateFile = new File(myHgDir, "dirstate"); myVcsObjectsFactory = ServiceManager.getService(vcs.getProject(), VcsLogObjectsFactory.class); } @@ -98,6 +105,36 @@ public class HgRepositoryReader { */ @Nullable public String readCurrentRevision() { + if (!isDirStateInfoAvailable()) return null; + try { + return Hex.encodeHexString(readBytesFromFile(myDirStateFile, 20)); + } + catch (IOException e) { + // dirState exists if not fresh, if we could not load dirState info repository must be corrupted + throw new RepoStateException("IOException while trying to read current repository state information.", e); + } + } + + @NotNull + public byte[] readBytesFromFile(@NotNull File file, int len) throws IOException { + byte[] bytes; + final InputStream stream = new FileInputStream(file); + try { + bytes = FileUtil.loadBytes(stream, len); + } + finally { + stream.close(); + } + return bytes; + } + + /** + * Finds tip revision value. + * + * @return The tip revision hash, or <b>{@code null}</b> if tip revision is unknown - it is the initial repository state. + */ + @Nullable + public String readCurrentTipRevision() { if (!isBranchInfoAvailable()) return null; String[] branchesWithHeads = RepositoryUtil.tryLoadFile(myBranchHeadsFile).split("\n"); String head = branchesWithHeads[0]; @@ -113,6 +150,10 @@ public class HgRepositoryReader { return !isFresh() && myBranchHeadsFile.exists(); } + private boolean isDirStateInfoAvailable() { + return myDirStateFile.exists(); + } + /** * Return current branch */ |