Tags and local tags references added to new log and repository reader

*tags read from appropriate file
*tests added
*references and colors for tags added to log
This commit is contained in:
Nadya Zabrodina
2013-10-31 20:23:10 +04:00
parent df823d606f
commit 2f15377c29
10 changed files with 120 additions and 30 deletions
@@ -109,6 +109,8 @@ public class HgLogProvider implements VcsLogProvider {
repository.update();
Collection<HgNameWithHashInfo> branches = repository.getBranches();
Collection<HgNameWithHashInfo> bookmarks = repository.getBookmarks();
Collection<HgNameWithHashInfo> tags = repository.getTags();
Collection<HgNameWithHashInfo> localTags = repository.getLocalTags();
Collection<VcsRef> refs = new ArrayList<VcsRef>(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<? extends VcsRef> readTags(@NotNull VirtualFile root) throws VcsException {
return Collections.emptyList();
}*/
@NotNull
@Override
public VcsKey getSupportedVcs() {
@@ -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<VcsRefType> REF_TYPE_PRIORITIES = Arrays.asList(HEAD, BRANCH, BOOKMARK, TAG);
@@ -103,7 +105,6 @@ public class HgRefManager implements VcsLogRefManager {
@NotNull
@Override
public List<RefGroup> group(Collection<VcsRef> refs) {
// TODO group non-tracking refs into remotes
return ContainerUtil.map(sort(refs), new Function<VcsRef, RefGroup>() {
@Override
public RefGroup fun(final VcsRef ref) {
@@ -36,19 +36,25 @@ public class HgRepoInfo {
@Nullable private String myCurrentBookmark = null;
@NotNull private Set<HgNameWithHashInfo> myBranches = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myBookmarks = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myTags = Collections.emptySet();
@NotNull private Set<HgNameWithHashInfo> myLocalTags = Collections.emptySet();
public HgRepoInfo(@NotNull String currentBranch,
@Nullable String currentRevision,
@NotNull Repository.State state,
@NotNull Collection<HgNameWithHashInfo> branches,
@NotNull Collection<HgNameWithHashInfo> bookmarks,
@Nullable String currentBookmark) {
@Nullable String currentBookmark,
@NotNull Collection<HgNameWithHashInfo> tags,
@NotNull Collection<HgNameWithHashInfo> localTags) {
myCurrentBranch = currentBranch;
myCurrentRevision = currentRevision;
myState = state;
myBranches = new LinkedHashSet<HgNameWithHashInfo>(branches);
myBookmarks = new LinkedHashSet<HgNameWithHashInfo>(bookmarks);
myCurrentBookmark = currentBookmark;
myTags = new LinkedHashSet<HgNameWithHashInfo>(tags);
myLocalTags = new LinkedHashSet<HgNameWithHashInfo>(localTags);
}
@NotNull
@@ -66,6 +72,16 @@ public class HgRepoInfo {
return myBookmarks;
}
@NotNull
public Collection<HgNameWithHashInfo> getTags() {
return myTags;
}
@NotNull
public Collection<HgNameWithHashInfo> 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
@@ -44,6 +44,12 @@ public interface HgRepository extends Repository {
@NotNull
Collection<HgNameWithHashInfo> getBookmarks();
@NotNull
Collection<HgNameWithHashInfo> getTags();
@NotNull
Collection<HgNameWithHashInfo> getLocalTags();
@Nullable
String getCurrentBookmark();
@@ -105,6 +105,18 @@ public class HgRepositoryImpl extends RepositoryImpl implements HgRepository {
return myInfo.getCurrentBookmark();
}
@NotNull
@Override
public Collection<HgNameWithHashInfo> getTags() {
return myInfo.getTags();
}
@NotNull
@Override
public Collection<HgNameWithHashInfo> 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() {
@@ -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<HgNameWithHashInfo> readBookmarks() {
// .hg/bookmarks contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark
Set<HgNameWithHashInfo> bookmarks = new HashSet<HgNameWithHashInfo>();
if (!myBookmarksFile.exists()) {
return bookmarks;
return readReference(myBookmarksFile);
}
@NotNull
public Collection<HgNameWithHashInfo> readTags() {
return readReference(myTagsFile);
}
@NotNull
public Collection<HgNameWithHashInfo> readLocalTags() {
return readReference(myLocalTagsFile);
}
@NotNull
private Collection<HgNameWithHashInfo> readReference(@NotNull File fileWithReferences) {
// files like .hg/bookmarks which contains hash + name, f.e. 25e44c95b2612e3cdf29a704dabf82c77066cb67 A_BookMark
Set<HgNameWithHashInfo> refs = new HashSet<HgNameWithHashInfo>();
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
+2
View File
@@ -0,0 +1,2 @@
25e44c95b2612e3cdf29a704dabf82c77066cb67 tag1
c4e6b94abdf018515b2300698e3eb9b441d53619 tag2
@@ -0,0 +1 @@
25e44c95b2612e3cdf29a704dabf82c77066cb67 localTag
@@ -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");
@@ -37,6 +37,8 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
@NotNull private File myHgDir;
@NotNull private Collection<String> myBranches;
@NotNull private Collection<String> myBookmarks;
@NotNull private Collection<String> myTags;
@NotNull private Collection<String> 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<String> tags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readTags());
TestRepositoryUtil.assertEqualCollections(tags, myTags);
}
public void testLocalTags() {
Collection<String> localTags = HgUtil.getNamesWithoutHashes(myRepositoryReader.readLocalTags());
TestRepositoryUtil.assertEqualCollections(localTags, myLocalTags);
}
@NotNull
private Collection<String> readBranches() throws IOException {
Collection<String> branches = new HashSet<String>();
@@ -100,15 +118,14 @@ public class HgRepositoryReaderTest extends HgPlatformTest {
}
@NotNull
private Collection<String> readBookmarks() throws IOException {
Collection<String> bookmarks = new HashSet<String>();
File bookmarksFile = new File(myHgDir, "bookmarks");
String[] bookmarksWithHashes = FileUtil.loadFile(bookmarksFile).split("\n");
for (String str : bookmarksWithHashes) {
private static Collection<String> readRefs(@NotNull File refFile) throws IOException {
Collection<String> refs = new HashSet<String>();
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;
}
}