Search in sources :

Example 6 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 7 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 8 with HgRevisionNumber

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

the class HgCompareWithBranchAction method getDiffChanges.

@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
    HgRepository repository = getRepositoryManager(project).getRepositoryForFile(file);
    if (repository == null) {
        throw new VcsException("Couldn't find repository for " + file.getName());
    }
    final FilePath filePath = VcsUtil.getFilePath(file);
    final VirtualFile repositoryRoot = repository.getRoot();
    final HgFile hgFile = new HgFile(repositoryRoot, filePath);
    Hash refHashToCompare = detectActiveHashByName(repository, branchToCompare);
    if (refHashToCompare == null) {
        throw new VcsException(String.format("Couldn't detect commit related to %s name for %s.", branchToCompare, file));
    }
    final HgRevisionNumber compareWithRevisionNumber = HgRevisionNumber.getInstance(branchToCompare, refHashToCompare.toString());
    List<Change> changes = HgUtil.getDiff(project, repositoryRoot, filePath, compareWithRevisionNumber, null);
    if (changes.isEmpty() && !existInBranch(repository, filePath, compareWithRevisionNumber)) {
        throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
    }
    return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, HgContentRevision.create(project, hgFile, compareWithRevisionNumber)) : changes;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Change(com.intellij.openapi.vcs.changes.Change) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with HgRevisionNumber

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

the class HgUpdateTest method assertCurrentHeadIsMerge.

private void assertCurrentHeadIsMerge(HgRevisionNumber incomingHead, HgRevisionNumber headBeforeUpdate) {
    List<HgRevisionNumber> newHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread();
    assertEquals(newHeads.size(), 1, "After updating, there should be only one head because the remote heads should have been merged");
    HgRevisionNumber newHead = newHeads.get(0);
    HgParentsCommand parents = new HgParentsCommand(myProject);
    parents.setRevision(newHead);
    List<HgRevisionNumber> parentRevisions = parents.executeInCurrentThread(projectRepoVirtualFile);
    assertEquals(parentRevisions.size(), 2);
    assertTrue(parentRevisions.contains(incomingHead));
    assertTrue(parentRevisions.contains(headBeforeUpdate));
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber)

Example 10 with HgRevisionNumber

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

the class HgUpdateTest method updateKeepsWorkingAfterPull.

@Test
public void updateKeepsWorkingAfterPull() throws Exception {
    changeFile_A_AndCommitInRemoteRepository();
    //do a simple pull without an update
    HgPullCommand pull = new HgPullCommand(myProject, projectRepoVirtualFile);
    pull.setSource(HgUtil.getRepositoryDefaultPath(myProject, projectRepoVirtualFile));
    pull.executeInCurrentThread();
    assertEquals(determineNumberOfIncomingChanges(projectRepo), 0, "The update operation should have pulled the incoming changes from the default repository.");
    updateThroughPlugin();
    HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(projectRepoVirtualFile);
    assertEquals(parentRevision.getRevision(), "1", "The working directory should have been updated to the latest version");
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) Test(org.testng.annotations.Test)

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