本文整理汇总了Java中org.zmlx.hg4idea.util.HgUtil类的典型用法代码示例。如果您正苦于以下问题:Java HgUtil类的具体用法?Java HgUtil怎么用?Java HgUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HgUtil类属于org.zmlx.hg4idea.util包,在下文中一共展示了HgUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractBranchName
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
public static String extractBranchName(Project project) {
String branch = "";
ProjectLevelVcsManager instance = ProjectLevelVcsManagerImpl.getInstance(project);
if (instance.checkVcsIsActive("Git")) {
GitLocalBranch currentBranch = GitBranchUtil.getCurrentRepository(project).getCurrentBranch();
if (currentBranch != null) {
// Branch name matches Ticket Name
branch = currentBranch.getName().trim();
}
} else if (instance.checkVcsIsActive("Mercurial")) {
branch = HgUtil.getCurrentRepository(project).getCurrentBranch().trim();
}
return branch;
}
示例2: initRepository
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@NotNull
@Override
protected Repository initRepository(@NotNull String name) {
String tempDirectory = FileUtil.getTempDirectory();
String root = tempDirectory + "/" + name;
assertTrue(new File(root).mkdirs());
HgPlatformTest.initRepo(root);
touch("a.txt");
hg("add a.txt");
hg("commit -m another");
hg("up -r 0");
ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject);
vcsManager.setDirectoryMapping(root, HgVcs.VCS_NAME);
VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(root));
HgRepository repository = HgUtil.getRepositoryManager(myProject).getRepositoryForRoot(file);
assertNotNull("Couldn't find repository for root " + root, repository);
return repository;
}
示例3: getCurrentUser
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@Nullable
@Override
public VcsUser getCurrentUser(@NotNull VirtualFile root) throws VcsException {
String userName = HgConfig.getInstance(myProject, root).getNamedConfig("ui", "username");
//order of variables to identify hg username see at mercurial/ui.py
if (userName == null) {
userName = System.getenv("HGUSER");
if (userName == null) {
userName = System.getenv("USER");
if (userName == null) {
userName = System.getenv("LOGNAME");
if (userName == null) {
return null;
}
}
}
}
Couple<String> userArgs = HgUtil.parseUserNameAndEmail(userName);
return myVcsObjectsFactory.createUser(userArgs.getFirst(), userArgs.getSecond());
}
示例4: logCommand
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@SuppressWarnings("UseOfSystemOutOrSystemErr")
protected void logCommand(@NotNull String operation, @Nullable List<String> arguments) {
if (myProject.isDisposed()) {
return;
}
final HgGlobalSettings settings = myVcs.getGlobalSettings();
String exeName;
final int lastSlashIndex = settings.getHgExecutable().lastIndexOf(File.separator);
exeName = settings.getHgExecutable().substring(lastSlashIndex + 1);
String str = String.format("%s %s %s", exeName, operation, arguments == null ? "" : StringUtil.join(arguments, " "));
//remove password from path before log
final String cmdString = myDestination != null ? HgUtil.removePasswordIfNeeded(str) : str;
final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
// log command
if (isUnitTestMode) {
System.out.print(cmdString + "\n");
}
if (!myIsSilent) {
LOG.info(cmdString);
myVcs.showMessageInConsole(cmdString, ConsoleViewContentType.NORMAL_OUTPUT.getAttributes());
}
else {
LOG.debug(cmdString);
}
}
示例5: initOrNotifyError
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@Override
protected boolean initOrNotifyError(@NotNull final VirtualFile projectDir) {
final boolean[] success = new boolean[1];
new HgInitCommand(myProject).execute(projectDir, new HgCommandResultHandler() {
@Override
public void process(@Nullable HgCommandResult result) {
VcsNotifier notification = VcsNotifier.getInstance(myProject);
if (!HgErrorUtil.hasErrorsInCommandExecution(result)) {
success[0] = true;
refreshVcsDir(projectDir, HgUtil.DOT_HG);
notification.notifySuccess(HgVcsMessages.message("hg4idea.init.created.notification.title"),
HgVcsMessages
.message("hg4idea.init.created.notification.description", projectDir.getPresentableUrl())
);
}
else {
success[0] = false;
String errors = result != null ? result.getRawError() : "";
notification.notifyError(
HgVcsMessages.message("hg4idea.init.error.description", projectDir.getPresentableUrl()), errors);
}
}
});
return success[0];
}
示例6: cherryPick
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@Override
public void cherryPick(@NotNull final List<VcsFullCommitDetails> commits) {
Map<HgRepository, List<VcsFullCommitDetails>> commitsInRoots = DvcsUtil.groupCommitsByRoots(
HgUtil.getRepositoryManager(myProject), commits);
for (Map.Entry<HgRepository, List<VcsFullCommitDetails>> entry : commitsInRoots.entrySet()) {
processGrafting(entry.getKey(), ContainerUtil.map(entry.getValue(),
new Function<VcsFullCommitDetails, String>() {
@Override
public String fun(
VcsFullCommitDetails commitDetails) {
return commitDetails.getId()
.asString();
}
}));
}
}
示例7: onChangeRepository
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
private void onChangeRepository() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
final VirtualFile repo = hgRepositorySelector.getRepository().getRoot();
final String defaultPath = HgUtil.getRepositoryDefaultPath(project, repo);
if (!StringUtil.isEmptyOrSpaces(defaultPath)) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
addPathsFromHgrc(repo);
myRepositoryURL.setText(HgUtil.removePasswordIfNeeded(defaultPath));
myCurrentRepositoryUrl = defaultPath;
}
});
onChangePullSource();
}
}
});
}
示例8: HgInitDialog
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
public HgInitDialog(@Nullable Project project) {
super(project);
myProject = project;
// a file chooser instead of dialog will be shown immediately if there is no current project or if current project is already an hg root
myShowDialog = (myProject != null && (! myProject.isDefault()) && !HgUtil.isHgRoot(myProject.getBaseDir()));
myFileDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) {
public void validateSelectedFiles(VirtualFile[] files) throws Exception {
if (HgUtil.isHgRoot(files[0])) {
throw new ConfigurationException(HgVcsMessages.message("hg4idea.init.this.is.hg.root", files[0].getPresentableUrl()));
}
updateEverything();
}
};
myFileDescriptor.setHideIgnored(false);
init();
}
示例9: annotate
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
public FileAnnotation annotate(VirtualFile file, VcsFileRevision revision) throws VcsException {
final VirtualFile vcsRoot = VcsUtil.getVcsRootFor(myProject, VcsUtil.getFilePath(file.getPath()));
if (vcsRoot == null) {
throw new VcsException("vcs root is null for " + file);
}
final HgFile hgFile = new HgFile(vcsRoot, VfsUtilCore.virtualToIoFile(file));
HgFile fileToAnnotate = revision instanceof HgFileRevision
? HgUtil.getFileNameInTargetRevision(myProject, ((HgFileRevision)revision).getRevisionNumber(), hgFile)
: new HgFile(vcsRoot,
HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(myProject)));
final List<HgAnnotationLine> annotationResult = (new HgAnnotateCommand(myProject)).execute(fileToAnnotate, revision);
final List<HgFileRevision> logResult;
try {
HgLogCommand logCommand = new HgLogCommand(myProject);
logCommand.setFollowCopies(true);
logResult = logCommand.execute(fileToAnnotate, -1, false);
}
catch (HgCommandException e) {
throw new VcsException("Can not annotate, " + HgVcsMessages.message("hg4idea.error.log.command.execution"), e);
}
VcsRevisionNumber revisionNumber = revision == null ?
new HgWorkingCopyRevisionsCommand(myProject).tip(vcsRoot) :
revision.getRevisionNumber();
return new HgAnnotation(myProject, hgFile, annotationResult, logResult, revisionNumber);
}
示例10: addFile
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
private void addFile(Map<HgRepository, Set<HgFile>> result, ContentRevision contentRevision) {
FilePath filePath = contentRevision.getFile();
// try to find repository from hgFile from change: to be able commit sub repositories as expected
HgRepository repo = HgUtil.getRepositoryForFile(myProject, contentRevision instanceof HgCurrentBinaryContentRevision
? ((HgCurrentBinaryContentRevision)contentRevision).getRepositoryRoot()
: ChangesUtil.findValidParentAccurately(filePath));
if (repo == null) {
return;
}
Set<HgFile> hgFiles = result.get(repo);
if (hgFiles == null) {
hgFiles = new HashSet<HgFile>();
result.put(repo, hgFiles);
}
hgFiles.add(new HgFile(repo.getRoot(), filePath));
}
示例11: getOneList
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@Override
public Pair<CommittedChangeList, FilePath> getOneList(VirtualFile file, VcsRevisionNumber number) throws VcsException {
final ChangeBrowserSettings settings = createDefaultSettings();
settings.USE_CHANGE_AFTER_FILTER = true;
settings.USE_CHANGE_BEFORE_FILTER = true;
settings.CHANGE_AFTER = number.asString();
settings.CHANGE_BEFORE = number.asString();
// todo implement in proper way
VirtualFile localVirtualFile = HgUtil.convertToLocalVirtualFile(file);
if (localVirtualFile == null) {
return null;
}
final FilePath filePath = VcsUtil.getFilePath(localVirtualFile);
final CommittedChangeList list = getCommittedChangesForRevision(getLocationFor(filePath), number.asString());
if (list != null) {
return new Pair<CommittedChangeList, FilePath>(list, filePath);
}
return null;
}
示例12: commitOrWarnAboutConflicts
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
private void commitOrWarnAboutConflicts(List<VcsException> exceptions, HgCommandResult mergeResult) throws VcsException {
if (mergeResult.getExitValue() == 0) { //operation successful and no conflicts
try {
HgRepository hgRepository = HgUtil.getRepositoryForFile(project, repoRoot);
if (hgRepository == null) {
LOG.warn("Couldn't find repository info for " + repoRoot.getName());
return;
}
new HgCommitCommand(project, hgRepository, "Automated merge").execute();
}
catch (HgCommandException e) {
throw new VcsException(e);
}
}
else {
reportWarning(exceptions, HgVcsMessages.message("hg4idea.update.warning.merge.conflicts", repoRoot.getPath()));
}
}
示例13: process
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
private Collection<HgChange> process(ChangelistBuilder builder, Collection<FilePath> files) {
final Set<HgChange> hgChanges = new HashSet<HgChange>();
for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(myProject, files).entrySet()) {
VirtualFile repo = entry.getKey();
final HgRevisionNumber workingRevision = new HgWorkingCopyRevisionsCommand(myProject).identify(repo).getFirst();
final HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(repo);
final Map<HgFile, HgResolveStatusEnum> list = new HgResolveCommand(myProject).getListSynchronously(repo);
hgChanges.addAll(new HgStatusCommand.Builder(true).build(myProject).execute(repo, entry.getValue()));
final HgRepository hgRepo = HgUtil.getRepositoryForFile(myProject, repo);
if (hgRepo != null && hgRepo.hasSubrepos()) {
hgChanges.addAll(ContainerUtil.mapNotNull(hgRepo.getSubrepos(), new Function<HgNameWithHashInfo, HgChange>() {
@Override
public HgChange fun(HgNameWithHashInfo info) {
return findChange(hgRepo, info);
}
}));
}
sendChanges(builder, hgChanges, list, workingRevision, parentRevision);
}
return hgChanges;
}
示例14: processUnsavedChanges
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
/**
* Finds modified but unsaved files in the given list of dirty files and notifies the builder about MODIFIED changes.
* Changes contained in <code>alreadyProcessed</code> are skipped - they have already been processed as modified, or else.
*/
public void processUnsavedChanges(ChangelistBuilder builder, Set<FilePath> dirtyFiles, Collection<HgChange> alreadyProcessed) {
// exclude already processed
for (HgChange c : alreadyProcessed) {
dirtyFiles.remove(c.beforeFile().toFilePath());
dirtyFiles.remove(c.afterFile().toFilePath());
}
final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
for (FilePath filePath : dirtyFiles) {
final VirtualFile vf = filePath.getVirtualFile();
if (vf != null && fileDocumentManager.isFileModified(vf)) {
final VirtualFile root = vcsManager.getVcsRootFor(vf);
if (root != null && HgUtil.isHgRoot(root)) {
final HgRevisionNumber beforeRevisionNumber = new HgWorkingCopyRevisionsCommand(myProject).tip(root);
final ContentRevision beforeRevision = (beforeRevisionNumber == null ? null :
HgContentRevision.create(myProject, new HgFile(myProject, vf), beforeRevisionNumber));
builder.processChange(new Change(beforeRevision, CurrentContentRevision.create(filePath), FileStatus.MODIFIED), myVcsKey);
}
}
}
}
示例15: filterUniqueRoots
import org.zmlx.hg4idea.util.HgUtil; //导入依赖的package包/类
@Override
public <S> List<S> filterUniqueRoots(final List<S> in, final Convertor<S, VirtualFile> convertor) {
Collections.sort(in, new ComparatorDelegate<S, VirtualFile>(convertor, FilePathComparator.getInstance()));
for (int i = 1; i < in.size(); i++) {
final S sChild = in.get(i);
final VirtualFile child = convertor.convert(sChild);
final VirtualFile childRoot = HgUtil.getHgRootOrNull(myProject, child);
if (childRoot == null) {
continue;
}
for (int j = i - 1; j >= 0; --j) {
final S sParent = in.get(j);
final VirtualFile parent = convertor.convert(sParent);
// if the parent is an ancestor of the child and that they share common root, the child is removed
if (VfsUtilCore.isAncestor(parent, child, false) && VfsUtilCore.isAncestor(childRoot, parent, false)) {
in.remove(i);
//noinspection AssignmentToForLoopParameter
--i;
break;
}
}
}
return in;
}