use of org.zmlx.hg4idea.command.HgLogCommand in project intellij-community by JetBrains.
the class HgCachingCommittedChangesProvider method getCommittedChangesForRevision.
@Nullable
public CommittedChangeList getCommittedChangesForRevision(@Nullable RepositoryLocation repositoryLocation, String revision) {
if (repositoryLocation == null) {
return null;
}
VirtualFile root = ((HgRepositoryLocation) repositoryLocation).getRoot();
HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
HgLogCommand hgLogCommand = new HgLogCommand(project);
hgLogCommand.setLogFile(false);
hgLogCommand.setFollowCopies(true);
List<String> args = new ArrayList<>();
args.add("--rev");
args.add(revision);
final List<HgFileRevision> revisions;
revisions = hgLogCommand.execute(hgFile, 1, true, args);
if (ContainerUtil.isEmpty(revisions)) {
return null;
}
HgFileRevision localRevision = revisions.get(0);
HgRevisionNumber vcsRevisionNumber = localRevision.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 : localRevision.getModifiedFiles()) {
changes.add(createChange(root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
}
for (String file : localRevision.getAddedFiles()) {
changes.add(createChange(root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
}
for (String file : localRevision.getDeletedFiles()) {
changes.add(createChange(root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
}
for (Map.Entry<String, String> copiedFile : localRevision.getMovedFiles().entrySet()) {
changes.add(createChange(root, copiedFile.getKey(), firstParent, copiedFile.getValue(), vcsRevisionNumber, HgChangeProvider.RENAMED));
}
return new HgCommittedChangeList(myVcs, vcsRevisionNumber, localRevision.getBranchName(), localRevision.getCommitMessage(), localRevision.getAuthor(), localRevision.getRevisionDate(), changes);
}
use of org.zmlx.hg4idea.command.HgLogCommand in project intellij-community by JetBrains.
the class HgHistoryProvider method getHistoryForUncommittedRenamed.
/**
* Workaround for getting follow file history in case of uncommitted move/rename change
*/
private static List<HgFileRevision> getHistoryForUncommittedRenamed(@NotNull FilePath originalHgFilePath, @NotNull VirtualFile vcsRoot, @NotNull Project project, int limit) {
HgFile originalHgFile = new HgFile(vcsRoot, originalHgFilePath);
final HgLogCommand logCommand = new HgLogCommand(project);
logCommand.setIncludeRemoved(true);
final HgVersion version = logCommand.getVersion();
String[] templates = HgBaseLogParser.constructFullTemplateArgument(false, version);
String template = HgChangesetUtil.makeTemplate(templates);
List<String> argsForCmd = ContainerUtil.newArrayList();
String relativePath = originalHgFile.getRelativePath();
argsForCmd.add("--rev");
argsForCmd.add(String.format("reverse(follow(%s))", relativePath != null ? "'" + FileUtil.toSystemIndependentName(relativePath) + "'" : ""));
HgCommandResult result = logCommand.execute(vcsRoot, template, limit, relativePath != null ? null : originalHgFile, argsForCmd);
return HgHistoryUtil.getCommitRecords(project, result, new HgFileRevisionLogParser(project, originalHgFile, version));
}
use of org.zmlx.hg4idea.command.HgLogCommand 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);
}
Aggregations