use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class TagsHelper method findVcsRoots.
public static Collection<FilePath> findVcsRoots(FilePath[] files, Project project) {
if (files.length == 0) {
return Collections.emptyList();
}
final Collection<FilePath> roots = new HashSet<>();
final Set<VirtualFile> seen = new HashSet<>();
for (FilePath filePath : files) {
final VirtualFile root = ProjectLevelVcsManager.getInstance(project).getVcsRootFor(filePath);
if (root == null || !seen.add(root)) {
continue;
}
roots.add(VcsContextFactory.SERVICE.getInstance().createFilePathOn(root));
}
return roots;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class UpdateOperation method fileIsUnderProject.
@Override
public boolean fileIsUnderProject(File file) {
final FilePath path = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
if (!super.fileIsUnderProject(file)) {
return false;
}
final AbstractVcs vcs = ApplicationManager.getApplication().runReadAction(new Computable<AbstractVcs>() {
@Nullable
public AbstractVcs compute() {
return myVcsManager.getVcsFor(path);
}
});
return vcs == myVcs;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class RTagOperation method createOn.
public static RTagOperation[] createOn(FilePath[] files, String tagName, boolean overrideExisting) {
Map<CvsEnvironment, List<File>> envToFiles = new HashMap<>();
for (FilePath file : files) {
CvsConnectionSettings cvsConnectionSettings = CvsUtil.getCvsConnectionSettings(file);
if (!envToFiles.containsKey(cvsConnectionSettings))
envToFiles.put(cvsConnectionSettings, new ArrayList<>());
envToFiles.get(cvsConnectionSettings).add(file.getIOFile());
}
ArrayList<RTagOperation> result = new ArrayList<>();
for (CvsEnvironment cvsEnvironment : envToFiles.keySet()) {
RTagOperation rTagOperation = new RTagOperation(cvsEnvironment, tagName, overrideExisting);
result.add(rTagOperation);
List<File> iofiles = envToFiles.get(cvsEnvironment);
for (File file : iofiles) {
rTagOperation.addFile(file);
}
}
return result.toArray(new RTagOperation[result.size()]);
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class CommandCvsHandler method createCommitHandler.
public static CvsHandler createCommitHandler(FilePath[] selectedFiles, String commitMessage, String title, boolean makeNewFilesReadOnly, Project project, final boolean tagFilesAfterCommit, final String tagName, @NotNull final List<File> dirsToPrune) {
final CommitFilesOperation operation = new CommitFilesOperation(commitMessage, makeNewFilesReadOnly);
if (selectedFiles != null) {
for (FilePath selectedFile : selectedFiles) {
operation.addFile(selectedFile.getIOFile());
}
}
if (!dirsToPrune.isEmpty()) {
operation.addFinishAction(() -> {
final IOFilesBasedDirectoryPruner pruner = new IOFilesBasedDirectoryPruner(null);
for (File dir : dirsToPrune) {
pruner.addFile(dir);
}
pruner.execute();
});
}
final CommandCvsHandler result = new CommandCvsHandler(title, operation, FileSetToBeUpdated.selectedFiles(selectedFiles));
if (tagFilesAfterCommit) {
result.addOperation(new TagOperation(selectedFiles, tagName, false, CvsConfiguration.getInstance(project).OVERRIDE_EXISTING_TAG_FOR_PROJECT));
}
return result;
}
use of com.intellij.openapi.vcs.FilePath in project intellij-community by JetBrains.
the class GitAnnotationProvider method parseAnnotations.
@NotNull
private GitFileAnnotation parseAnnotations(@Nullable VcsRevisionNumber revision, @NotNull VirtualFile file, @NotNull VirtualFile root, @NotNull String output) throws VcsException {
Interner<FilePath> pathInterner = new Interner<>();
try {
List<LineInfo> lines = new ArrayList<>();
HashMap<String, LineInfo> commits = new HashMap<>();
for (StringScanner s = new StringScanner(output); s.hasMoreData(); ) {
// parse header line
String commitHash = s.spaceToken();
if (commitHash.equals(GitRevisionNumber.NOT_COMMITTED_HASH)) {
commitHash = null;
}
// skip revision line number
s.spaceToken();
String s1 = s.spaceToken();
int lineNum = Integer.parseInt(s1);
s.nextLine();
// parse commit information
LineInfo commit = commits.get(commitHash);
if (commit != null || commitHash == null) {
while (s.hasMoreData() && !s.startsWith('\t')) {
s.nextLine();
}
} else {
Date committerDate = null;
FilePath filePath = null;
String subject = null;
String authorName = null;
String authorEmail = null;
String previousRevision = null;
FilePath previousFilePath = null;
while (s.hasMoreData() && !s.startsWith('\t')) {
String key = s.spaceToken();
String value = s.line();
if (SUBJECT_KEY.equals(key)) {
subject = value;
} else if (AUTHOR_KEY.equals(key)) {
authorName = value;
} else if (COMMITTER_TIME_KEY.equals(key)) {
committerDate = GitUtil.parseTimestamp(value);
} else if (FILENAME_KEY.equals(key)) {
filePath = VcsUtil.getFilePath(root, value);
} else if (AUTHOR_EMAIL_KEY.equals(key)) {
authorEmail = value;
if (authorEmail.startsWith("<") && authorEmail.endsWith(">")) {
authorEmail = authorEmail.substring(1, authorEmail.length() - 1);
}
} else if (PREVIOUS_KEY.equals(key)) {
int index = value.indexOf(' ');
if (index != -1) {
previousRevision = value.substring(0, index);
previousFilePath = VcsUtil.getFilePath(root, value.substring(index + 1, value.length()));
}
}
}
if (committerDate == null || filePath == null || authorName == null || authorEmail == null || subject == null) {
throw new VcsException("Output for line " + lineNum + " lacks necessary data");
}
GitRevisionNumber revisionNumber = new GitRevisionNumber(commitHash, committerDate);
VcsUser author = myUserRegistry.createUser(authorName, authorEmail);
GitRevisionNumber previousRevisionNumber = previousRevision != null ? new GitRevisionNumber(previousRevision) : null;
filePath = pathInterner.intern(filePath);
if (previousFilePath != null)
previousFilePath = pathInterner.intern(previousFilePath);
commit = new LineInfo(myProject, revisionNumber, filePath, committerDate, author, subject, previousRevisionNumber, previousFilePath);
commits.put(commitHash, commit);
}
s.nextLine();
int expectedLineNum = lines.size() + 1;
if (lineNum != expectedLineNum) {
throw new VcsException("Adding for info for line " + lineNum + " but we are expecting it to be for " + expectedLineNum);
}
lines.add(commit);
}
return new GitFileAnnotation(myProject, file, revision, lines);
} catch (Exception e) {
LOG.error("Couldn't parse annotation: " + e, new Attachment("output.txt", output));
throw new VcsException(e);
}
}
Aggregations