Search in sources :

Example 16 with HgRevisionNumber

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

the class HgDiffProvider method getLastRevision.

public ItemLatestState getLastRevision(VirtualFile file) {
    VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
    if (vcsRoot == null) {
        return null;
    }
    HgRevisionNumber revision = (HgRevisionNumber) getCurrentRevision(file);
    if (revision == null) {
        return null;
    }
    return new ItemLatestState(revision, file.exists(), true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState)

Example 17 with HgRevisionNumber

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

the class HgBaseLogParser method convert.

@Nullable
public CommitT convert(@NotNull String line) {
    // we need to get all attributes, include empty trailing strings, so use non-positive limit as second argument
    List<String> attributes = StringUtil.split(line, HgChangesetUtil.ITEM_SEPARATOR, true, false);
    int numAttributes = attributes.size();
    if (numAttributes <= AUTHOR_INDEX) {
        LOG.info("Hg Log Command was cancelled or failed");
        return null;
    }
    try {
        String revisionString = attributes.get(REVISION_INDEX);
        String changeset = attributes.get(CHANGESET_INDEX);
        String parentsString = attributes.get(PARENTS_INDEX);
        SmartList<HgRevisionNumber> parents = parseParentRevisions(parentsString, revisionString);
        String unixTimeStamp = ContainerUtil.getFirstItem(StringUtil.split(attributes.get(DATE_INDEX), " "));
        if (unixTimeStamp == null) {
            LOG.warn("Error parsing date in line " + line);
            return null;
        }
        Date revisionDate = new Date(Long.parseLong(unixTimeStamp.trim()) * 1000);
        Couple<String> authorAndEmail = HgUtil.parseUserNameAndEmail(attributes.get(AUTHOR_INDEX));
        return convertDetails(revisionString, changeset, parents, revisionDate, authorAndEmail.first, authorAndEmail.second, attributes);
    } catch (NumberFormatException e) {
        LOG.warn("Error parsing rev in line " + line);
        return null;
    }
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) Date(java.util.Date) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with HgRevisionNumber

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

the class HgFileRevisionLogParser method convertDetails.

@Override
@Nullable
protected HgFileRevision convertDetails(@NotNull String rev, @NotNull String changeset, @NotNull SmartList<HgRevisionNumber> parents, @NotNull Date revisionDate, @NotNull String author, @NotNull String email, @NotNull List<String> attributes) {
    int numAttributes = attributes.size();
    String commitMessage = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
    String branchName = parseAdditionalStringAttribute(attributes, BRANCH_INDEX);
    final HgRevisionNumber vcsRevisionNumber = new HgRevisionNumber(rev, changeset, author, email, commitMessage, parents);
    Set<String> filesAdded = Collections.emptySet();
    Set<String> filesModified = Collections.emptySet();
    Set<String> filesDeleted = Collections.emptySet();
    Map<String, String> copies = Collections.emptyMap();
    boolean shouldParseOldTemplate = !myVersion.isBuiltInFunctionSupported();
    String separator = shouldParseOldTemplate ? " " : HgChangesetUtil.FILE_SEPARATOR;
    //  deleted or copied files, then we won't get any attributes for them...
    if (numAttributes > FILES_ADDED_INDEX) {
        filesAdded = parseFileList(attributes.get(FILES_ADDED_INDEX), separator);
        if (numAttributes > FILES_MODIFIED_INDEX) {
            filesModified = parseFileList(attributes.get(FILES_MODIFIED_INDEX), separator);
            if (numAttributes > FILES_DELETED_INDEX) {
                filesDeleted = parseFileList(attributes.get(FILES_DELETED_INDEX), separator);
                if (numAttributes > FILES_COPIED_INDEX) {
                    copies = shouldParseOldTemplate ? parseCopiesFileListAsOldVersion(attributes.get(FILES_COPIED_INDEX)) : parseCopiesFileList(attributes.get(FILES_COPIED_INDEX));
                    // Only keep renames, i.e. copies where the source file is also deleted.
                    Iterator<String> keys = copies.keySet().iterator();
                    while (keys.hasNext()) {
                        String s = keys.next();
                        if (filesAdded.contains(copies.get(s)) && filesDeleted.contains(s)) {
                            filesAdded.remove(copies.get(s));
                            filesDeleted.remove(s);
                        } else if (!filesDeleted.contains(s)) {
                            keys.remove();
                        }
                    }
                }
            }
        }
    }
    return new HgFileRevision(myProject, myHgFile, vcsRevisionNumber, branchName, revisionDate, vcsRevisionNumber.getAuthor(), commitMessage, filesModified, filesAdded, filesDeleted, copies);
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with HgRevisionNumber

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

the class HgUpdateTest method updateShouldNotMergeTwoHeadsComingFromRemote.

@Test
public void updateShouldNotMergeTwoHeadsComingFromRemote() throws Exception {
    String originalParent = runHg(remoteRepo, "parents", "--template", "{rev}\n").getStdout().trim();
    changeFile_A_AndCommitInRemoteRepository();
    runHg(remoteRepo, "update", "--clean", originalParent);
    File file = fillFile(remoteRepo, new String[] { "com", "b.txt" }, "second file");
    runHg(remoteRepo, "add", file.getPath());
    runHg(remoteRepo, "commit", "-m", "adding second file");
    assertUpdateThroughPluginFails();
    List<HgRevisionNumber> branchHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread();
    assertEquals(branchHeads.size(), 2);
}
Also used : HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) HgFile(org.zmlx.hg4idea.HgFile) Test(org.testng.annotations.Test)

Example 20 with HgRevisionNumber

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

the class HgUpdateTest method updateShouldNotMergeWithNonCommittedChanges.

@Test
public void updateShouldNotMergeWithNonCommittedChanges() throws Exception {
    changeFile_A_AndCommitInRemoteRepository();
    //generate some extra local history
    createAndCommitNewFileInLocalRepository();
    HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).get(0);
    VcsTestUtil.editFileInCommand(myProject, projectRepoVirtualFile.findFileByRelativePath("com/a.txt"), "modified file contents");
    assertUpdateThroughPluginFails();
    assertEquals(new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread().size(), 2, "Remote head should have been pulled in");
    assertEquals(new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).size(), 1, "No merge should have been attempted");
    assertEquals(new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).get(0), parentBeforeUpdate, "No merge should have been attempted");
}
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