Search in sources :

Example 1 with Change

use of com.intellij.openapi.vcs.changes.Change in project intellij-community by JetBrains.

the class HgUtil method getOriginalFileName.

@NotNull
public static FilePath getOriginalFileName(@NotNull FilePath filePath, ChangeListManager changeListManager) {
    Change change = changeListManager.getChange(filePath);
    if (change == null) {
        return filePath;
    }
    FileStatus status = change.getFileStatus();
    if (status == HgChangeProvider.COPIED || status == HgChangeProvider.RENAMED) {
        ContentRevision beforeRevision = change.getBeforeRevision();
        assert beforeRevision != null : "If a file's status is copied or renamed, there must be an previous version";
        return beforeRevision.getFile();
    } else {
        return filePath;
    }
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Change

use of com.intellij.openapi.vcs.changes.Change in project intellij-community by JetBrains.

the class HgUtil method getDiff.

@NotNull
public static List<Change> getDiff(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull final FilePath path, @Nullable final HgRevisionNumber revNum1, @Nullable final HgRevisionNumber revNum2) {
    HgStatusCommand statusCommand;
    if (revNum1 != null) {
        //rev2==null means "compare with local version"
        statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(!path.isDirectory()).baseRevision(revNum1).targetRevision(revNum2).build(project);
    } else {
        //rev1 and rev2 can't be null both//
        LOG.assertTrue(revNum2 != null, "revision1 and revision2 can't both be null. Path: " + path);
        //get initial changes//
        statusCommand = new HgStatusCommand.Builder(true).ignored(false).unknown(false).copySource(false).baseRevision(revNum2).build(project);
    }
    Collection<HgChange> hgChanges = statusCommand.executeInCurrentThread(root, Collections.singleton(path));
    List<Change> changes = new ArrayList<>();
    //convert output changes to standard Change class
    for (HgChange hgChange : hgChanges) {
        FileStatus status = convertHgDiffStatus(hgChange.getStatus());
        if (status != FileStatus.UNKNOWN) {
            changes.add(HgHistoryUtil.createChange(project, root, hgChange.beforeFile().getRelativePath(), revNum1, hgChange.afterFile().getRelativePath(), revNum2, status));
        }
    }
    return changes;
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) Change(com.intellij.openapi.vcs.changes.Change) HgStatusCommand(org.zmlx.hg4idea.command.HgStatusCommand) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Change

use of com.intellij.openapi.vcs.changes.Change in project intellij-community by JetBrains.

the class SvnCheckinHandlerFactory method splitIntoCopies.

@NotNull
private static MultiMap<String, WorkingCopyFormat> splitIntoCopies(@NotNull SvnVcs vcs, @NotNull Collection<Change> changes) {
    MultiMap<String, WorkingCopyFormat> result = MultiMap.createSet();
    SvnFileUrlMapping mapping = vcs.getSvnFileUrlMapping();
    for (Change change : changes) {
        RootUrlInfo path = mapping.getWcRootForFilePath(ChangesUtil.getFilePath(change).getIOFile());
        if (path != null) {
            result.putValue(path.getRepositoryUrl(), path.getFormat());
        }
    }
    return result;
}
Also used : Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Change

use of com.intellij.openapi.vcs.changes.Change in project intellij-community by JetBrains.

the class HgVFSListener method executeDelete.

protected void executeDelete() {
    final List<FilePath> filesToDelete = new ArrayList<>(myDeletedWithoutConfirmFiles);
    final List<FilePath> filesToConfirmDeletion = new ArrayList<>(myDeletedFiles);
    myDeletedWithoutConfirmFiles.clear();
    myDeletedFiles.clear();
    // skip files which are not under Mercurial
    skipNotUnderHg(filesToDelete);
    skipNotUnderHg(filesToConfirmDeletion);
    filesToDelete.removeAll(processAndGetVcsIgnored(filesToDelete));
    filesToConfirmDeletion.removeAll(processAndGetVcsIgnored(filesToConfirmDeletion));
    // but without user confirmation.
    for (Iterator<FilePath> it = filesToConfirmDeletion.iterator(); it.hasNext(); ) {
        FilePath filePath = it.next();
        Change fileChange = ChangeListManager.getInstance(myProject).getChange(filePath);
        if (fileChange != null && fileChange.getFileStatus().equals(FileStatus.ADDED)) {
            filesToDelete.add(filePath);
            it.remove();
        }
    }
    new Task.ConditionalModal(myProject, HgVcsMessages.message("hg4idea.remove.progress"), false, VcsConfiguration.getInstance(myProject).getAddRemoveOption()) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            // confirm removal from the VCS if needed
            if (myRemoveOption.getValue() != VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY) {
                if (myRemoveOption.getValue() == VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY || filesToConfirmDeletion.isEmpty()) {
                    filesToDelete.addAll(filesToConfirmDeletion);
                } else {
                    final AtomicReference<Collection<FilePath>> filePaths = new AtomicReference<>();
                    ApplicationManager.getApplication().invokeAndWait(() -> filePaths.set(selectFilePathsToDelete(filesToConfirmDeletion)));
                    if (filePaths.get() != null) {
                        filesToDelete.addAll(filePaths.get());
                    }
                }
            }
            if (!filesToDelete.isEmpty()) {
                performDeletion(filesToDelete);
            }
        }
    }.queue();
}
Also used : VcsBackgroundTask(com.intellij.util.ui.VcsBackgroundTask) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AtomicReference(java.util.concurrent.atomic.AtomicReference) Change(com.intellij.openapi.vcs.changes.Change)

Example 5 with Change

use of com.intellij.openapi.vcs.changes.Change 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;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) HgRepository(org.zmlx.hg4idea.repo.HgRepository) Change(com.intellij.openapi.vcs.changes.Change) Hash(com.intellij.vcs.log.Hash) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Change (com.intellij.openapi.vcs.changes.Change)208 VirtualFile (com.intellij.openapi.vfs.VirtualFile)101 Test (org.junit.Test)79 File (java.io.File)52 ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)44 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)32 VcsException (com.intellij.openapi.vcs.VcsException)31 NotNull (org.jetbrains.annotations.NotNull)31 RollbackWorker (com.intellij.openapi.vcs.changes.ui.RollbackWorker)28 FilePath (com.intellij.openapi.vcs.FilePath)26 ArrayList (java.util.ArrayList)23 ConflictVersion (org.jetbrains.idea.svn.conflict.ConflictVersion)23 TreeConflictDescription (org.jetbrains.idea.svn.conflict.TreeConflictDescription)23 Project (com.intellij.openapi.project.Project)14 Nullable (org.jetbrains.annotations.Nullable)10 FileStatus (com.intellij.openapi.vcs.FileStatus)8 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)8 VcsAnnotationLocalChangesListener (com.intellij.openapi.vcs.changes.VcsAnnotationLocalChangesListener)8 GitRevisionNumber (git4idea.GitRevisionNumber)8 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)7