コード例 #1
0
  @NotNull
  public Change[] getSelectedChanges() {
    Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) {
      return new Change[0];
    }

    for (TreePath path : paths) {
      ChangesBrowserNode<?> node = (ChangesBrowserNode) path.getLastPathComponent();
      changes.addAll(node.getAllChangesUnder());
    }

    if (changes.isEmpty()) {
      final List<VirtualFile> selectedModifiedWithoutEditing = getSelectedModifiedWithoutEditing();
      if (selectedModifiedWithoutEditing != null && !selectedModifiedWithoutEditing.isEmpty()) {
        for (VirtualFile file : selectedModifiedWithoutEditing) {
          AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
          if (vcs == null) continue;
          final VcsCurrentRevisionProxy before =
              VcsCurrentRevisionProxy.create(file, myProject, vcs.getKeyInstanceMethod());
          if (before != null) {
            ContentRevision afterRevision = new CurrentContentRevision(new FilePathImpl(file));
            changes.add(new Change(before, afterRevision, FileStatus.HIJACKED));
          }
        }
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
コード例 #2
0
  private Change[] getLeadSelection() {
    final Set<Change> changes = new LinkedHashSet<Change>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) return new Change[0];

    for (TreePath path : paths) {
      ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
      if (node instanceof ChangesBrowserChangeNode) {
        changes.add(((ChangesBrowserChangeNode) node).getUserObject());
      }
    }

    return changes.toArray(new Change[changes.size()]);
  }
コード例 #3
0
 public Collection<AbstractVcs> getAffectedVcses() {
   final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
   final Set<AbstractVcs> vcses =
       new HashSet<AbstractVcs>(Arrays.asList(vcsManager.getAllActiveVcss()));
   final Set<AbstractVcs> result = new HashSet<AbstractVcs>();
   for (Change change : myBrowser.myAllChanges) {
     if (vcses.isEmpty()) break;
     final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, myBrowser.myProject);
     if (vcs != null) {
       result.add(vcs);
       vcses.remove(vcs);
     }
   }
   return result;
 }
コード例 #4
0
  @NotNull
  private ChangeList[] getSelectedChangeLists() {
    Set<ChangeList> lists = new HashSet<ChangeList>();

    final TreePath[] paths = getSelectionPaths();
    if (paths == null) return new ChangeList[0];

    for (TreePath path : paths) {
      ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
      final Object userObject = node.getUserObject();
      if (userObject instanceof ChangeList) {
        lists.add((ChangeList) userObject);
      }
    }

    return lists.toArray(new ChangeList[lists.size()]);
  }
コード例 #5
0
 @Nullable
 private List<Task> getIssuesFromRepositories(
     @Nullable String request,
     int max,
     long since,
     boolean forceRequest,
     @NotNull final ProgressIndicator cancelled) {
   List<Task> issues = null;
   for (final TaskRepository repository : getAllRepositories()) {
     if (!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository))) {
       continue;
     }
     try {
       Task[] tasks = repository.getIssues(request, max, since, cancelled);
       myBadRepositories.remove(repository);
       if (issues == null) issues = new ArrayList<Task>(tasks.length);
       if (!repository.isSupported(TaskRepository.NATIVE_SEARCH) && request != null) {
         List<Task> filteredTasks =
             TaskSearchSupport.filterTasks(request, ContainerUtil.list(tasks));
         ContainerUtil.addAll(issues, filteredTasks);
       } else {
         ContainerUtil.addAll(issues, tasks);
       }
     } catch (ProcessCanceledException ignored) {
       // OK
     } catch (Exception e) {
       String reason = "";
       // Fix to IDEA-111810
       if (e.getClass() == Exception.class) {
         // probably contains some message meaningful to end-user
         reason = e.getMessage();
       }
       //noinspection InstanceofCatchParameter
       if (e instanceof SocketTimeoutException) {
         LOG.warn("Socket timeout from " + repository);
       } else {
         LOG.warn("Cannot connect to " + repository, e);
       }
       myBadRepositories.add(repository);
       if (forceRequest) {
         notifyAboutConnectionFailure(repository, reason);
       }
     }
   }
   return issues;
 }
コード例 #6
0
    @Nullable
    private Intersection checkIntersection(
        @Nullable final List<CommittedChangeList> lists, List<LocalChangeList> localChangeLists) {
      if (lists == null || lists.isEmpty()) {
        return null;
      }
      final Set<FilePath> mergePaths = new HashSet<FilePath>();
      for (CommittedChangeList list : lists) {
        final SvnChangeList svnList = (SvnChangeList) list;
        final List<String> paths = new ArrayList<String>(svnList.getAddedPaths());
        paths.addAll(svnList.getChangedPaths());
        paths.addAll(svnList.getDeletedPaths());
        for (String path : paths) {
          final File localPath = getLocalPath(path);
          if (localPath != null) {
            mergePaths.add(new FilePathImpl(localPath, false));
          }
        }
      }

      final Intersection intersection = new Intersection();
      for (LocalChangeList localChangeList : localChangeLists) {
        final Collection<Change> localChanges = localChangeList.getChanges();

        for (Change localChange : localChanges) {
          final FilePath before =
              localChange.getBeforeRevision() == null
                  ? null
                  : localChange.getBeforeRevision().getFile();
          final FilePath after =
              localChange.getAfterRevision() == null
                  ? null
                  : localChange.getAfterRevision().getFile();

          if ((before != null && mergePaths.contains(before))
              || (after != null && mergePaths.contains(after))) {
            intersection.add(localChangeList.getName(), localChangeList.getComment(), localChange);
          }
        }
      }
      return intersection;
    }
コード例 #7
0
 public List<VcsException> commit(
     @NotNull List<Change> changes,
     @NotNull String message,
     @NotNull NullableFunction<Object, Object> parametersHolder,
     Set<String> feedback) {
   List<VcsException> exceptions = new ArrayList<VcsException>();
   Map<VirtualFile, Collection<Change>> sortedChanges = sortChangesByGitRoot(changes, exceptions);
   log.assertTrue(
       !sortedChanges.isEmpty(), "Trying to commit an empty list of changes: " + changes);
   for (Map.Entry<VirtualFile, Collection<Change>> entry : sortedChanges.entrySet()) {
     final VirtualFile root = entry.getKey();
     try {
       File messageFile = createMessageFile(root, message);
       try {
         final Set<FilePath> added = new HashSet<FilePath>();
         final Set<FilePath> removed = new HashSet<FilePath>();
         for (Change change : entry.getValue()) {
           switch (change.getType()) {
             case NEW:
             case MODIFICATION:
               added.add(change.getAfterRevision().getFile());
               break;
             case DELETED:
               removed.add(change.getBeforeRevision().getFile());
               break;
             case MOVED:
               FilePath afterPath = change.getAfterRevision().getFile();
               FilePath beforePath = change.getBeforeRevision().getFile();
               added.add(afterPath);
               if (!GitFileUtils.shouldIgnoreCaseChange(
                   afterPath.getPath(), beforePath.getPath())) {
                 removed.add(beforePath);
               }
               break;
             default:
               throw new IllegalStateException("Unknown change type: " + change.getType());
           }
         }
         try {
           try {
             Set<FilePath> files = new HashSet<FilePath>();
             files.addAll(added);
             files.addAll(removed);
             commit(
                 myProject,
                 root,
                 files,
                 messageFile,
                 myNextCommitAuthor,
                 myNextCommitAmend,
                 myNextCommitAuthorDate);
           } catch (VcsException ex) {
             PartialOperation partialOperation = isMergeCommit(ex);
             if (partialOperation == PartialOperation.NONE) {
               throw ex;
             }
             if (!mergeCommit(
                 myProject,
                 root,
                 added,
                 removed,
                 messageFile,
                 myNextCommitAuthor,
                 exceptions,
                 partialOperation)) {
               throw ex;
             }
           }
         } finally {
           if (!messageFile.delete()) {
             log.warn("Failed to remove temporary file: " + messageFile);
           }
         }
       } catch (VcsException e) {
         exceptions.add(e);
       }
     } catch (IOException ex) {
       //noinspection ThrowableInstanceNeverThrown
       exceptions.add(new VcsException("Creation of commit message file failed", ex));
     }
   }
   if (myNextCommitIsPushed != null
       && myNextCommitIsPushed.booleanValue()
       && exceptions.isEmpty()) {
     // push
     UIUtil.invokeLaterIfNeeded(
         new Runnable() {
           public void run() {
             GitPusher.showPushDialogAndPerformPush(
                 myProject, ServiceManager.getService(myProject, GitPlatformFacade.class));
           }
         });
   }
   return exceptions;
 }