Search in sources :

Example 11 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgAnnotateCommand method parse.

private static List<HgAnnotationLine> parse(List<String> outputLines) {
    List<HgAnnotationLine> annotations = new ArrayList<>(outputLines.size());
    for (String line : outputLines) {
        Matcher matcher = LINE_PATTERN.matcher(line);
        if (matcher.matches()) {
            String user = matcher.group(USER_GROUP).trim();
            HgRevisionNumber rev = HgRevisionNumber.getInstance(matcher.group(REVISION_GROUP), matcher.group(CHANGESET_GROUP));
            String dateGroup = matcher.group(DATE_GROUP).trim();
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
            String date = "";
            try {
                date = DateFormatUtil.formatPrettyDate(dateFormat.parse(dateGroup));
            } catch (ParseException e) {
                LOG.error("Couldn't parse annotation date ", e);
            }
            Integer lineNumber = Integer.valueOf(matcher.group(LINE_NUMBER_GROUP));
            String content = matcher.group(CONTENT_GROUP);
            HgAnnotationLine annotationLine = new HgAnnotationLine(user, rev, date, lineNumber, content);
            annotations.add(annotationLine);
        }
    }
    return annotations;
}
Also used : HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) Matcher(java.util.regex.Matcher) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgChangesetsCommand method getRevisions.

protected List<HgRevisionNumber> getRevisions(VirtualFile repo) {
    List<String> args = new ArrayList<>(Arrays.asList("--template", HgChangesetUtil.makeTemplate("{rev}", "{node}", "{author}", "{desc|firstline}"), "--quiet"));
    addArguments(args);
    HgCommandResult result = executeCommandInCurrentThread(repo, args);
    if (result == null) {
        return Collections.emptyList();
    }
    String output = result.getRawOutput();
    if (StringUtil.isEmpty(output)) {
        return Collections.emptyList();
    }
    String[] changesets = output.split(HgChangesetUtil.CHANGESET_SEPARATOR);
    List<HgRevisionNumber> revisions = new ArrayList<>(changesets.length);
    for (String changeset : changesets) {
        List<String> parts = StringUtil.split(changeset, HgChangesetUtil.ITEM_SEPARATOR);
        if (parts.size() >= 3) {
            //support zero commit message
            revisions.add(HgRevisionNumber.getInstance(parts.get(0), parts.get(1), parts.get(2), parts.size() > 3 ? parts.get(3) : ""));
        } else {
            LOG.warn("Could not parse changeset [" + changeset + "]");
        }
    }
    return revisions;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ArrayList(java.util.ArrayList)

Example 13 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgRollbackEnvironment method revert.

private void revert(@NotNull List<FilePath> filePaths) {
    for (Map.Entry<VirtualFile, Collection<FilePath>> entry : HgUtil.groupFilePathsByHgRoots(project, filePaths).entrySet()) {
        final VirtualFile repo = entry.getKey();
        final Collection<FilePath> files = entry.getValue();
        HgRevisionNumber revisionNumber = new HgWorkingCopyRevisionsCommand(project).firstParent(repo);
        for (List<String> chunk : VcsFileUtil.chunkPaths(repo, files)) {
            HgCommandResult revertResult = new HgRevertCommand(project).execute(repo, chunk, revisionNumber, false);
            if (HgErrorUtil.hasUncommittedChangesConflict(revertResult)) {
                String message = String.format("<html>Revert failed due to uncommitted merge.<br>" + "Would you like to discard all changes for repository <it><b>%s</b></it>?</html>", repo.getPresentableName());
                int exitCode = HgUpdateCommand.showDiscardChangesConfirmation(project, message);
                if (exitCode == Messages.OK) {
                    //discard all changes for this repository//
                    HgUpdateCommand updateCommand = new HgUpdateCommand(project, repo);
                    updateCommand.setClean(true);
                    updateCommand.setRevision(".");
                    updateCommand.execute();
                }
                break;
            }
            new HgResolveCommand(project).markResolved(repo, files);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) HgResolveCommand(org.zmlx.hg4idea.command.HgResolveCommand) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand) HgRevertCommand(org.zmlx.hg4idea.command.HgRevertCommand) HgUpdateCommand(org.zmlx.hg4idea.command.HgUpdateCommand) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 14 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgDiffProvider method createFileContent.

public ContentRevision createFileContent(VcsRevisionNumber revisionNumber, VirtualFile file) {
    if (file == null) {
        return null;
    }
    VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
    if (vcsRoot == null) {
        return null;
    }
    HgRevisionNumber hgRevisionNumber = (HgRevisionNumber) revisionNumber;
    if (hgRevisionNumber.isWorkingVersion()) {
        throw new IllegalStateException("Should not compare against working copy");
    }
    HgFile hgFile = new HgFile(vcsRoot, HgUtil.getOriginalFileName(VcsUtil.getFilePath(file), ChangeListManager.getInstance(project)));
    return HgContentRevision.create(project, hgFile, hgRevisionNumber);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 15 with HgRevisionNumber

use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.

the class HgDiffProvider method getLastRevision.

public ItemLatestState getLastRevision(FilePath filePath) {
    VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, filePath);
    if (vcsRoot == null) {
        return null;
    }
    HgWorkingCopyRevisionsCommand command = new HgWorkingCopyRevisionsCommand(project);
    HgRevisionNumber currentRevision = command.identify(vcsRoot).getFirst();
    if (currentRevision == null) {
        return null;
    }
    boolean fileExists = filePath.getIOFile().exists();
    if (currentRevision.isWorkingVersion()) {
        return new ItemLatestState(command.firstParent(vcsRoot), fileExists, true);
    }
    return new ItemLatestState(currentRevision, fileExists, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState) HgWorkingCopyRevisionsCommand(org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)

Aggregations

HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Test (org.testng.annotations.Test)8 HgFile (org.zmlx.hg4idea.HgFile)6 VcsException (com.intellij.openapi.vcs.VcsException)5 NotNull (org.jetbrains.annotations.NotNull)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)4 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)4 FilePath (com.intellij.openapi.vcs.FilePath)3 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)3 Change (com.intellij.openapi.vcs.changes.Change)2 ItemLatestState (com.intellij.openapi.vcs.diff.ItemLatestState)2 Nullable (org.jetbrains.annotations.Nullable)2 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)1 MergeData (com.intellij.openapi.vcs.merge.MergeData)1 SmartList (com.intellij.util.SmartList)1 Hash (com.intellij.vcs.log.Hash)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1