public Change getChange(Project project) {
    // todo unify with
    if (myChange == null) {
      File baseDir = new File(project.getBaseDir().getPath());

      File file = getAbsolutePath(baseDir, myBeforePath);
      FilePath beforePath = VcsUtil.getFilePath(file, false);
      beforePath.refresh();
      ContentRevision beforeRevision = null;
      if (myFileStatus != FileStatus.ADDED) {
        beforeRevision =
            new CurrentContentRevision(beforePath) {
              @Override
              @NotNull
              public VcsRevisionNumber getRevisionNumber() {
                return new TextRevisionNumber(VcsBundle.message("local.version.title"));
              }
            };
      }
      ContentRevision afterRevision = null;
      if (myFileStatus != FileStatus.DELETED) {
        FilePath afterPath = VcsUtil.getFilePath(getAbsolutePath(baseDir, myAfterPath), false);
        afterRevision = new PatchedContentRevision(project, beforePath, afterPath);
      }
      myChange = new Change(beforeRevision, afterRevision, myFileStatus);
    }
    return myChange;
  }
 @NotNull
 private static FilePath rebasePath(
     @NotNull FilePath oldBase, @NotNull FilePath newBase, @NotNull FilePath path) {
   String relativePath =
       ObjectUtils.assertNotNull(FileUtil.getRelativePath(oldBase.getPath(), path.getPath(), '/'));
   return VcsUtil.getFilePath(newBase.getPath() + "/" + relativePath, path.isDirectory());
 }
      public MyDiffRequestProducer(
          @NotNull VirtualFilePointer filePointer, @NotNull FileStatus fileStatus) {
        myFilePointer = filePointer;
        myFileStatus = fileStatus;

        myFilePath = VcsUtil.getFilePath(myFilePointer.getPresentableUrl(), false);
      }
 public ThreeState haveChangesUnder(@NotNull VirtualFile virtualFile) {
   FilePath dir = VcsUtil.getFilePath(virtualFile);
   FilePath changeCandidate = myIdx.getAffectedPaths().ceiling(dir);
   if (changeCandidate == null) {
     return ThreeState.NO;
   }
   return FileUtil.isAncestorThreeState(dir.getPath(), changeCandidate.getPath(), false);
 }
  @NotNull
  private static Pair<FilePath, VirtualFile> getPathAndParentFile(@NotNull VcsContext context) {
    if (context.getSelectedFilesStream().findAny().isPresent()) {
      VirtualFile file = getIfSingle(context.getSelectedFilesStream());
      return file != null ? Pair.create(VcsUtil.getFilePath(file), file) : Pair.empty();
    }

    File[] ioFiles = context.getSelectedIOFiles();
    if (ioFiles != null && ioFiles.length > 0) {
      for (File ioFile : ioFiles) {
        VirtualFile parent = getParentVirtualFile(ioFile);
        if (parent != null)
          return Pair.create(VcsUtil.getFilePath(parent, ioFile.getName()), parent);
      }
    }

    return Pair.empty();
  }
 public static HgFile getOriginalHgFile(Project project, VirtualFile root) {
   HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
   if (project.isDisposed()) {
     return hgFile;
   }
   FilePath originalFileName =
       HgUtil.getOriginalFileName(hgFile.toFilePath(), ChangeListManager.getInstance(project));
   return new HgFile(hgFile.getRepo(), originalFileName);
 }
 /**
  * Revert files from the list
  *
  * @param project the project
  * @param root the vcs root
  * @param files the files to revert
  */
 private static void revertFiles(Project project, VirtualFile root, ArrayList<String> files)
     throws VcsException {
   // TODO consider deleted files
   GitRollbackEnvironment rollback = GitRollbackEnvironment.getInstance(project);
   ArrayList<FilePath> list = new ArrayList<FilePath>(files.size());
   for (String p : files) {
     list.add(VcsUtil.getFilePath(p));
   }
   rollback.revert(root, list);
 }
Esempio n. 8
0
 /**
  * Return a git root for the file (the parent directory with ".git" subdirectory)
  *
  * @param file the file to check
  * @return git root for the file or null if the file is not not under Git
  * @deprecated because uses the java.io.File.
  * @use GitRepositoryManager#getRepositoryForFile().
  */
 @Nullable
 public static VirtualFile gitRootOrNull(final VirtualFile file) {
   if (file instanceof AbstractVcsVirtualFile) {
     return getGitRootOrNull(VcsUtil.getFilePath(file.getPath()));
   }
   VirtualFile root = file;
   while (root != null) {
     if (root.findFileByRelativePath(DOT_GIT) != null) {
       return root;
     }
     root = root.getParent();
   }
   return root;
 }
Esempio n. 9
0
  private Change getChange(GitVirtualFile file) {
    if (file == null) return null;
    ContentRevision beforeRev =
        new GitContentRevision(
            file,
            new GitRevisionNumber(GitRevisionNumber.TIP, new Date(file.getModificationStamp())),
            project);
    ContentRevision afterRev = CurrentContentRevision.create(VcsUtil.getFilePath(file.getPath()));

    Change c = null;
    switch (file.getStatus()) {
      case UNMERGED:
        {
          c = new Change(beforeRev, afterRev, FileStatus.MERGED_WITH_CONFLICTS);
          break;
        }
      case ADDED:
        {
          c = new Change(null, afterRev, FileStatus.ADDED);
          break;
        }
      case DELETED:
        {
          c = new Change(beforeRev, null, FileStatus.DELETED);
          break;
        }
      case COPY:
      case RENAME:
      case MODIFIED:
        {
          c = new Change(beforeRev, afterRev, FileStatus.MODIFIED);
          break;
        }
      case UNMODIFIED:
        {
          break;
        }
      case IGNORED:
        {
          c = new Change(null, afterRev, FileStatus.IGNORED);
          break;
        }
      case UNVERSIONED:
      default:
        {
          c = new Change(null, afterRev, FileStatus.UNKNOWN);
        }
    }
    return c;
  }
  private void processRecursively(final VirtualFile vFile, final SVNDepth prevDepth) {
    if (SVNDepth.EMPTY.equals(prevDepth)) return;
    if (myPartner.isIgnoredIdeaLevel(vFile)) {
      myReceiver.processIgnored(vFile);
      return;
    }
    final SVNDepth newDepth =
        SVNDepth.INFINITY.equals(prevDepth) ? SVNDepth.INFINITY : SVNDepth.EMPTY;

    final SVNStatusClient childClient = myPartner.createStatusClient();
    final VirtualFile[] children = vFile.getChildren();
    for (VirtualFile child : children) {
      final FilePath filePath = VcsUtil.getFilePath(child.getPath(), child.isDirectory());
      // recursiveness is used ONLY for search of working copies that have unversioned files above
      final MyItem childItem = new MyItem(myProject, filePath, newDepth, childClient, true);
      myQueue.add(childItem);
    }
  }
  public Map<VirtualFile, RepositoryLocation> getRoots() {
    myContentRoots = myPlManager.getRootsUnderVcs(myVcs);

    List<VirtualFile> roots = new ArrayList<>();
    final List<VcsDirectoryMapping> mappings = myPlManager.getDirectoryMappings(myVcs);
    for (VcsDirectoryMapping mapping : mappings) {
      if (mapping.isDefaultMapping()) {
        if (myVcs.equals(myPlManager.getVcsFor(myProject.getBaseDir()))) {
          roots.add(myProject.getBaseDir());
        }
      } else {
        VirtualFile newFile = LocalFileSystem.getInstance().findFileByPath(mapping.getDirectory());
        if (newFile == null) {
          newFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(mapping.getDirectory());
        }
        if (newFile != null) {
          roots.add(newFile);
        } else {
          LOG.info("Can not file virtual file for root: " + mapping.getDirectory());
        }
      }
    }
    ContainerUtil.addAll(roots, myContentRoots);
    final Map<VirtualFile, RepositoryLocation> result = new HashMap<>();
    for (Iterator<VirtualFile> iterator = roots.iterator(); iterator.hasNext(); ) {
      final VirtualFile vf = iterator.next();
      final RepositoryLocation location =
          myLocationCache.getLocation(myVcs, VcsUtil.getFilePath(vf), false);
      if (location != null) {
        result.put(vf, location);
      } else {
        iterator.remove();
      }
    }
    roots = myVcs.filterUniqueRoots(roots, IntoSelfVirtualFileConvertor.getInstance());
    result.keySet().retainAll(roots);

    logRoots(roots);
    return result;
  }
    public void handleStatus(final SVNStatus status) throws SVNException {
      myPartner.checkCanceled();
      final File ioFile = status.getFile();
      checkIfCopyRootWasReported();

      final LocalFileSystem lfs = LocalFileSystem.getInstance();
      VirtualFile vFile = lfs.findFileByIoFile(ioFile);
      if (vFile == null) {
        vFile = lfs.refreshAndFindFileByIoFile(ioFile);
      }
      if ((vFile != null) && myPartner.isExcluded(vFile)) return;

      if ((vFile != null) && (SvnVcs.svnStatusIsUnversioned(status))) {
        myReceiver.processUnversioned(vFile);
        if (vFile.isDirectory()) {
          processRecursively(vFile, myCurrentItem.getDepth());
        }
      } else {
        final FilePath path = VcsUtil.getFilePath(ioFile, status.getKind().equals(SVNNodeKind.DIR));
        myReceiver.process(path, status);
      }
    }
  /**
   * Preform a merge commit
   *
   * @param project a project
   * @param root a vcs root
   * @param added added files
   * @param removed removed files
   * @param messageFile a message file for commit
   * @param author an author
   * @param exceptions the list of exceptions to report
   * @param partialOperation
   * @return true if merge commit was successful
   */
  private static boolean mergeCommit(
      final Project project,
      final VirtualFile root,
      final Set<FilePath> added,
      final Set<FilePath> removed,
      final File messageFile,
      final String author,
      List<VcsException> exceptions,
      @NotNull final PartialOperation partialOperation) {
    HashSet<FilePath> realAdded = new HashSet<FilePath>();
    HashSet<FilePath> realRemoved = new HashSet<FilePath>();
    // perform diff
    GitSimpleHandler diff = new GitSimpleHandler(project, root, GitCommand.DIFF);
    diff.setSilent(true);
    diff.setStdoutSuppressed(true);
    diff.addParameters("--diff-filter=ADMRUX", "--name-status", "HEAD");
    diff.endOptions();
    String output;
    try {
      output = diff.run();
    } catch (VcsException ex) {
      exceptions.add(ex);
      return false;
    }
    String rootPath = root.getPath();
    for (StringTokenizer lines = new StringTokenizer(output, "\n", false);
        lines.hasMoreTokens(); ) {
      String line = lines.nextToken().trim();
      if (line.length() == 0) {
        continue;
      }
      String[] tk = line.split("\t");
      switch (tk[0].charAt(0)) {
        case 'M':
        case 'A':
          realAdded.add(VcsUtil.getFilePath(rootPath + "/" + tk[1]));
          break;
        case 'D':
          realRemoved.add(VcsUtil.getFilePathForDeletedFile(rootPath + "/" + tk[1], false));
          break;
        default:
          throw new IllegalStateException("Unexpected status: " + line);
      }
    }
    realAdded.removeAll(added);
    realRemoved.removeAll(removed);
    if (realAdded.size() != 0 || realRemoved.size() != 0) {

      final List<FilePath> files = new ArrayList<FilePath>();
      files.addAll(realAdded);
      files.addAll(realRemoved);
      final Ref<Boolean> mergeAll = new Ref<Boolean>();
      try {
        GuiUtils.runOrInvokeAndWait(
            new Runnable() {
              public void run() {
                String message =
                    GitBundle.message("commit.partial.merge.message", partialOperation.getName());
                SelectFilePathsDialog dialog =
                    new SelectFilePathsDialog(
                        project,
                        files,
                        message,
                        null,
                        "Commit All Files",
                        CommonBundle.getCancelButtonText(),
                        false);
                dialog.setTitle(GitBundle.getString("commit.partial.merge.title"));
                dialog.show();
                mergeAll.set(dialog.isOK());
              }
            });
      } catch (RuntimeException ex) {
        throw ex;
      } catch (Exception ex) {
        throw new RuntimeException("Unable to invoke a message box on AWT thread", ex);
      }
      if (!mergeAll.get()) {
        return false;
      }
      // update non-indexed files
      if (!updateIndex(project, root, realAdded, realRemoved, exceptions)) {
        return false;
      }
      for (FilePath f : realAdded) {
        VcsDirtyScopeManager.getInstance(project).fileDirty(f);
      }
      for (FilePath f : realRemoved) {
        VcsDirtyScopeManager.getInstance(project).fileDirty(f);
      }
    }
    // perform merge commit
    try {
      GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT);
      handler.setStdoutSuppressed(false);
      handler.addParameters("-F", messageFile.getAbsolutePath());
      if (author != null) {
        handler.addParameters("--author=" + author);
      }
      handler.endOptions();
      handler.run();
      GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
      manager.updateRepository(root);
    } catch (VcsException ex) {
      exceptions.add(ex);
      return false;
    }
    return true;
  }
 @Deprecated
 @Override
 public FileStatus getStatus(File file) {
   return myWorker.getStatus(VcsUtil.getFilePath(file));
 }
 @Nullable
 private VirtualFile getRootForPath(final String s) {
   return myVcsManager.getVcsRootFor(VcsUtil.getFilePath(s, false));
 }
Esempio n. 16
0
 private VcsHistorySession getHistorySession(String relativePath) throws VcsException {
   return HgVcs.getInstance(myProject)
       .getVcsHistoryProvider()
       .createSessionFor(VcsUtil.getFilePath(new File(myProjectDir, relativePath), false));
 }
 @Override
 protected boolean isFileDirty(final VcsDirtyScope scope, final VirtualFile file) {
   if (scope == null) return true;
   if (fileDropped(file)) return true;
   return scope.belongsTo(VcsUtil.getFilePath(file));
 }