コード例 #1
0
  public boolean move(VirtualFile file, VirtualFile toDir) throws IOException {
    File srcFile = getIOFile(file);
    File dstFile = new File(getIOFile(toDir), file.getName());

    final SvnVcs vcs = getVCS(toDir);
    final SvnVcs sourceVcs = getVCS(file);
    if (vcs == null && sourceVcs == null) return false;

    if (vcs == null) {
      return false;
    }

    FileDocumentManager.getInstance().saveAllDocuments();
    if (sourceVcs == null) {
      return createItem(toDir, file.getName(), file.isDirectory(), true);
    }

    if (isPendingAdd(vcs.getProject(), toDir)) {

      myMovedFiles.add(new MovedFileInfo(sourceVcs.getProject(), srcFile, dstFile));
      return true;
    } else {
      final VirtualFile oldParent = file.getParent();
      myFilesToRefresh.add(oldParent);
      myFilesToRefresh.add(toDir);
      return doMove(sourceVcs, srcFile, dstFile);
    }
  }
コード例 #2
0
 private static boolean isUndo(SvnVcs vcs) {
   if (vcs == null || vcs.getProject() == null) {
     return false;
   }
   Project p = vcs.getProject();
   return UndoManager.getInstance(p).isUndoInProgress();
 }
コード例 #3
0
  /**
   * delete file or directory (both 'undo' and 'do' modes) unversioned: do nothing, return false
   * obstructed: do nothing, return false external or wc root: do nothing, return false missing: do
   * nothing, return false
   *
   * <p>versioned: schedule for deletion, return true added: schedule for deletion (make
   * unversioned), return true copied, but not scheduled: schedule for deletion, return true
   * replaced: schedule for deletion, return true
   *
   * <p>deleted: do nothing, return true (strange)
   */
  public boolean delete(VirtualFile file) throws IOException {
    final SvnVcs vcs = getVCS(file);
    if (vcs != null && SvnUtil.isAdminDirectory(file)) {
      return true;
    }
    if (vcs == null) return false;
    final VcsShowConfirmationOption.Value value = vcs.getDeleteConfirmation().getValue();
    if (VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY.equals(value)) return false;

    final File ioFile = getIOFile(file);
    if (!SvnUtil.isSvnVersioned(vcs.getProject(), ioFile.getParentFile())) {
      return false;
    }
    if (SvnUtil.isWorkingCopyRoot(ioFile)) {
      return false;
    }

    SVNStatus status = getFileStatus(vcs, ioFile);

    if (status == null
        || SvnVcs.svnStatusIsUnversioned(status)
        || SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_OBSTRUCTED)
        || SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_MISSING)
        || SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_EXTERNAL)
        || SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_IGNORED)) {
      return false;
    } else if (SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_DELETED)) {
      if (isUndo(vcs)) {
        moveToUndoStorage(file);
      }
      return true;
    } else {
      if (vcs != null) {
        if (isAboveSourceOfCopyOrMove(vcs.getProject(), ioFile)) {
          myDeletedFiles.putValue(vcs.getProject(), ioFile);
          return true;
        }
        if (SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_ADDED)) {
          try {
            createRevertAction(vcs, ioFile, false).execute();
          } catch (SVNException e) {
            // ignore
          }
        } else {
          myDeletedFiles.putValue(vcs.getProject(), ioFile);
          // packages deleted from disk should not be deleted from svn (IDEADEV-16066)
          if (file.isDirectory() || isUndo(vcs)) return true;
        }
      }
      return false;
    }
  }
コード例 #4
0
  private boolean sameRoot(final SvnVcs vcs, final VirtualFile srcDir, final VirtualFile dstDir) {
    final UUIDHelper helper = new UUIDHelper(vcs);
    final String srcUUID = helper.getRepositoryUUID(vcs.getProject(), srcDir);
    final String dstUUID = helper.getRepositoryUUID(vcs.getProject(), dstDir);

    return srcUUID != null && dstUUID != null && srcUUID.equals(dstUUID);
  }
コード例 #5
0
  /**
   * add file or directory:
   *
   * <p>parent directory is: unversioned: do nothing, return false versioned: entry is: null: create
   * entry, schedule for addition missing: do nothing, return false deleted, 'do' mode: try to
   * create entry and it schedule for addition if kind is the same, otherwise do nothing, return
   * false. deleted: 'undo' mode: try to revert non-recursively, if kind is the same, otherwise do
   * nothing, return false. anything else: return false.
   */
  private boolean createItem(
      VirtualFile dir, String name, boolean directory, final boolean recursive) {
    SvnVcs vcs = getVCS(dir);
    if (vcs == null) {
      return false;
    }
    final VcsShowConfirmationOption.Value value = vcs.getAddConfirmation().getValue();
    if (VcsShowConfirmationOption.Value.DO_NOTHING_SILENTLY.equals(value)) return false;

    if (isUndo(vcs) && SvnUtil.isAdminDirectory(dir, name)) {
      return false;
    }
    File ioDir = getIOFile(dir);
    boolean pendingAdd = isPendingAdd(vcs.getProject(), dir);
    if (!SvnUtil.isSvnVersioned(vcs.getProject(), ioDir) && !pendingAdd) {
      return false;
    }
    final File targetFile = new File(ioDir, name);
    SVNStatus status = getFileStatus(vcs, targetFile);

    if (status == null
        || status.getContentsStatus() == SVNStatusType.STATUS_NONE
        || status.getContentsStatus() == SVNStatusType.STATUS_UNVERSIONED) {
      myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(dir, name, null, recursive));
      return false;
    } else if (SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_MISSING)) {
      return false;
    } else if (SvnVcs.svnStatusIs(status, SVNStatusType.STATUS_DELETED)) {
      SVNNodeKind kind = status.getKind();
      // kind differs.
      if (directory && kind != SVNNodeKind.DIR || !directory && kind != SVNNodeKind.FILE) {
        return false;
      }
      try {
        if (isUndo(vcs)) {
          createRevertAction(vcs, targetFile, false).execute();
          return true;
        }
        myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(dir, name, null, recursive));
        return false;
      } catch (SVNException e) {
        SVNFileUtil.deleteAll(targetFile, true);
        return false;
      }
    }
    return false;
  }
コード例 #6
0
  private boolean doMove(@NotNull SvnVcs vcs, final File src, final File dst) {
    long srcTime = src.lastModified();
    try {
      final boolean isUndo = isUndo(vcs);
      final String list = isUndo ? null : SvnChangelistListener.getCurrentMapping(vcs, src);

      WorkingCopyFormat format = vcs.getWorkingCopyFormat(src);
      final boolean is17OrLater =
          WorkingCopyFormat.ONE_DOT_EIGHT.equals(format)
              || WorkingCopyFormat.ONE_DOT_SEVEN.equals(format);
      if (is17OrLater) {
        SVNStatus srcStatus = getFileStatus(vcs, src);
        final File toDir = dst.getParentFile();
        SVNStatus dstStatus = getFileStatus(vcs, toDir);
        final boolean srcUnversioned =
            srcStatus == null || SvnVcs.svnStatusIsUnversioned(srcStatus);
        if (srcUnversioned && (dstStatus == null || SvnVcs.svnStatusIsUnversioned(dstStatus))) {
          return false;
        }
        if (srcUnversioned) {
          SVNStatus dstWasStatus = getFileStatus(vcs, dst);
          if (dstWasStatus == null || SvnVcs.svnStatusIsUnversioned(dstWasStatus)) {
            return false;
          }
        }
        if (for17move(vcs, src, dst, isUndo, srcStatus)) return false;
      } else {
        if (for16move(vcs, src, dst, isUndo)) return false;
      }

      if (!isUndo && list != null) {
        SvnChangelistListener.putUnderList(vcs.getProject(), list, dst);
      }
      dst.setLastModified(srcTime);
    } catch (SVNException e) {
      addToMoveExceptions(vcs.getProject(), e);
      return false;
    } catch (VcsException e) {
      addToMoveExceptions(vcs.getProject(), e);
      return false;
    }
    return true;
  }
コード例 #7
0
    public void detectCopyRoots(final VirtualFile[] roots, final boolean clearState) {
      final Getter<Boolean> cancelGetter =
          new Getter<Boolean>() {
            public Boolean get() {
              return myVcs.getProject().isDisposed();
            }
          };

      for (final VirtualFile vcsRoot : roots) {
        final List<Real> foundRoots =
            ForNestedRootChecker.getAllNestedWorkingCopies(vcsRoot, myVcs, false, cancelGetter);
        if (foundRoots.isEmpty()) {
          myLonelyRoots.add(vcsRoot);
        }
        // filter out bad(?) items
        for (Real foundRoot : foundRoots) {
          final SVNURL repoRoot = foundRoot.getInfo().getRepositoryRootURL();
          if (repoRoot == null) {
            LOG.info(
                "Error: cannot find repository URL for versioned folder: "
                    + foundRoot.getFile().getPath());
          } else {
            myRepositoryRoots.register(repoRoot);
            myTopRoots.add(
                new RootUrlInfo(
                    repoRoot,
                    foundRoot.getInfo().getURL(),
                    SvnFormatSelector.getWorkingCopyFormat(foundRoot.getInfo().getFile()),
                    foundRoot.getFile(),
                    vcsRoot));
          }
        }
      }

      if (!SvnConfiguration.getInstance(myVcs.getProject()).DETECT_NESTED_COPIES) {
        myApplier.apply(myVcs, myTopRoots, myLonelyRoots);
      } else {
        addNestedRoots(clearState);
      }
    }
コード例 #8
0
  @Nullable
  public File copy(final VirtualFile file, final VirtualFile toDir, final String copyName)
      throws IOException {
    SvnVcs vcs = getVCS(toDir);
    if (vcs == null) {
      vcs = getVCS(file);
    }
    if (vcs == null) {
      return null;
    }

    File srcFile = new File(file.getPath());
    File destFile = new File(new File(toDir.getPath()), copyName);
    final boolean dstDirUnderControl =
        SvnUtil.isSvnVersioned(vcs.getProject(), destFile.getParentFile());
    if (!dstDirUnderControl && !isPendingAdd(vcs.getProject(), toDir)) {
      return null;
    }

    if (!SvnUtil.isSvnVersioned(vcs.getProject(), srcFile.getParentFile())) {
      myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(toDir, copyName, null, false));
      return null;
    }

    final SVNStatus fileStatus = getFileStatus(vcs, srcFile);
    if (fileStatus != null && SvnVcs.svnStatusIs(fileStatus, SVNStatusType.STATUS_ADDED)) {
      myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(toDir, copyName, null, false));
      return null;
    }

    if (sameRoot(vcs, file.getParent(), toDir)) {
      myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(toDir, copyName, srcFile, false));
      return null;
    }

    myAddedFiles.putValue(vcs.getProject(), new AddedFileInfo(toDir, copyName, null, false));
    return null;
  }
コード例 #9
0
    private void addNestedRoots(final boolean clearState) {
      final List<VirtualFile> basicVfRoots =
          ObjectsConvertor.convert(
              myTopRoots,
              new Convertor<RootUrlInfo, VirtualFile>() {
                public VirtualFile convert(final RootUrlInfo real) {
                  return real.getVirtualFile();
                }
              });

      final ChangeListManager clManager = ChangeListManager.getInstance(myVcs.getProject());

      if (clearState) {
        // clear what was reported before (could be for currently-not-existing roots)
        myGate.get();
      }
      clManager.invokeAfterUpdate(
          new Runnable() {
            public void run() {
              final List<RootUrlInfo> nestedRoots = new ArrayList<RootUrlInfo>();

              final NestedCopiesData data = myGate.get();
              for (NestedCopiesBuilder.MyPointInfo info : data.getSet()) {
                if (NestedCopyType.external.equals(info.getType())
                    || NestedCopyType.switched.equals(info.getType())) {
                  final File infoFile = new File(info.getFile().getPath());
                  boolean copyFound = false;
                  for (RootUrlInfo topRoot : myTopRoots) {
                    if (topRoot.getIoFile().equals(infoFile)) {
                      topRoot.setType(info.getType());
                      copyFound = true;
                      break;
                    }
                  }
                  if (copyFound) {
                    continue;
                  }
                  try {
                    final SVNStatus svnStatus = SvnUtil.getStatus(myVcs, infoFile);
                    if (svnStatus.getURL() == null) continue;
                    info.setUrl(svnStatus.getURL());
                    info.setFormat(WorkingCopyFormat.getInstance(svnStatus.getWorkingCopyFormat()));
                  } catch (Exception e) {
                    continue;
                  }
                }
                for (RootUrlInfo topRoot : myTopRoots) {
                  if (VfsUtil.isAncestor(topRoot.getVirtualFile(), info.getFile(), true)) {
                    final SVNURL repoRoot = myRepositoryRoots.ask(info.getUrl());
                    if (repoRoot != null) {
                      final RootUrlInfo rootInfo =
                          new RootUrlInfo(
                              repoRoot,
                              info.getUrl(),
                              info.getFormat(),
                              info.getFile(),
                              topRoot.getRoot());
                      rootInfo.setType(info.getType());
                      nestedRoots.add(rootInfo);
                    }
                    break;
                  }
                }
              }
              // check those top roots which ARE externals, but that was not detected due to they
              // itself were the status request target
              // new SvnNestedTypeRechecker(myVcs.getProject(), myTopRoots).run();

              myTopRoots.addAll(nestedRoots);
              myApplier.apply(myVcs, myTopRoots, myLonelyRoots);
            }
          },
          InvokeAfterUpdateMode.SILENT_CALLBACK_POOLED,
          null,
          new Consumer<VcsDirtyScopeManager>() {
            public void consume(VcsDirtyScopeManager vcsDirtyScopeManager) {
              if (clearState) {
                vcsDirtyScopeManager.filesDirty(null, basicVfRoots);
              }
            }
          },
          null);
    }