Search in sources :

Example 6 with HgLogCommand

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

the class HgLogTest method testCommitMessagesWithMultipleLines.

@Test
public void testCommitMessagesWithMultipleLines() throws Exception {
    fillFile(myProjectDir, new String[] { "file.txt" }, "initial contents");
    runHgOnProjectRepo("add", ".");
    runHgOnProjectRepo("commit", "-m", "initial\ncontents");
    fillFile(myProjectDir, new String[] { "file.txt" }, "updated contents");
    runHgOnProjectRepo("commit", "-m", "updated\ncontents");
    List<HgFileRevision> fileLog = new HgLogCommand(myProject).execute(getHgFile("file.txt"), 10, false);
    assertEquals(fileLog.size(), 2, "The file history should show two entries");
}
Also used : HgFileRevision(org.zmlx.hg4idea.HgFileRevision) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand) Test(org.testng.annotations.Test)

Example 7 with HgLogCommand

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

the class HgCachingCommittedChangesProvider method getCommittedChanges.

public List<CommittedChangeList> getCommittedChanges(ChangeBrowserSettings changeBrowserSettings, RepositoryLocation repositoryLocation, int maxCount) throws VcsException {
    VirtualFile root = ((HgRepositoryLocation) repositoryLocation).getRoot();
    HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
    List<CommittedChangeList> result = new LinkedList<>();
    HgLogCommand hgLogCommand = new HgLogCommand(project);
    hgLogCommand.setLogFile(false);
    List<String> args = null;
    if (changeBrowserSettings != null) {
        HgLogArgsBuilder argsBuilder = new HgLogArgsBuilder(changeBrowserSettings);
        args = argsBuilder.getLogArgs();
        if (args.isEmpty()) {
            maxCount = maxCount == 0 ? VcsConfiguration.getInstance(project).MAXIMUM_HISTORY_ROWS : maxCount;
        }
    }
    final List<HgFileRevision> localRevisions;
    localRevisions = hgLogCommand.execute(hgFile, maxCount == 0 ? -1 : maxCount, true, args);
    Collections.reverse(localRevisions);
    for (HgFileRevision revision : localRevisions) {
        HgRevisionNumber vcsRevisionNumber = revision.getRevisionNumber();
        List<HgRevisionNumber> parents = vcsRevisionNumber.getParents();
        // can have no parents if it is a root
        HgRevisionNumber firstParent = parents.isEmpty() ? null : parents.get(0);
        List<Change> changes = new ArrayList<>();
        for (String file : revision.getModifiedFiles()) {
            changes.add(createChange(root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
        }
        for (String file : revision.getAddedFiles()) {
            changes.add(createChange(root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
        }
        for (String file : revision.getDeletedFiles()) {
            changes.add(createChange(root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
        }
        for (Map.Entry<String, String> copiedFile : revision.getMovedFiles().entrySet()) {
            changes.add(createChange(root, copiedFile.getKey(), firstParent, copiedFile.getValue(), vcsRevisionNumber, HgChangeProvider.RENAMED));
        }
        result.add(new HgCommittedChangeList(myVcs, vcsRevisionNumber, revision.getBranchName(), revision.getCommitMessage(), revision.getAuthor(), revision.getRevisionDate(), changes));
    }
    Collections.reverse(result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Example 8 with HgLogCommand

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

the class HgHistoryUtil method getLogResult.

@Nullable
public static HgCommandResult getLogResult(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull HgVersion version, int limit, @NotNull List<String> parameters, @NotNull String template) {
    HgFile originalHgFile = getOriginalHgFile(project, root);
    HgLogCommand hgLogCommand = new HgLogCommand(project);
    List<String> args = new ArrayList<>(parameters);
    hgLogCommand.setLogFile(false);
    if (!version.isParentRevisionTemplateSupported()) {
        args.add("--debug");
    }
    return hgLogCommand.execute(root, template, limit, originalHgFile, args);
}
Also used : HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with HgLogCommand

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

the class HgHistoryUtil method getDescendingHeadsOfBranches.

@NotNull
public static Collection<String> getDescendingHeadsOfBranches(@NotNull Project project, @NotNull VirtualFile root, @NotNull Hash hash) throws VcsException {
    //hg log -r "descendants(659db54c1b6865c97c4497fa867194bcd759ca76) and head()" --template "{branch}{bookmarks}"
    Set<String> branchHeads = new HashSet<>();
    List<String> params = new ArrayList<>();
    params.add("-r");
    params.add("descendants(" + hash.asString() + ") and head()");
    HgLogCommand hgLogCommand = new HgLogCommand(project);
    hgLogCommand.setLogFile(false);
    String template = HgChangesetUtil.makeTemplate("{branch}", "{bookmarks}");
    HgCommandResult logResult = hgLogCommand.execute(root, template, -1, null, params);
    if (logResult == null || logResult.getExitValue() != 0) {
        throw new VcsException("Couldn't get commit details: log command execution error.");
    }
    String output = logResult.getRawOutput();
    List<String> changeSets = StringUtil.split(output, HgChangesetUtil.CHANGESET_SEPARATOR);
    for (String line : changeSets) {
        List<String> attributes = StringUtil.split(line, HgChangesetUtil.ITEM_SEPARATOR);
        branchHeads.addAll(attributes);
    }
    return branchHeads;
}
Also used : HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) VcsException(com.intellij.openapi.vcs.VcsException) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with HgLogCommand

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

the class HgHistoryProvider method getHistory.

public static List<HgFileRevision> getHistory(@NotNull FilePath filePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, @Nullable HgRevisionNumber revisionNumber, int limit) {
    /*  The standard way to get history following renames is to call hg log --follow. However:
  1. It is broken in case of uncommitted rename (i.e. if the file is currently renamed in the working dir):
    in this case we use a special python template "follow(path)" which handles this case.
  2. We don't use this python "follow(path)" function for all cases, because it is fully supported only since hg 2.6,
   and it is a bit slower and possibly less reliable than plain --follow parameter.
  3. It doesn't work with "-r": in this case --follow is simply ignored (hg commit 24208:8b4b9ee6001a).
   As a workaround we could use the same follow(path) python, but this function requires current name of the file,
    which is unknown in case of "-r", and identifying it would be very slow.

    As a result we don't follow renames in annotate called from diff or from an old revision, which we can survive.
*/
    FilePath originalFilePath = HgUtil.getOriginalFileName(filePath, ChangeListManager.getInstance(project));
    if (revisionNumber == null && !filePath.isDirectory() && !filePath.equals(originalFilePath)) {
        // uncommitted renames detected
        return getHistoryForUncommittedRenamed(originalFilePath, vcsRoot, project, limit);
    }
    final HgLogCommand logCommand = new HgLogCommand(project);
    logCommand.setFollowCopies(!filePath.isDirectory());
    logCommand.setIncludeRemoved(true);
    List<String> args = new ArrayList<>();
    if (revisionNumber != null) {
        args.add("--rev");
        args.add("reverse(0::" + revisionNumber.getChangeset() + ")");
    }
    return logCommand.execute(new HgFile(vcsRoot, filePath), limit, false, args);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) HgFile(org.zmlx.hg4idea.HgFile) ArrayList(java.util.ArrayList) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Aggregations

HgLogCommand (org.zmlx.hg4idea.command.HgLogCommand)13 HgFile (org.zmlx.hg4idea.HgFile)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 HgFileRevision (org.zmlx.hg4idea.HgFileRevision)7 File (java.io.File)3 Change (com.intellij.openapi.vcs.changes.Change)2 Nullable (org.jetbrains.annotations.Nullable)2 HgCommitCommand (org.zmlx.hg4idea.command.HgCommitCommand)2 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)2 HgRepository (org.zmlx.hg4idea.repo.HgRepository)2 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Test (org.testng.annotations.Test)1 HgFileRevisionLogParser (org.zmlx.hg4idea.log.HgFileRevisionLogParser)1 HgVersion (org.zmlx.hg4idea.util.HgVersion)1