use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgDiffProvider method getLastRevision.
public ItemLatestState getLastRevision(VirtualFile file) {
VirtualFile vcsRoot = VcsUtil.getVcsRootFor(project, file);
if (vcsRoot == null) {
return null;
}
HgRevisionNumber revision = (HgRevisionNumber) getCurrentRevision(file);
if (revision == null) {
return null;
}
return new ItemLatestState(revision, file.exists(), true);
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgBaseLogParser method convert.
@Nullable
public CommitT convert(@NotNull String line) {
// we need to get all attributes, include empty trailing strings, so use non-positive limit as second argument
List<String> attributes = StringUtil.split(line, HgChangesetUtil.ITEM_SEPARATOR, true, false);
int numAttributes = attributes.size();
if (numAttributes <= AUTHOR_INDEX) {
LOG.info("Hg Log Command was cancelled or failed");
return null;
}
try {
String revisionString = attributes.get(REVISION_INDEX);
String changeset = attributes.get(CHANGESET_INDEX);
String parentsString = attributes.get(PARENTS_INDEX);
SmartList<HgRevisionNumber> parents = parseParentRevisions(parentsString, revisionString);
String unixTimeStamp = ContainerUtil.getFirstItem(StringUtil.split(attributes.get(DATE_INDEX), " "));
if (unixTimeStamp == null) {
LOG.warn("Error parsing date in line " + line);
return null;
}
Date revisionDate = new Date(Long.parseLong(unixTimeStamp.trim()) * 1000);
Couple<String> authorAndEmail = HgUtil.parseUserNameAndEmail(attributes.get(AUTHOR_INDEX));
return convertDetails(revisionString, changeset, parents, revisionDate, authorAndEmail.first, authorAndEmail.second, attributes);
} catch (NumberFormatException e) {
LOG.warn("Error parsing rev in line " + line);
return null;
}
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgFileRevisionLogParser method convertDetails.
@Override
@Nullable
protected HgFileRevision convertDetails(@NotNull String rev, @NotNull String changeset, @NotNull SmartList<HgRevisionNumber> parents, @NotNull Date revisionDate, @NotNull String author, @NotNull String email, @NotNull List<String> attributes) {
int numAttributes = attributes.size();
String commitMessage = parseAdditionalStringAttribute(attributes, MESSAGE_INDEX);
String branchName = parseAdditionalStringAttribute(attributes, BRANCH_INDEX);
final HgRevisionNumber vcsRevisionNumber = new HgRevisionNumber(rev, changeset, author, email, commitMessage, parents);
Set<String> filesAdded = Collections.emptySet();
Set<String> filesModified = Collections.emptySet();
Set<String> filesDeleted = Collections.emptySet();
Map<String, String> copies = Collections.emptyMap();
boolean shouldParseOldTemplate = !myVersion.isBuiltInFunctionSupported();
String separator = shouldParseOldTemplate ? " " : HgChangesetUtil.FILE_SEPARATOR;
// deleted or copied files, then we won't get any attributes for them...
if (numAttributes > FILES_ADDED_INDEX) {
filesAdded = parseFileList(attributes.get(FILES_ADDED_INDEX), separator);
if (numAttributes > FILES_MODIFIED_INDEX) {
filesModified = parseFileList(attributes.get(FILES_MODIFIED_INDEX), separator);
if (numAttributes > FILES_DELETED_INDEX) {
filesDeleted = parseFileList(attributes.get(FILES_DELETED_INDEX), separator);
if (numAttributes > FILES_COPIED_INDEX) {
copies = shouldParseOldTemplate ? parseCopiesFileListAsOldVersion(attributes.get(FILES_COPIED_INDEX)) : parseCopiesFileList(attributes.get(FILES_COPIED_INDEX));
// Only keep renames, i.e. copies where the source file is also deleted.
Iterator<String> keys = copies.keySet().iterator();
while (keys.hasNext()) {
String s = keys.next();
if (filesAdded.contains(copies.get(s)) && filesDeleted.contains(s)) {
filesAdded.remove(copies.get(s));
filesDeleted.remove(s);
} else if (!filesDeleted.contains(s)) {
keys.remove();
}
}
}
}
}
}
return new HgFileRevision(myProject, myHgFile, vcsRevisionNumber, branchName, revisionDate, vcsRevisionNumber.getAuthor(), commitMessage, filesModified, filesAdded, filesDeleted, copies);
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgUpdateTest method updateShouldNotMergeTwoHeadsComingFromRemote.
@Test
public void updateShouldNotMergeTwoHeadsComingFromRemote() throws Exception {
String originalParent = runHg(remoteRepo, "parents", "--template", "{rev}\n").getStdout().trim();
changeFile_A_AndCommitInRemoteRepository();
runHg(remoteRepo, "update", "--clean", originalParent);
File file = fillFile(remoteRepo, new String[] { "com", "b.txt" }, "second file");
runHg(remoteRepo, "add", file.getPath());
runHg(remoteRepo, "commit", "-m", "adding second file");
assertUpdateThroughPluginFails();
List<HgRevisionNumber> branchHeads = new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread();
assertEquals(branchHeads.size(), 2);
}
use of org.zmlx.hg4idea.HgRevisionNumber in project intellij-community by JetBrains.
the class HgUpdateTest method updateShouldNotMergeWithNonCommittedChanges.
@Test
public void updateShouldNotMergeWithNonCommittedChanges() throws Exception {
changeFile_A_AndCommitInRemoteRepository();
//generate some extra local history
createAndCommitNewFileInLocalRepository();
HgRevisionNumber parentBeforeUpdate = new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).get(0);
VcsTestUtil.editFileInCommand(myProject, projectRepoVirtualFile.findFileByRelativePath("com/a.txt"), "modified file contents");
assertUpdateThroughPluginFails();
assertEquals(new HgHeadsCommand(myProject, projectRepoVirtualFile).executeInCurrentThread().size(), 2, "Remote head should have been pulled in");
assertEquals(new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).size(), 1, "No merge should have been attempted");
assertEquals(new HgWorkingCopyRevisionsCommand(myProject).parents(projectRepoVirtualFile).get(0), parentBeforeUpdate, "No merge should have been attempted");
}
Aggregations