use of org.zmlx.hg4idea.HgFileRevision 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.HgFileRevision 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);
}
use of org.zmlx.hg4idea.HgFileRevision in project intellij-community by JetBrains.
the class HgGetDiffForDirTest method testDiffForDir.
public void testDiffForDir() {
cd(myRepository);
touch("A.txt", "dsfdfdsf");
hg("add A.txt");
touch("B.txt");
hg("add B.txt");
hg("commit -m 2files_added");
File dirFile = mkdir("dir");
cd("dir");
touch("C.txt");
touch("D.txt");
hg("add C.txt");
hg("add D.txt");
hg("commit -m createDir");
String[] hash1 = hg("log -l 1 --template=" + SHORT_TEMPLATE_REVISION).split(":");
HgRevisionNumber r1number = HgRevisionNumber.getInstance(hash1[0], hash1[1]);
HgFileRevision rev1 = new HgFileRevision(myProject, new HgFile(myRepository, dirFile), r1number, "", null, "", "", null, null, null, null);
echo("C.txt", "aaaa");
echo("D.txt", "dddd");
hg("commit -m modifyDir");
String[] hash2 = hg("log -l 1 --template=" + SHORT_TEMPLATE_REVISION).split(":");
HgRevisionNumber r2number = HgRevisionNumber.getInstance(hash2[0], hash2[1]);
HgFileRevision rev2 = new HgFileRevision(myProject, new HgFile(myRepository, dirFile), r2number, "", null, "", "", null, null, null, null);
FilePath dirPath = VcsUtil.getFilePath(dirFile, true);
List<Change> changes = HgUtil.getDiff(myProject, myRepository, dirPath, rev1.getRevisionNumber(), rev2.getRevisionNumber());
assertEquals(2, changes.size());
}
Aggregations