use of org.zmlx.hg4idea.util.HgVersion in project intellij-community by JetBrains.
the class HgOutgoingCommitsProvider method getOutgoingCommits.
@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull final HgRepository repository, @NotNull final PushSpec<HgPushSource, HgTarget> pushSpec, boolean initial) {
final Project project = repository.getProject();
HgVcs hgvcs = HgVcs.getInstance(project);
assert hgvcs != null;
final HgVersion version = hgvcs.getVersion();
String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
HgOutgoingCommand hgOutgoingCommand = new HgOutgoingCommand(project);
HgTarget hgTarget = pushSpec.getTarget();
List<VcsError> errors = new ArrayList<>();
if (StringUtil.isEmptyOrSpaces(hgTarget.myTarget)) {
errors.add(new VcsError("Hg push path could not be empty."));
return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
}
HgCommandResult result = hgOutgoingCommand.execute(repository.getRoot(), HgChangesetUtil.makeTemplate(templates), pushSpec.getSource().getPresentation(), hgTarget.myTarget, initial);
if (result == null) {
errors.add(new VcsError("Couldn't execute hg outgoing command for " + repository));
return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), errors);
}
List<String> resultErrors = result.getErrorLines();
if (resultErrors != null && !resultErrors.isEmpty() && result.getExitValue() != 0) {
for (String error : resultErrors) {
if (HgErrorUtil.isAbortLine(error)) {
if (HgErrorUtil.isAuthorizationError(error)) {
VcsError authorizationError = new VcsError(error + "<a href='authenticate'>" + LOGIN_AND_REFRESH_LINK + "</a>", new VcsErrorHandler() {
public void handleError(@NotNull CommitLoader commitLoader) {
commitLoader.reloadCommits();
}
});
errors.add(authorizationError);
} else {
errors.add(new VcsError(error));
}
}
}
LOG.warn(resultErrors.toString());
}
return new OutgoingResult(HgHistoryUtil.createFullCommitsFromResult(project, repository.getRoot(), result, version, true), errors);
}
use of org.zmlx.hg4idea.util.HgVersion in project intellij-community by JetBrains.
the class HgHistoryUtil method readMiniDetails.
@NotNull
public static List<? extends VcsShortCommitDetails> readMiniDetails(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull List<String> hashes) throws VcsException {
final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
if (factory == null) {
return Collections.emptyList();
}
HgVcs hgvcs = HgVcs.getInstance(project);
assert hgvcs != null;
final HgVersion version = hgvcs.getVersion();
List<String> templateList = HgBaseLogParser.constructDefaultTemplate(version);
templateList.add("{desc}");
final String[] templates = ArrayUtil.toStringArray(templateList);
return VcsFileUtil.foreachChunk(prepareHashes(hashes), 2, strings -> {
HgCommandResult logResult = getLogResult(project, root, version, -1, strings, HgChangesetUtil.makeTemplate(templates));
return getCommitRecords(project, logResult, new HgBaseLogParser<VcsShortCommitDetails>() {
@Override
protected VcsShortCommitDetails convertDetails(@NotNull String rev, @NotNull String changeset, @NotNull SmartList<HgRevisionNumber> parents, @NotNull Date revisionDate, @NotNull String author, @NotNull String email, @NotNull List<String> attributes) {
String message = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
String subject = extractSubject(message);
List<Hash> parentsHash = new SmartList<>();
for (HgRevisionNumber parent : parents) {
parentsHash.add(factory.createHash(parent.getChangeset()));
}
return factory.createShortDetails(factory.createHash(changeset), parentsHash, revisionDate.getTime(), root, subject, author, email, author, email, revisionDate.getTime());
}
});
});
}
use of org.zmlx.hg4idea.util.HgVersion in project intellij-community by JetBrains.
the class HgHistoryUtil method loadMetadata.
@NotNull
public static List<VcsCommitMetadata> loadMetadata(@NotNull final Project project, @NotNull final VirtualFile root, int limit, @NotNull List<String> parameters) throws VcsException {
final VcsLogObjectsFactory factory = getObjectsFactoryWithDisposeCheck(project);
if (factory == null) {
return Collections.emptyList();
}
HgVcs hgvcs = HgVcs.getInstance(project);
assert hgvcs != null;
HgVersion version = hgvcs.getVersion();
List<String> templateList = HgBaseLogParser.constructDefaultTemplate(version);
templateList.add("{desc}");
String[] templates = ArrayUtil.toStringArray(templateList);
HgCommandResult result = getLogResult(project, root, version, limit, parameters, HgChangesetUtil.makeTemplate(templates));
HgBaseLogParser<VcsCommitMetadata> baseParser = new HgBaseLogParser<VcsCommitMetadata>() {
@Override
protected VcsCommitMetadata convertDetails(@NotNull String rev, @NotNull String changeset, @NotNull SmartList<HgRevisionNumber> parents, @NotNull Date revisionDate, @NotNull String author, @NotNull String email, @NotNull List<String> attributes) {
String message = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
String subject = extractSubject(message);
List<Hash> parentsHash = new SmartList<>();
for (HgRevisionNumber parent : parents) {
parentsHash.add(factory.createHash(parent.getChangeset()));
}
return factory.createCommitMetadata(factory.createHash(changeset), parentsHash, revisionDate.getTime(), root, subject, author, email, message, author, email, revisionDate.getTime());
}
};
return getCommitRecords(project, result, baseParser);
}
use of org.zmlx.hg4idea.util.HgVersion in project intellij-community by JetBrains.
the class HgHistoryUtil method history.
/**
* <p>Get & parse hg log detailed output with commits, their parents and their changes.
* For null destination return log command result</p>
* <p/>
* <p>Warning: this is method is efficient by speed, but don't query too much, because the whole log output is retrieved at once,
* and it can occupy too much memory. The estimate is ~600Kb for 1000 commits.</p>
*/
@NotNull
public static List<? extends VcsFullCommitDetails> history(@NotNull final Project project, @NotNull final VirtualFile root, final int limit, @NotNull List<String> hashParameters, final boolean silent) throws VcsException {
HgVcs hgvcs = HgVcs.getInstance(project);
assert hgvcs != null;
final HgVersion version = hgvcs.getVersion();
final String[] templates = HgBaseLogParser.constructFullTemplateArgument(true, version);
return VcsFileUtil.foreachChunk(hashParameters, 2, strings -> {
HgCommandResult logResult = getLogResult(project, root, version, limit, strings, HgChangesetUtil.makeTemplate(templates));
if (logResult == null)
return Collections.emptyList();
if (!logResult.getErrorLines().isEmpty())
throw new VcsException(logResult.getRawError());
return createFullCommitsFromResult(project, root, logResult, version, silent);
});
}
use of org.zmlx.hg4idea.util.HgVersion 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));
}
Aggregations