@NotNull
      @Override
      public DiffRequest process(
          @NotNull UserDataHolder context, @NotNull ProgressIndicator indicator)
          throws DiffRequestProducerException, ProcessCanceledException {
        try {
          DiffContent content1;
          DiffContent content2;

          if (FileStatus.ADDED.equals(myFileStatus)) {
            content1 = DiffContentFactory.getInstance().createEmpty();
          } else {
            byte[] bytes1 = loadContent(myFilePointer, myBefore);
            content1 =
                DiffContentFactoryImpl.getInstanceImpl()
                    .createFromBytes(myProject, myFilePath, bytes1);
          }

          if (FileStatus.DELETED.equals(myFileStatus)) {
            content2 = DiffContentFactory.getInstance().createEmpty();
          } else {
            byte[] bytes2 = loadContent(myFilePointer, myAfter);
            content2 =
                DiffContentFactoryImpl.getInstanceImpl()
                    .createFromBytes(myProject, myFilePath, bytes2);
          }

          String title = DiffRequestFactoryImpl.getContentTitle(myFilePath);
          return new SimpleDiffRequest(title, content1, content2, "Before update", "After update");
        } catch (IOException e) {
          throw new DiffRequestProducerException("Can't load content", e);
        }
      }
 /**
  * Get current revision for the file under git
  *
  * @param project a project
  * @param filePath a file path
  * @return a revision number or null if the file is unversioned or new
  * @throws VcsException if there is problem with running git
  */
 @Nullable
 public static ItemLatestState getLastRevision(final Project project, FilePath filePath)
     throws VcsException {
   VirtualFile root = GitUtil.getGitRoot(filePath);
   GitBranch c = GitBranch.current(project, root);
   GitBranch t = c == null ? null : c.tracked(project, root);
   if (t == null) {
     return new ItemLatestState(getCurrentRevision(project, filePath, null), true, false);
   }
   filePath = getLastCommitName(project, filePath);
   GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.LOG);
   GitLogParser parser =
       new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, SHORT_PARENTS);
   h.setNoSSH(true);
   h.setSilent(true);
   h.addParameters("-n1", parser.getPretty(), "--name-status", t.getFullName());
   h.endOptions();
   h.addRelativePaths(filePath);
   String result = h.run();
   if (result.length() == 0) {
     return null;
   }
   GitLogRecord record = parser.parseOneRecord(result);
   if (record == null) {
     return null;
   }
   final List<Change> changes = record.parseChanges(project, root);
   boolean exists = !FileStatus.DELETED.equals(changes.get(0).getFileStatus());
   record.setUsedHandler(h);
   return new ItemLatestState(
       new GitRevisionNumber(record.getHash(), record.getDate()), exists, false);
 }
    public Change next() {
      final Pair<VirtualFilePointer, FileStatus> pair = myVfIterator.next();
      final VirtualFilePointer pointer = pair.getFirst();

      MyCheckpointContentRevision before =
          new MyCheckpointContentRevision(pointer, myBeforeLoader, true);
      MyCheckpointContentRevision after =
          new MyCheckpointContentRevision(pointer, myAfterLoader, false);
      if (FileStatus.ADDED.equals(pair.getSecond())) {
        before = null;
      } else if (FileStatus.DELETED.equals(pair.getSecond())) {
        after = null;
      }
      return new Change(before, after, pair.getSecond());
    }
  private Collection<FilePath> chooseBinaryFiles(List<Change> converted, Set<FilePath> paths) {
    String singleMessage = "";
    if (paths.size() == 1) {
      final Change change = converted.get(0);
      final FileStatus status = change.getFileStatus();
      final FilePath path = ChangesUtil.getFilePath(change);
      final String stringPath = TreeConflictRefreshablePanel.filePath(path);
      if (FileStatus.DELETED.equals(status)) {
        singleMessage = "Delete binary file " + stringPath + " (according to theirs changes)?";
      } else if (FileStatus.ADDED.equals(status)) {
        singleMessage = "Create binary file " + stringPath + " (according to theirs changes)?";
      } else {
        singleMessage =
            "Apply changes to binary file " + stringPath + " (according to theirs changes)?";
      }
    }
    return AbstractVcsHelper.getInstance(myVcs.getProject())
        .selectFilePathsToProcess(
            new ArrayList<FilePath>(paths),
            TreeConflictRefreshablePanel.TITLE,
            "Select binary files to patch",
            TreeConflictRefreshablePanel.TITLE,
            singleMessage,
            new VcsShowConfirmationOption() {

              @Override
              public Value getValue() {
                return null;
              }

              @Override
              public void setValue(Value value) {}

              @Override
              public boolean isPersistent() {
                return false;
              }
            });
  }
  public CommitLegendPanel(InfoCalculator infoCalculator) {
    myInfoCalculator = infoCalculator;
    final Color background = UIUtil.getListBackground();
    myModifiedPanel.setBackground(background);
    myNewPanel.setBackground(background);
    myDeletedPanel.setBackground(background);
    if (UIUtil.isUnderDarcula()) {
      final Color color = UIUtil.getSeparatorColor();
      final TitledBorder border = new TitledBorder(new LineBorder(color, 1));
      myModifiedPanel.setBorder(border);
      myNewPanel.setBorder(border);
      myDeletedPanel.setBorder(border);
    }

    myModifiedLabel.setForeground(FileStatus.MODIFIED.getColor());
    myNewLabel.setForeground(FileStatus.ADDED.getColor());
    myDeletedLabel.setForeground(FileStatus.DELETED.getColor());

    boldLabel(myModifiedLabel, true);
    boldLabel(myNewLabel, true);
    boldLabel(myDeletedLabel, true);
  }
Exemple #6
0
    public void execute(
        final Change change,
        final FilePath filePath,
        final SLRUMap<Pair<Long, String>, List<BeforeAfter<TextRange>>> cache,
        final LineStatusTrackerManagerI lstManager) {
      try {
        myDocument = null;
        myOldDocument = documentFromRevision(change.getBeforeRevision());
        final String convertedPath = FilePathsHelper.convertPath(filePath);
        if (filePath.getVirtualFile() != null) {
          myDocument =
              FileStatus.DELETED.equals(change.getFileStatus())
                  ? new DocumentImpl("")
                  : FileDocumentManager.getInstance().getDocument(filePath.getVirtualFile());
          if (myDocument != null) {
            final List<BeforeAfter<TextRange>> cached =
                cache.get(new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath));
            if (cached != null) {
              myRanges = cached;
              return;
            }
          }
        }

        if (myDocument == null) {
          myDocument = documentFromRevision(change.getAfterRevision());
          final List<BeforeAfter<TextRange>> cached =
              cache.get(new Pair<Long, String>(-1L, convertedPath));
          if (cached != null) {
            myRanges = cached;
            return;
          }
        }

        ComparisonPolicy comparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy();
        if (comparisonPolicy == null) {
          comparisonPolicy = ComparisonPolicy.DEFAULT;
        }
        final TextCompareProcessor processor = new TextCompareProcessor(comparisonPolicy);
        final List<LineFragment> lineFragments =
            processor.process(myOldDocument.getText(), myDocument.getText());
        myRanges = new ArrayList<BeforeAfter<TextRange>>(lineFragments.size());
        for (LineFragment lineFragment : lineFragments) {
          if (!lineFragment.isEqual()) {
            final TextRange oldRange = lineFragment.getRange(FragmentSide.SIDE1);
            final TextRange newRange = lineFragment.getRange(FragmentSide.SIDE2);
            int beforeBegin = myOldDocument.getLineNumber(oldRange.getStartOffset());
            int beforeEnd =
                myOldDocument.getLineNumber(
                    correctRangeEnd(oldRange.getEndOffset(), myOldDocument));
            int afterBegin = myDocument.getLineNumber(newRange.getStartOffset());
            int afterEnd =
                myDocument.getLineNumber(correctRangeEnd(newRange.getEndOffset(), myDocument));
            if (oldRange.isEmpty()) {
              beforeEnd = beforeBegin - 1;
            }
            if (newRange.isEmpty()) {
              afterEnd = afterBegin - 1;
            }
            myRanges.add(
                new BeforeAfter<TextRange>(
                    new UnfairTextRange(beforeBegin, beforeEnd),
                    new UnfairTextRange(afterBegin, afterEnd)));
          }
        }
        cache.put(
            new Pair<Long, String>(myDocument.getModificationStamp(), convertedPath),
            new ArrayList<BeforeAfter<TextRange>>(myRanges));
      } catch (VcsException e) {
        myException = e;
      } catch (FilesTooBigForDiffException e) {
        myException = new VcsException(e);
      }
    }