use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.
the class HgLogProvider method readAllRefs.
@NotNull
private Set<VcsRef> readAllRefs(@NotNull VirtualFile root) throws VcsException {
if (myProject.isDisposed()) {
return Collections.emptySet();
}
HgRepository repository = myRepositoryManager.getRepositoryForRoot(root);
if (repository == null) {
LOG.error("Repository not found for root " + root);
return Collections.emptySet();
}
repository.update();
Map<String, LinkedHashSet<Hash>> branches = repository.getBranches();
Set<String> openedBranchNames = repository.getOpenedBranches();
Collection<HgNameWithHashInfo> bookmarks = repository.getBookmarks();
Collection<HgNameWithHashInfo> tags = repository.getTags();
Collection<HgNameWithHashInfo> localTags = repository.getLocalTags();
Collection<HgNameWithHashInfo> mqAppliedPatches = repository.getMQAppliedPatches();
Set<VcsRef> refs = new HashSet<>(branches.size() + bookmarks.size());
for (Map.Entry<String, LinkedHashSet<Hash>> entry : branches.entrySet()) {
String branchName = entry.getKey();
boolean opened = openedBranchNames.contains(branchName);
for (Hash hash : entry.getValue()) {
refs.add(myVcsObjectsFactory.createRef(hash, branchName, opened ? HgRefManager.BRANCH : HgRefManager.CLOSED_BRANCH, root));
}
}
for (HgNameWithHashInfo bookmarkInfo : bookmarks) {
refs.add(myVcsObjectsFactory.createRef(bookmarkInfo.getHash(), bookmarkInfo.getName(), HgRefManager.BOOKMARK, root));
}
String currentRevision = repository.getCurrentRevision();
if (currentRevision != null) {
// null => fresh repository
refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(currentRevision), HEAD_REFERENCE, HgRefManager.HEAD, root));
}
String tipRevision = repository.getTipRevision();
if (tipRevision != null) {
// null => fresh repository
refs.add(myVcsObjectsFactory.createRef(myVcsObjectsFactory.createHash(tipRevision), TIP_REFERENCE, HgRefManager.TIP, root));
}
for (HgNameWithHashInfo tagInfo : tags) {
refs.add(myVcsObjectsFactory.createRef(tagInfo.getHash(), tagInfo.getName(), HgRefManager.TAG, root));
}
for (HgNameWithHashInfo localTagInfo : localTags) {
refs.add(myVcsObjectsFactory.createRef(localTagInfo.getHash(), localTagInfo.getName(), HgRefManager.LOCAL_TAG, root));
}
for (HgNameWithHashInfo mqPatchRef : mqAppliedPatches) {
refs.add(myVcsObjectsFactory.createRef(mqPatchRef.getHash(), mqPatchRef.getName(), HgRefManager.MQ_APPLIED_TAG, root));
}
return refs;
}
use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.
the class HgBranchUtil method getCommonBranches.
/**
* Only common hg heavy branches
*/
@NotNull
public static List<String> getCommonBranches(@NotNull Collection<HgRepository> repositories) {
Collection<String> commonBranches = null;
for (HgRepository repository : repositories) {
Collection<String> names = repository.getOpenedBranches();
if (commonBranches == null) {
commonBranches = names;
} else {
commonBranches = ContainerUtil.intersection(commonBranches, names);
}
}
if (commonBranches != null) {
ArrayList<String> common = new ArrayList<>(commonBranches);
Collections.sort(common);
return common;
} else {
return Collections.emptyList();
}
}
use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.
the class HgBranchUtil method getCommonBookmarks.
@NotNull
public static List<String> getCommonBookmarks(@NotNull Collection<HgRepository> repositories) {
Collection<String> commonBookmarkNames = null;
for (HgRepository repository : repositories) {
Collection<HgNameWithHashInfo> bookmarksInfo = repository.getBookmarks();
Collection<String> names = HgUtil.getSortedNamesWithoutHashes(bookmarksInfo);
if (commonBookmarkNames == null) {
commonBookmarkNames = names;
} else {
commonBookmarkNames = ContainerUtil.intersection(commonBookmarkNames, names);
}
}
if (commonBookmarkNames != null) {
ArrayList<String> common = new ArrayList<>(commonBookmarkNames);
Collections.sort(common);
return common;
} else {
return Collections.emptyList();
}
}
use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.
the class HgChangeProvider method findChange.
@Nullable
private HgChange findChange(@NotNull HgRepository hgRepo, @NotNull HgNameWithHashInfo info) {
File file = new File(hgRepo.getRoot().getPath(), info.getName());
VirtualFile virtualSubrepoFile = VfsUtil.findFileByIoFile(file, false);
HgRepository subrepo = HgUtil.getRepositoryForFile(myProject, virtualSubrepoFile);
if (subrepo != null && !info.getHash().asString().equals(subrepo.getCurrentRevision())) {
return new HgChange(new HgFile(hgRepo.getRoot(), VcsUtil.getFilePath(virtualSubrepoFile)), HgFileStatusEnum.MODIFIED);
}
return null;
}
use of org.zmlx.hg4idea.repo.HgRepository in project intellij-community by JetBrains.
the class HgCheckinEnvironment method commit.
public List<VcsException> commit(List<Change> changes, String preparedComment, @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
List<VcsException> exceptions = new LinkedList<>();
Map<HgRepository, Set<HgFile>> repositoriesMap = getFilesByRepository(changes);
addRepositoriesWithoutChanges(repositoriesMap);
for (Map.Entry<HgRepository, Set<HgFile>> entry : repositoriesMap.entrySet()) {
HgRepository repo = entry.getKey();
Set<HgFile> selectedFiles = entry.getValue();
HgCommitTypeCommand command = myMqNewPatch ? new HgQNewCommand(myProject, repo, preparedComment, myNextCommitAmend) : new HgCommitCommand(myProject, repo, preparedComment, myNextCommitAmend, myCloseBranch, myShouldCommitSubrepos && !selectedFiles.isEmpty());
if (isMergeCommit(repo.getRoot())) {
//partial commits are not allowed during merges
//verifyResult that all changed files in the repo are selected
//If so, commit the entire repository
//If not, abort
Set<HgFile> changedFilesNotInCommit = getChangedFilesNotInCommit(repo.getRoot(), selectedFiles);
boolean partial = !changedFilesNotInCommit.isEmpty();
if (partial) {
final StringBuilder filesNotIncludedString = new StringBuilder();
for (HgFile hgFile : changedFilesNotInCommit) {
filesNotIncludedString.append("<li>");
filesNotIncludedString.append(hgFile.getRelativePath());
filesNotIncludedString.append("</li>");
}
if (!mayCommitEverything(filesNotIncludedString.toString())) {
//abort
return exceptions;
}
//firstly selected changes marked dirty in CommitHelper -> postRefresh, so we need to mark others
VcsDirtyScopeManager dirtyManager = VcsDirtyScopeManager.getInstance(myProject);
for (HgFile hgFile : changedFilesNotInCommit) {
dirtyManager.fileDirty(hgFile.toFilePath());
}
}
// else : all was included, or it was OK to commit everything,
// so no need to set the files on the command, because then mercurial will complain
} else {
command.setFiles(selectedFiles);
}
try {
command.executeInCurrentThread();
} catch (HgCommandException e) {
exceptions.add(new VcsException(e));
} catch (VcsException e) {
exceptions.add(e);
}
}
// push if needed
if (myNextCommitIsPushed && exceptions.isEmpty()) {
final List<HgRepository> preselectedRepositories = ContainerUtil.newArrayList(repositoriesMap.keySet());
GuiUtils.invokeLaterIfNeeded(() -> new VcsPushDialog(myProject, preselectedRepositories, HgUtil.getCurrentRepository(myProject)).show(), ModalityState.defaultModalityState());
}
return exceptions;
}
Aggregations