コード例 #1
0
  @NotNull
  private GitFileRevision createParentRevision(
      @NotNull GitRepository repository,
      @NotNull GitFileRevision currentRevision,
      @NotNull String parentHash)
      throws VcsException {
    FilePath currentRevisionPath = currentRevision.getPath();
    if (currentRevisionPath.isDirectory()) {
      // for directories the history doesn't follow renames
      return makeRevisionFromHash(currentRevisionPath, parentHash);
    }

    // can't limit by the path: in that case rename information will be missed
    Collection<Change> changes =
        GitChangeUtils.getDiff(
            myProject, repository.getRoot(), parentHash, currentRevision.getHash(), null);
    for (Change change : changes) {
      ContentRevision afterRevision = change.getAfterRevision();
      ContentRevision beforeRevision = change.getBeforeRevision();
      if (afterRevision != null && afterRevision.getFile().equals(currentRevisionPath)) {
        // if the file was renamed, taking the path how it was in the parent; otherwise the path
        // didn't change
        FilePath path =
            (beforeRevision != null ? beforeRevision.getFile() : afterRevision.getFile());
        return new GitFileRevision(myProject, path, new GitRevisionNumber(parentHash), true);
      }
    }
    LOG.error(
        String.format(
            "Could not find parent revision. Will use the path from parent revision. Current revision: %s, parent hash: %s",
            currentRevision, parentHash));
    return makeRevisionFromHash(currentRevisionPath, parentHash);
  }
コード例 #2
0
 @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());
 }
コード例 #3
0
 private void doShowDiff(
     @NotNull FilePath filePath,
     @NotNull VcsFileRevision revision1,
     @NotNull VcsFileRevision revision2,
     boolean autoSort) {
   if (!filePath.isDirectory()) {
     VcsHistoryUtil.showDifferencesInBackground(
         myProject, filePath, revision1, revision2, autoSort);
   } else if (revision2 instanceof CurrentRevision) {
     GitFileRevision left = (GitFileRevision) revision1;
     showDiffForDirectory(filePath, left.getHash(), null);
   } else if (revision1.equals(VcsFileRevision.NULL)) {
     GitFileRevision right = (GitFileRevision) revision2;
     showDiffForDirectory(filePath, null, right.getHash());
   } else {
     GitFileRevision left = (GitFileRevision) revision1;
     GitFileRevision right = (GitFileRevision) revision2;
     if (autoSort) {
       Pair<VcsFileRevision, VcsFileRevision> pair =
           VcsHistoryUtil.sortRevisions(revision1, revision2);
       left = (GitFileRevision) pair.first;
       right = (GitFileRevision) pair.second;
     }
     showDiffForDirectory(filePath, left.getHash(), right.getHash());
   }
 }
コード例 #4
0
  public void go(final FilePath rootPath, final SVNDepth depth) throws SVNException {
    final MyItem root =
        new MyItem(myProject, rootPath, depth, myPartner.createStatusClient(), false);
    myQueue.add(root);

    while (!myQueue.isEmpty()) {
      myPartner.checkCanceled();

      final MyItem item = myQueue.removeFirst();
      final FilePath path = item.getPath();
      final File ioFile = path.getIOFile();

      if (path.isDirectory()) {
        myHandler.setCurrentItem(item);
        try {
          item.getClient(ioFile)
              .doStatus(
                  ioFile,
                  SVNRevision.WORKING,
                  item.getDepth(),
                  false,
                  false,
                  true,
                  false,
                  myHandler,
                  null);
          myHandler.checkIfCopyRootWasReported();
        } catch (SVNException e) {
          if (e.getErrorMessage().getErrorCode() == SVNErrorCode.WC_NOT_DIRECTORY) {
            final VirtualFile virtualFile = path.getVirtualFile();
            if (virtualFile != null) {
              if (myPartner.isExcluded(virtualFile)) return;
              // self is unversioned
              myReceiver.processUnversioned(virtualFile);

              processRecursively(virtualFile, item.getDepth());
            }
          } else {
            throw e;
          }
        }
      } else {
        if (item.isIsInnerCopyRoot()) {
          // this means that the status of parent directory had already been checked and is
          // unversioned;
          // to avoid SVN exception on status query to unversioned directory; and since we already
          // know then that the file
          // status is "unversioned" -> just register the unversioned file
          if (path.getVirtualFile() != null) {
            myReceiver.processUnversioned(path.getVirtualFile());
          }
        } else {
          // just file
          final SVNStatus status = item.getClient().doStatus(ioFile, false, false);
          myReceiver.process(path, status);
        }
      }
    }
  }
コード例 #5
0
 private String modifyCheckinActionName(final VcsContext dataContext, String checkinActionName) {
   final FilePath[] roots = getRoots(dataContext);
   if (roots == null || roots.length == 0) return checkinActionName;
   final FilePath first = roots[0];
   if (roots.length == 1) {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directory", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.file", checkinActionName);
     }
   } else {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directories", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.files", checkinActionName);
     }
   }
 }
コード例 #6
0
 public static boolean canCreateRequest(Change change) {
   if (ChangesUtil.isTextConflictingChange(change)
       || change.isTreeConflict()
       || change.isPhantom()) return false;
   if (ShowDiffAction.isBinaryChange(change)) return false;
   final FilePath filePath = ChangesUtil.getFilePath(change);
   if (filePath.isDirectory()) return false;
   return true;
 }
コード例 #7
0
 @Override
 protected void renderIcon(FilePath path) {
   final String module = myModules.get(path.getVirtualFile());
   if (module != null) {
     setIcon(PlatformIcons.CONTENT_ROOT_ICON_CLOSED);
   } else {
     if (path.isDirectory()) {
       setIcon(PlatformIcons.DIRECTORY_CLOSED_ICON);
     } else {
       setIcon(path.getFileType().getIcon());
     }
   }
 }
コード例 #8
0
 private static boolean directoryOrBinary(final Change change) {
   // todo instead for repository tab, filter directories (? ask remotely ? non leaf nodes)
   /*if ((change.getBeforeRevision() instanceof BinaryContentRevision) || (change.getAfterRevision() instanceof BinaryContentRevision)) {
     changesList.remove(i);
     continue;
   }*/
   final FilePath path = ChangesUtil.getFilePath(change);
   if (path.isDirectory()) {
     return !change.hasOtherLayers();
   }
   /*final FileType type = path.getFileType();
   if ((! FileTypes.UNKNOWN.equals(type)) && (type.isBinary())) {
     return true;
   }*/
   return false;
 }
コード例 #9
0
  private static boolean isEnabled(
      @NotNull Project project, @NotNull FilePath path, @NotNull VirtualFile fileOrParent) {
    boolean result = false;
    AbstractVcs vcs = ChangesUtil.getVcsForFile(fileOrParent, project);

    if (vcs != null) {
      VcsHistoryProvider provider = vcs.getVcsHistoryProvider();

      result =
          provider != null
              && (provider.supportsHistoryForDirectories() || !path.isDirectory())
              && AbstractVcs.fileInVcsByFileStatus(project, fileOrParent)
              && provider.canShowHistoryFor(fileOrParent);
    }

    return result;
  }
コード例 #10
0
 @Override
 public boolean isContentAvailable(final VcsFileRevision revision) {
   return !myCommittedPath.isDirectory();
 }