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");
}
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;
}
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);
}
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;
}
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);
}
Aggregations