Java Code Examples for com.intellij.openapi.vcs.changes.Change#getBeforeRevision()

The following examples show how to use com.intellij.openapi.vcs.changes.Change#getBeforeRevision() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommittedChangesTreeBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addOrReplaceChange(final List<Change> changes, final Change c) {
  final ContentRevision beforeRev = c.getBeforeRevision();
  // todo!!! further improvements needed
  if (beforeRev != null) {
    final String beforeName = beforeRev.getFile().getName();
    final String beforeAbsolutePath = beforeRev.getFile().getIOFile().getAbsolutePath();
    for (Change oldChange : changes) {
      ContentRevision rev = oldChange.getAfterRevision();
      // first compare name, which is many times faster - to remove 99% not matching
      if (rev != null && (rev.getFile().getName().equals(beforeName)) && rev.getFile().getIOFile().getAbsolutePath().equals(beforeAbsolutePath)) {
        changes.remove(oldChange);
        if (oldChange.getBeforeRevision() != null || c.getAfterRevision() != null) {
          changes.add(new Change(oldChange.getBeforeRevision(), c.getAfterRevision()));
        }
        return;
      }
    }
  }
  changes.add(c);
}
 
Example 2
Source File: VcsLogStructureFilterImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matches(@Nonnull VcsCommitMetadata details) {
  if ((details instanceof VcsFullCommitDetails)) {
    for (Change change : ((VcsFullCommitDetails)details).getChanges()) {
      ContentRevision before = change.getBeforeRevision();
      if (before != null && matches(before.getFile().getPath())) {
        return true;
      }
      ContentRevision after = change.getAfterRevision();
      if (after != null && matches(after.getFile().getPath())) {
        return true;
      }
    }
    return false;
  }
  else {
    return false;
  }
}
 
Example 3
Source File: TFSRollbackEnvironment.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
public void rollbackChanges(final List<Change> changes,
                            final List<VcsException> vcsExceptions,
                            @NotNull final RollbackProgressListener listener) {
    logger.info("rollbackChanges started");
    final List<FilePath> localPaths = new ArrayList<FilePath>();

    listener.determinate();
    for (final Change change : changes) {
        final ContentRevision revision = change.getType() == Change.Type.DELETED ? change.getBeforeRevision() : change.getAfterRevision();
        localPaths.add(revision.getFile());
    }

    undoPendingChanges(localPaths, vcsExceptions, listener);
    logger.info("rollbackChanges ended");
}
 
Example 4
Source File: TodoCheckinHandlerWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void execute() {
  for (Change change : changes) {
    ProgressManager.checkCanceled();
    if (change.getAfterRevision() == null) continue;
    final VirtualFile afterFile = getFileWithRefresh(change.getAfterRevision().getFile());
    if (afterFile == null || afterFile.isDirectory() || afterFile.getFileType().isBinary()) continue;
    myPsiFile = null;

    if (afterFile.isValid()) {
      myPsiFile = ApplicationManager.getApplication().runReadAction(new Computable<PsiFile>() {
        @Override
        public PsiFile compute() {
          return myPsiManager.findFile(afterFile);
        }
      });
    }
    if (myPsiFile == null) {
      mySkipped.add(Pair.create(change.getAfterRevision().getFile(), ourInvalidFile));
      continue;
    }

    myNewTodoItems = new ArrayList<TodoItem>(Arrays.asList(
            ApplicationManager.getApplication().runReadAction(new Computable<TodoItem[]>() {
              @Override
              public TodoItem[] compute() {
                return mySearchHelper.findTodoItems(myPsiFile);
              }
            })));
    applyFilterAndRemoveDuplicates(myNewTodoItems, myTodoFilter);
    if (change.getBeforeRevision() == null) {
      // take just all todos
      if (myNewTodoItems.isEmpty()) continue;
      myAddedOrEditedTodos.addAll(myNewTodoItems);
    }
    else {
      myEditedFileProcessor.process(change, myNewTodoItems);
    }
  }
}
 
Example 5
Source File: SelectFilesToAddTextsToPatchPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Set<Change> getBig(List<Change> changes) {
  final Set<Change> exclude = new HashSet<>();
  for (Change change : changes) {
    // try to estimate size via VF: we assume that base content hasn't been changed much
    VirtualFile virtualFile = getVfFromChange(change);
    if (virtualFile != null) {
      if (isBig(virtualFile)) {
        exclude.add(change);
      }
      continue;
    }
    // otherwise, to avoid regression we have to process context length
    ContentRevision beforeRevision = change.getBeforeRevision();
    if (beforeRevision != null) {
      try {
        String content = beforeRevision.getContent();
        if (content == null) {
          final FilePath file = beforeRevision.getFile();
          LOG.info("null content for " + (file.getPath()) + ", is dir: " + (file.isDirectory()));
          continue;
        }
        if (content.length() > VcsConfiguration.ourMaximumFileForBaseRevisionSize) {
          exclude.add(change);
        }
      }
      catch (VcsException e) {
        LOG.info(e);
      }
    }
  }
  return exclude;
}
 
Example 6
Source File: VcsAwareFormatChangedTextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private static String getRevisionedContentFrom(@Nonnull Change change) {
  ContentRevision revision = change.getBeforeRevision();
  if (revision == null) {
    return null;
  }

  try {
    return revision.getContent();
  }
  catch (VcsException e) {
    LOG.error("Can't get content for: " + change.getVirtualFile(), e);
    return null;
  }
}
 
Example 7
Source File: VcsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param change "Change" description.
 * @return Return true if the "Change" object is created for "Rename" operation:
 *         in this case name of files for "before" and "after" revisions must not
 *         coniside.
 */
public static boolean isRenameChange(Change change) {
  boolean isRenamed = false;
  ContentRevision before = change.getBeforeRevision();
  ContentRevision after = change.getAfterRevision();
  if (before != null && after != null) {
    String prevFile = getCanonicalLocalPath(before.getFile().getPath());
    String newFile = getCanonicalLocalPath(after.getFile().getPath());
    isRenamed = !prevFile.equals(newFile);
  }
  return isRenamed;
}
 
Example 8
Source File: VcsChangesLazilyParsedDetails.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Collection<Couple<String>> getRenamedPaths() {
  Set<Couple<String>> renames = ContainerUtil.newHashSet();
  for (Change change : getChanges()) {
    if (change.getType().equals(Change.Type.MOVED)) {
      if (change.getAfterRevision() != null && change.getBeforeRevision() != null) {
        renames.add(Couple.of(change.getBeforeRevision().getFile().getPath(), change.getAfterRevision().getFile().getPath()));
      }
    }
  }
  return renames;
}
 
Example 9
Source File: VcsChangesLazilyParsedDetails.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Collection<String> getModifiedPaths() {
  Set<String> changedPaths = ContainerUtil.newHashSet();
  for (Change change : getChanges()) {
    if (change.getAfterRevision() != null) changedPaths.add(change.getAfterRevision().getFile().getPath());
    if (change.getBeforeRevision() != null) changedPaths.add(change.getBeforeRevision().getFile().getPath());
  }
  return changedPaths;
}
 
Example 10
Source File: MockChangelistBuilder.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private void addChange(@Nullable String changeListName, @NotNull Change change) {
    addedChanges.put(changeListName, change);
    if (change.getBeforeRevision() != null) {
        addedChangedFiles.put(changeListName, change.getBeforeRevision().getFile());
    }
    if (change.getAfterRevision() != null) {
        addedChangedFiles.put(changeListName, change.getAfterRevision().getFile());
    }
}
 
Example 11
Source File: SubmitModel.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
private List<OptionalClientServerConfig> getConfigsForChanges(Collection<Change> changes) {
    ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project);
    if (registry == null) {
        return Collections.emptyList();
    }
    List<FilePath> files = new ArrayList<>(changes.size() * 2);
    for (Change change : changes) {
        ContentRevision before = change.getBeforeRevision();
        if (before != null) {
            files.add(before.getFile());
        }
        ContentRevision after = change.getAfterRevision();
        if (after != null) {
            files.add(after.getFile());
        }
    }
    // We only need the unique servers; multiples of the same server will result
    // in excessive job queries.  Instead, we'll find one of the clients associated
    // with each server.
    Map<P4ServerName, OptionalClientServerConfig> configs = new HashMap<>();
    for (FilePath file : files) {
        ClientConfigRoot config = registry.getClientFor(file);
        if (config != null && !configs.containsKey(config.getServerConfig().getServerName())) {
            configs.put(
                    config.getServerConfig().getServerName(),
                    new OptionalClientServerConfig(config.getClientConfig()));
        }
    }
    return new ArrayList<>(configs.values());
}
 
Example 12
Source File: VcsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean isChangeForFolder(Change change) {
  ContentRevision revB = change.getBeforeRevision();
  ContentRevision revA = change.getAfterRevision();
  return (revA != null && revA.getFile().isDirectory()) || (revB != null && revB.getFile().isDirectory());
}
 
Example 13
Source File: RefreshVFsSynchronously.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean afterNull(Change change) {
  return change.getBeforeRevision() == null;
}
 
Example 14
Source File: RefreshVFsSynchronously.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean beforeNull(Change change) {
  return change.getBeforeRevision() == null;
}
 
Example 15
Source File: ChangeForDiffConvertor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DiffRequestPresentable convert(final Change ch, final boolean forceText) {
  if (ch.hasOtherLayers() && myRecursive) {
    return new MultipleDiffRequestPresentable(myProject, ch);
  }
  if (ChangesUtil.isTextConflictingChange(ch)) {
    final AbstractVcs vcs = ChangesUtil.getVcsForChange(ch, myProject);
    final MergeProvider mergeProvider = vcs.getMergeProvider();
    if (mergeProvider == null) return null;
    final FilePath path = ChangesUtil.getFilePath(ch);
    VirtualFile vf = path.getVirtualFile();
    if (vf == null) {
      path.hardRefresh();
      vf = path.getVirtualFile();
    }
    if (vf == null) return null;

    return new ConflictedDiffRequestPresentable(myProject, vf, ch);
  } else {
    if (forceText) {
      if (ch.getBeforeRevision() != null && ch.getAfterRevision() != null) {
        try {
          if (StringUtil.isEmptyOrSpaces(ch.getBeforeRevision().getContent()) &&
              StringUtil.isEmptyOrSpaces(ch.getAfterRevision().getContent())) {
            return null;
          }
          if (StringUtil.equals(ch.getBeforeRevision().getContent(), ch.getAfterRevision().getContent())) {
            return null;
          }
        }
        catch (VcsException e) {
          //
        }
      }
    }
    final ChangeDiffRequestPresentable presentable = new ChangeDiffRequestPresentable(myProject, ch);
    if (forceText) {
      presentable.setIgnoreDirectoryFlag(true);
    }
    return presentable;
  }
}
 
Example 16
Source File: TFSCheckinEnvironment.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
@Nullable
public List<VcsException> commit(final List<Change> changes,
                                 final String preparedComment,
                                 @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    final List<VcsException> errors = new ArrayList<VcsException>();

    // set progress bar status
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    TFSProgressUtil.setProgressText(progressIndicator, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_STATUS));

    // find files that are to be checked in
    final List<String> files = new ArrayList<String>();
    for (final Change change : changes) {
        String path = null;
        final ContentRevision beforeRevision = change.getBeforeRevision();
        final ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null) {
            path = afterRevision.getFile().getPath();
        } else if (beforeRevision != null) {
            path = beforeRevision.getFile().getPath();
        }
        if (path != null) {
            files.add(path);
        }
    }

    try {
        final ServerContext context = myVcs.getServerContext(true);
        final List<Integer> workItemIds = VcsHelper.getWorkItemIdsFromMessage(preparedComment);
        final String changesetNumber = CommandUtils.checkinFiles(context, files, preparedComment, workItemIds);

        // notify user of success
        final String changesetLink = String.format(UrlHelper.SHORT_HTTP_LINK_FORMATTER, UrlHelper.getTfvcChangesetURI(context.getUri().toString(), changesetNumber),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_LINK_TEXT, changesetNumber));
        VcsNotifier.getInstance(myVcs.getProject()).notifyImportantInfo(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_TITLE),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_MSG, changesetLink), new NotificationListener() {
                    @Override
                    public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent hyperlinkEvent) {
                        BrowserUtil.browse(hyperlinkEvent.getURL());
                    }
                });
    } catch (Exception e) {
        // no notification needs to be done by us for errors, IntelliJ handles that
        logger.warn("Error during checkin", e);
        if (e instanceof TeamServicesException) {
            // get localized message in the case of TeamServicesException otherwise the key will print out instead of the error
            errors.add(new VcsException(LocalizationServiceImpl.getInstance().getExceptionMessage(e)));
        } else {
            errors.add(new VcsException(e));
        }
    }

    return errors;
}
 
Example 17
Source File: VcsUtil.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @param change "Change" description.
 * @return Return true if the "Change" object is created for "New" operation:
 *         "before" revision is obviously NULL, while "after" revision is not.
 */
public static boolean isChangeForNew(Change change) {
  return (change.getBeforeRevision() == null) && (change.getAfterRevision() != null);
}
 
Example 18
Source File: VcsUtil.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @param change "Change" description.
 * @return Return true if the "Change" object is created for "Delete" operation:
 *         "before" revision is NOT NULL, while "after" revision is NULL.
 */
public static boolean isChangeForDeleted(Change change) {
  return (change.getBeforeRevision() != null) && (change.getAfterRevision() == null);
}