diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java index 6f1edf3dce90..e8f170bba3c4 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgLogProvider.java @@ -109,6 +109,8 @@ public class HgLogProvider implements VcsLogProvider { repository.update(); Collection branches = repository.getBranches(); Collection bookmarks = repository.getBookmarks(); + Collection tags = repository.getTags(); + Collection localTags = repository.getLocalTags(); Collection refs = new ArrayList(branches.size() + bookmarks.size()); @@ -123,17 +125,16 @@ public class HgLogProvider implements VcsLogProvider { if (currentRevision != null) { // null => fresh repository refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(currentRevision), "HEAD", HgRefManager.HEAD, root)); } - - //refs.addAll(readTags(root)); + for (HgNameWithHashInfo tagInfo : tags) { + refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(tagInfo.getHash()), tagInfo.getName(), HgRefManager.TAG, root)); + } + for (HgNameWithHashInfo localTagInfo : localTags) { + refs.add(new VcsRefImpl(myVcsObjectsFactory.createHash(localTagInfo.getHash()), localTagInfo.getName(), + HgRefManager.LOCAL_TAG, root)); + } return refs; } - //todo implement - /* @NotNull - private Collection readTags(@NotNull VirtualFile root) throws VcsException { - return Collections.emptyList(); - }*/ - @NotNull @Override public VcsKey getSupportedVcs() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java index c963c267dba0..1a52c2b49e22 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/log/HgRefManager.java @@ -38,11 +38,13 @@ public class HgRefManager implements VcsLogRefManager { private static final Color BRANCH_COLOR = new JBColor(new Color(0x75eec7), new Color(0x0D6D4F)); private static final Color BOOKMARK_COLOR = new JBColor(new Color(0xbcbcfc), new Color(0xbcbcfc).darker().darker()); private static final Color TAG_COLOR = JBColor.WHITE; + private static final Color LOCAL_TAG_COLOR = JBColor.CYAN; public static final VcsRefType HEAD = new SimpleRefType(true, HEAD_COLOR); public static final VcsRefType BRANCH = new SimpleRefType(true, BRANCH_COLOR); public static final VcsRefType BOOKMARK = new SimpleRefType(true, BOOKMARK_COLOR); public static final VcsRefType TAG = new SimpleRefType(false, TAG_COLOR); + public static final VcsRefType LOCAL_TAG = new SimpleRefType(false, LOCAL_TAG_COLOR); // first has the highest priority private static final List REF_TYPE_PRIORITIES = Arrays.asList(HEAD, BRANCH, BOOKMARK, TAG); @@ -103,7 +105,6 @@ public class HgRefManager implements VcsLogRefManager { @NotNull @Override public List group(Collection refs) { - // TODO group non-tracking refs into remotes return ContainerUtil.map(sort(refs), new Function() { @Override public RefGroup fun(final VcsRef ref) { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoInfo.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoInfo.java index d16dc7dd2dd4..90c59372dc8e 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoInfo.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepoInfo.java @@ -36,19 +36,25 @@ public class HgRepoInfo { @Nullable private String myCurrentBookmark = null; @NotNull private Set myBranches = Collections.emptySet(); @NotNull private Set myBookmarks = Collections.emptySet(); + @NotNull private Set myTags = Collections.emptySet(); + @NotNull private Set myLocalTags = Collections.emptySet(); public HgRepoInfo(@NotNull String currentBranch, @Nullable String currentRevision, @NotNull Repository.State state, @NotNull Collection branches, @NotNull Collection bookmarks, - @Nullable String currentBookmark) { + @Nullable String currentBookmark, + @NotNull Collection tags, + @NotNull Collection localTags) { myCurrentBranch = currentBranch; myCurrentRevision = currentRevision; myState = state; myBranches = new LinkedHashSet(branches); myBookmarks = new LinkedHashSet(bookmarks); myCurrentBookmark = currentBookmark; + myTags = new LinkedHashSet(tags); + myLocalTags = new LinkedHashSet(localTags); } @NotNull @@ -66,6 +72,16 @@ public class HgRepoInfo { return myBookmarks; } + @NotNull + public Collection getTags() { + return myTags; + } + + @NotNull + public Collection getLocalTags() { + return myLocalTags; + } + @Nullable public String getCurrentRevision() { return myCurrentRevision; @@ -94,13 +110,15 @@ public class HgRepoInfo { if (myCurrentBookmark != null ? !myCurrentBookmark.equals(info.myCurrentBookmark) : info.myCurrentBookmark != null) return false; if (!myBranches.equals(info.myBranches)) return false; if (!myBookmarks.equals(info.myBookmarks)) return false; + if (!myTags.equals(info.myTags)) return false; + if (!myLocalTags.equals(info.myLocalTags)) return false; return true; } @Override public int hashCode() { - return Objects.hashCode(myCurrentBranch, myCurrentRevision, myCurrentBookmark, myState, myBranches, myBookmarks); + return Objects.hashCode(myCurrentBranch, myCurrentRevision, myCurrentBookmark, myState, myBranches, myBookmarks, myTags, myLocalTags); } @Override diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java index 572b4a9589ce..fbaaa4f14a94 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepository.java @@ -44,6 +44,12 @@ public interface HgRepository extends Repository { @NotNull Collection getBookmarks(); + @NotNull + Collection getTags(); + + @NotNull + Collection getLocalTags(); + @Nullable String getCurrentBookmark(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java index 0ee790df1838..c3d9bc4e63ae 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryImpl.java @@ -105,6 +105,18 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository { return myInfo.getCurrentBookmark(); } + @NotNull + @Override + public Collection getTags() { + return myInfo.getTags(); + } + + @NotNull + @Override + public Collection getLocalTags() { + return myInfo.getLocalTags(); + } + @NotNull @Override public HgConfig getRepositoryConfig() { @@ -142,7 +154,7 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository { //in GitRepositoryImpl there are temporary state object for reader fields storing! Todo Check; return new HgRepoInfo(myReader.readCurrentBranch(), myReader.readCurrentRevision(), myReader.readState(), myReader.readBranches(), - myReader.readBookmarks(), myReader.readCurrentBookmark()); + myReader.readBookmarks(), myReader.readCurrentBookmark(), myReader.readTags(), myReader.readLocalTags()); } public void updateConfig() { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java index e7bf3780ef63..39524ad46e28 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/repo/HgRepositoryReader.java @@ -45,6 +45,8 @@ public class HgRepositoryReader { @NotNull private final File myCurrentBranch; // .hg/branch @NotNull private final File myBookmarksFile; //.hg/bookmarks @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 VcsLogObjectsFactory myVcsObjectsFactory; public HgRepositoryReader(@NotNull File hgDir) { @@ -56,6 +58,8 @@ public class HgRepositoryReader { myCurrentBranch = new File(myHgDir, "branch"); myBookmarksFile = new File(myHgDir, "bookmarks"); myCurrentBookmark = new File(myHgDir, "bookmarks.current"); + myLocalTagsFile = new File(myHgDir, "localtags"); + myTagsFile = new File(myHgDir.getParentFile(), ".hgtags"); myVcsObjectsFactory = ServiceManager.getService(VcsLogObjectsFactory.class); } @@ -123,19 +127,34 @@ public class HgRepositoryReader { @NotNull public Collection readBookmarks() { - // .hg/bookmarks contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark - Set bookmarks = new HashSet(); - if (!myBookmarksFile.exists()) { - return bookmarks; + return readReference(myBookmarksFile); + } + + @NotNull + public Collection readTags() { + return readReference(myTagsFile); + } + + @NotNull + public Collection readLocalTags() { + return readReference(myLocalTagsFile); + } + + @NotNull + private Collection readReference(@NotNull File fileWithReferences) { + // files like .hg/bookmarks which contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark + Set refs = new HashSet(); + if (!fileWithReferences.exists()) { + return refs; } - String[] bookmarksWithHeads = RepositoryUtil.tryLoadFile(myBookmarksFile).split("\n"); - for (String str : bookmarksWithHeads) { + String[] namesWithHashes = RepositoryUtil.tryLoadFile(fileWithReferences).split("\n"); + for (String str : namesWithHashes) { Matcher matcher = HASH_NAME.matcher(str); if (matcher.matches()) { - bookmarks.add(new HgNameWithHashInfo(matcher.group(2), myVcsObjectsFactory.createHash(matcher.group(1)))); + refs.add(new HgNameWithHashInfo(matcher.group(2), myVcsObjectsFactory.createHash(matcher.group(1)))); } } - return bookmarks; + return refs; } @Nullable diff --git a/plugins/hg4idea/testData/repo/.hgtags b/plugins/hg4idea/testData/repo/.hgtags new file mode 100644 index 000000000000..3feb1e05c09d --- /dev/null +++ b/plugins/hg4idea/testData/repo/.hgtags @@ -0,0 +1,2 @@ +25e44c95b2612e3cdf29a704dabf82c77066cb67 tag1 +c4e6b94abdf018515b2300698e3eb9b441d53619 tag2 \ No newline at end of file diff --git a/plugins/hg4idea/testData/repo/dot_hg/localtags b/plugins/hg4idea/testData/repo/dot_hg/localtags new file mode 100644 index 000000000000..7c4415461832 --- /dev/null +++ b/plugins/hg4idea/testData/repo/dot_hg/localtags @@ -0,0 +1 @@ +25e44c95b2612e3cdf29a704dabf82c77066cb67 localTag \ No newline at end of file diff --git a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java index cdaaefec81cb..642e125f1f11 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRealRepositoryReaderTest.java @@ -40,7 +40,7 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest { super.setUp(); File hgDir = new File(myRepository.getPath(), ".hg"); assertTrue(hgDir.exists()); - createBranches(); + createBranchesAndTags(); myRepositoryReader = new HgRepositoryReader(hgDir); } @@ -62,6 +62,16 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest { Arrays.asList("default", "branchA", "branchB")); } + public void testTags() { + TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags()), + Arrays.asList("tag1", "tag2")); + } + + public void testLocalTags() { + TestRepositoryUtil.assertEqualCollections(HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags()), + Arrays.asList("localTag")); + } + public void testCurrentBookmark() { hg("update B_BookMark"); assertEquals(myRepositoryReader.readCurrentBookmark(), "B_BookMark"); @@ -72,19 +82,22 @@ public class HgRealRepositoryReaderTest extends HgPlatformTest { Arrays.asList("A_BookMark", "B_BookMark", "C_BookMark")); } - private void createBranches() { + private void createBranchesAndTags() { cd(myRepository); hg("bookmark A_BookMark"); + hg("tag tag1"); String aFile = "A.txt"; touch(aFile, "base"); hg("add " + aFile); hg("commit -m 'create file'"); hg("bookmark B_BookMark"); hg("branch branchA"); + hg("tag tag2"); echo(aFile, " modify with a"); hg("commit -m 'create branchA'"); hg("up default"); hg("branch branchB"); + hg("tag -l localTag"); echo(aFile, " modify with b"); hg("commit -m 'modify file in branchB'"); hg("bookmark C_BookMark"); diff --git a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java index 045e66516e3e..872951ca5be8 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/repo/HgRepositoryReaderTest.java @@ -37,6 +37,8 @@ public class HgRepositoryReaderTest extends HgPlatformTest { @NotNull private File myHgDir; @NotNull private Collection myBranches; @NotNull private Collection myBookmarks; + @NotNull private Collection myTags; + @NotNull private Collection myLocalTags; @Override public void setUp() throws Exception { @@ -52,14 +54,20 @@ public class HgRepositoryReaderTest extends HgPlatformTest { File testBranchFile = new File(testHgDir, "branch"); File testBookmarkFile = new File(testHgDir, "bookmarks"); File testCurrentBookmarkFile = new File(testHgDir, "bookmarks.current"); + File testTagFile = new File(testHgDir.getParentFile(), ".hgtags"); + File testLocalTagFile = new File(testHgDir, "localtags"); FileUtil.copyDir(cacheDir, new File(myHgDir, "cache")); FileUtil.copy(testBranchFile, new File(myHgDir, "branch")); FileUtil.copy(testBookmarkFile, new File(myHgDir, "bookmarks")); FileUtil.copy(testCurrentBookmarkFile, new File(myHgDir, "bookmarks.current")); + FileUtil.copy(testTagFile, new File(myHgDir.getParentFile(), ".hgtags")); + FileUtil.copy(testLocalTagFile, new File(myHgDir, "localtags")); myRepositoryReader = new HgRepositoryReader(myHgDir); myBranches = readBranches(); - myBookmarks = readBookmarks(); + myBookmarks = readRefs(testBookmarkFile); + myTags = readRefs(testTagFile); + myLocalTags = readRefs(testLocalTagFile); } public void testHEAD() { @@ -81,6 +89,16 @@ public class HgRepositoryReaderTest extends HgPlatformTest { TestRepositoryUtil.assertEqualCollections(bookmarks, myBookmarks); } + public void testTags() { + Collection tags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags()); + TestRepositoryUtil.assertEqualCollections(tags, myTags); + } + + public void testLocalTags() { + Collection localTags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags()); + TestRepositoryUtil.assertEqualCollections(localTags, myLocalTags); + } + @NotNull private Collection readBranches() throws IOException { Collection branches = new HashSet(); @@ -100,15 +118,14 @@ public class HgRepositoryReaderTest extends HgPlatformTest { } @NotNull - private Collection readBookmarks() throws IOException { - Collection bookmarks = new HashSet(); - File bookmarksFile = new File(myHgDir, "bookmarks"); - String[] bookmarksWithHashes = FileUtil.loadFile(bookmarksFile).split("\n"); - for (String str : bookmarksWithHashes) { + private static Collection readRefs(@NotNull File refFile) throws IOException { + Collection refs = new HashSet(); + String[] refsWithHashes = FileUtil.loadFile(refFile).split("\n"); + for (String str : refsWithHashes) { String[] refAndName = str.trim().split(" "); assertEquals(2, refAndName.length); - bookmarks.add(refAndName[1]); + refs.add(refAndName[1]); } - return bookmarks; + return refs; } }