use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgAnnotateCommand method parse.
private static List<HgAnnotationLine> parse(List<String> outputLines) {
List<HgAnnotationLine> annotations = new ArrayList<>(outputLines.size());
for (String line : outputLines) {
Matcher matcher = LINE_PATTERN.matcher(line);
if (matcher.matches()) {
String user = matcher.group(USER_GROUP).trim();
HgRevisionNumber rev = HgRevisionNumber.getInstance(matcher.group(REVISION_GROUP), matcher.group(CHANGESET_GROUP));
String dateGroup = matcher.group(DATE_GROUP).trim();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
String date = "";
try {
date = DateFormatUtil.formatPrettyDate(dateFormat.parse(dateGroup));
} catch (ParseException e) {
LOG.error("Couldn't parse annotation date ", e);
}
Integer lineNumber = Integer.valueOf(matcher.group(LINE_NUMBER_GROUP));
String content = matcher.group(CONTENT_GROUP);
HgAnnotationLine annotationLine = new HgAnnotationLine(user, rev, date, lineNumber, content);
annotations.add(annotationLine);
}
}
return annotations;
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgChangesetsCommand method getRevisions.
protected List<HgRevisionNumber> getRevisions(VirtualFile repo) {
List<String> args = new ArrayList<>(Arrays.asList("--template", HgChangesetUtil.makeTemplate("{rev}", "{node}", "{author}", "{desc|firstline}"), "--quiet"));
addArguments(args);
HgCommandResult result = executeCommandInCurrentThread(repo, args);
if (result == null) {
return Collections.emptyList();
}
String output = result.getRawOutput();
if (StringUtil.isEmpty(output)) {
return Collections.emptyList();
}
String[] changesets = output.split(HgChangesetUtil.CHANGESET_SEPARATOR);
List<HgRevisionNumber> revisions = new ArrayList<>(changesets.length);
for (String changeset : changesets) {
List<String> parts = StringUtil.split(changeset, HgChangesetUtil.ITEM_SEPARATOR);
if (parts.size() >= 3) {
//support zero commit message
revisions.add(HgRevisionNumber.getInstance(parts.get(0), parts.get(1), parts.get(2), parts.size() > 3 ? parts.get(3) : ""));
} else {
LOG.warn("Could not parse changeset [" + changeset + "]");
}
}
return revisions;
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgCompareWithBranchAction method getDiffChanges.
@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
HgRepository repository = getRepositoryManager(project).getRepositoryForFile(file);
if (repository == null) {
throw new VcsException("Couldn't find repository for " + file.getName());
}
final FilePath filePath = VcsUtil.getFilePath(file);
final VirtualFile repositoryRoot = repository.getRoot();
final HgFile hgFile = new HgFile(repositoryRoot, filePath);
Hash refHashToCompare = detectActiveHashByName(repository, branchToCompare);
if (refHashToCompare == null) {
throw new VcsException(String.format("Couldn't detect commit related to %s name for %s.", branchToCompare, file));
}
final HgRevisionNumber compareWithRevisionNumber = HgRevisionNumber.getInstance(branchToCompare, refHashToCompare.toString());
List<Change> changes = HgUtil.getDiff(project, repositoryRoot, filePath, compareWithRevisionNumber, null);
if (changes.isEmpty() && !existInBranch(repository, filePath, compareWithRevisionNumber)) {
throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
}
return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, HgContentRevision.create(project, hgFile, compareWithRevisionNumber)) : changes;
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgUpdateTest method assertCurrentHeadIsMerge.
private void assertCurrentHeadIsMerge(HgRevisionNumber incomingHead, HgRevisionNumber headBeforeUpdate) {
List<HgRevisionNumber> newHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread();
assertEquals(newHeads.size(), 1, "After updating, there should be only one head because the remote heads should have been merged");
HgRevisionNumber newHead = newHeads.get(0);
HgParentsCommand parents = new HgParentsCommand(myProject);
parents.setRevision(newHead);
List<HgRevisionNumber> parentRevisions = parents.executeInCurrentThread(projectRepoVirtualFile);
assertEquals(parentRevisions.size(), 2);
assertTrue(parentRevisions.contains(incomingHead));
assertTrue(parentRevisions.contains(headBeforeUpdate));
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgUpdateTest method updateKeepsWorkingAfterPull.
@Test
public void updateKeepsWorkingAfterPull() throws Exception {
changeFile_A_AndCommitInRemoteRepository();
//do a simple pull without an update
HgPullCommand pull = new HgPullCommand(myProject, projectRepoVirtualFile);
pull.setSource(HgUtil.getRepositoryDefaultPath(myProject, projectRepoVirtualFile));
pull.executeInCurrentThread();
assertEquals(determineNumberOfIncomingChanges(projectRepo), 0, "The update operation should have pulled the incoming changes from the default repository.");
updateThroughPlugin();
HgRevisionNumber parentRevision = new HgWorkingCopyRevisionsCommand(myProject).firstParent(projectRepoVirtualFile);
assertEquals(parentRevision.getRevision(), "1", "The working directory should have been updated to the latest version");
}
Aggregations