Search in sources :

Example 11 with HgFileRevision

use of org.zmlx.hg4idea.HgFileRevision 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 12 with HgFileRevision

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

the class HgCommitTest method testAmendCommit.

public void testAmendCommit() throws HgCommandException, VcsException {
    String changedCommit = "anotherCommit";
    HgLogCommand logCommand = new HgLogCommand(myProject);
    logCommand.setLogFile(false);
    HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(myRepository));
    List<HgFileRevision> revisions = logCommand.execute(hgFile, -1, false);
    HgRepository hgRepo = HgRepositoryImpl.getInstance(myRepository, myProject, myProject);
    HgCommitCommand commit = new HgCommitCommand(myProject, hgRepo, changedCommit, true);
    commit.executeInCurrentThread();
    List<HgFileRevision> revisionsAfterAmendCommit = logCommand.execute(hgFile, -1, false);
    assertTrue(revisions.size() == revisionsAfterAmendCommit.size());
    assertEquals(revisionsAfterAmendCommit.get(0).getCommitMessage(), changedCommit);
}
Also used : HgFile(org.zmlx.hg4idea.HgFile) HgCommitCommand(org.zmlx.hg4idea.command.HgCommitCommand) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) HgRepository(org.zmlx.hg4idea.repo.HgRepository) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Example 13 with HgFileRevision

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

the class HgGetDiffForDirTest method testDiffForDir.

public void testDiffForDir() {
    cd(myRepository);
    touch("A.txt", "dsfdfdsf");
    hg("add A.txt");
    touch("B.txt");
    hg("add B.txt");
    hg("commit -m 2files_added");
    File dirFile = mkdir("dir");
    cd("dir");
    touch("C.txt");
    touch("D.txt");
    hg("add C.txt");
    hg("add D.txt");
    hg("commit -m createDir");
    String[] hash1 = hg("log -l 1 --template=" + SHORT_TEMPLATE_REVISION).split(":");
    HgRevisionNumber r1number = HgRevisionNumber.getInstance(hash1[0], hash1[1]);
    HgFileRevision rev1 = new HgFileRevision(myProject, new HgFile(myRepository, dirFile), r1number, "", null, "", "", null, null, null, null);
    echo("C.txt", "aaaa");
    echo("D.txt", "dddd");
    hg("commit -m modifyDir");
    String[] hash2 = hg("log -l 1 --template=" + SHORT_TEMPLATE_REVISION).split(":");
    HgRevisionNumber r2number = HgRevisionNumber.getInstance(hash2[0], hash2[1]);
    HgFileRevision rev2 = new HgFileRevision(myProject, new HgFile(myRepository, dirFile), r2number, "", null, "", "", null, null, null, null);
    FilePath dirPath = VcsUtil.getFilePath(dirFile, true);
    List<Change> changes = HgUtil.getDiff(myProject, myRepository, dirPath, rev1.getRevisionNumber(), rev2.getRevisionNumber());
    assertEquals(2, changes.size());
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) HgFileRevision(org.zmlx.hg4idea.HgFileRevision) Change(com.intellij.openapi.vcs.changes.Change) HgFile(org.zmlx.hg4idea.HgFile) File(java.io.File)

Aggregations

HgFileRevision (org.zmlx.hg4idea.HgFileRevision)13 HgFile (org.zmlx.hg4idea.HgFile)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)7 File (java.io.File)5 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)3 FilePath (com.intellij.openapi.vcs.FilePath)2 VcsException (com.intellij.openapi.vcs.VcsException)2 NotNull (org.jetbrains.annotations.NotNull)2 HgAnnotateCommand (org.zmlx.hg4idea.command.HgAnnotateCommand)2 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)2 HgRepository (org.zmlx.hg4idea.repo.HgRepository)2 Change (com.intellij.openapi.vcs.changes.Change)1 Charset (java.nio.charset.Charset)1 Nullable (org.jetbrains.annotations.Nullable)1 Test (org.testng.annotations.Test)1 HgWorkingCopyRevisionsCommand (org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand)1