public boolean setReadOnly(final String name, final boolean value) {
   final LocalChangeList list = myMap.get(name);
   if (list != null) {
     list.setReadOnly(value);
   }
   return list != null;
 }
  @Override
  public void rebuildList() {
    if (myInRebuildList) return;
    try {
      myInRebuildList = true;
      if (myChangesToDisplay == null) {
        // changes set not fixed === local changes
        final ChangeListManager manager = ChangeListManager.getInstance(myProject);
        myChangeListsMap = new HashMap<Change, LocalChangeList>();
        final List<LocalChangeList> lists = manager.getChangeListsCopy();
        Collection<Change> allChanges = new ArrayList<Change>();
        for (LocalChangeList list : lists) {
          final Collection<Change> changes = list.getChanges();
          allChanges.addAll(changes);
          for (Change change : changes) {
            myChangeListsMap.put(change, list);
          }
        }
        myAllChanges = allChanges;
        // refresh selected list also
        updateListsInChooser();
      }

      super.rebuildList();
      if (myRebuildListListener != null) {
        myRebuildListListener.run();
      }
    } finally {
      myInRebuildList = false;
    }
  }
  private ChangeListWorker(final ChangeListWorker worker) {
    myProject = worker.myProject;
    myMap = new LinkedHashMap<String, LocalChangeList>();
    myIdx = new ChangeListsIndexes(worker.myIdx);
    myLocallyDeleted = worker.myLocallyDeleted.copy();
    mySwitchedHolder = worker.mySwitchedHolder.copy();
    myDelta = worker.myDelta;
    myListsToDisappear = new LinkedList<String>(worker.myListsToDisappear);

    LocalChangeList defaultList = null;
    for (LocalChangeList changeList : worker.myMap.values()) {
      final LocalChangeList copy = changeList.copy();

      final String changeListName = copy.getName();
      myMap.put(changeListName, copy);
      if (copy.isDefault()) {
        defaultList = copy;
      }
    }
    if (defaultList == null) {
      LOG.info("default list not found when copy");
      defaultList = myMap.get(worker.getDefaultListName());
    }

    if (defaultList == null) {
      LOG.info("default list not found when copy in original object too");
      if (!myMap.isEmpty()) {
        defaultList = myMap.values().iterator().next();
      } else {
        // can be when there's no vcs configured
        /// LOG.error("no changelists at all");
      }
    }
    myDefault = defaultList;
  }
 public Collection<Change> getAllChanges() {
   final Collection<Change> changes = new HashSet<Change>();
   for (LocalChangeList list : myMap.values()) {
     changes.addAll(list.getChanges());
   }
   return changes;
 }
示例#5
0
 public void processChangeLists(final List<LocalChangeList> lists) {
   final ProjectLevelVcsManager plVcsManager =
       ProjectLevelVcsManager.getInstanceChecked(myProject);
   plVcsManager.startBackgroundVcsOperation();
   try {
     final SVNChangelistClient client = createChangelistClient();
     for (LocalChangeList list : lists) {
       if (!list.isDefault()) {
         final Collection<Change> changes = list.getChanges();
         for (Change change : changes) {
           correctListForRevision(
               plVcsManager, change.getBeforeRevision(), client, list.getName());
           correctListForRevision(plVcsManager, change.getAfterRevision(), client, list.getName());
         }
       }
     }
   } finally {
     final Application appManager = ApplicationManager.getApplication();
     if (appManager.isDispatchThread()) {
       appManager.executeOnPooledThread(
           new Runnable() {
             @Override
             public void run() {
               plVcsManager.stopBackgroundVcsOperation();
             }
           });
     } else {
       plVcsManager.stopBackgroundVcsOperation();
     }
   }
 }
 protected void processInChange(Couple<String> key, Change change) {
   final LocalChangeList list = myInternalMap.get(key);
   if (list != null) {
     myIncludedListsCopies.put(list.getName(), list);
     myValidChanges.add(change);
   }
 }
 @Nullable
 public LocalChangeList listForChange(final Change change) {
   for (LocalChangeList list : myMap.values()) {
     if (list.getChanges().contains(change)) return list.copy();
   }
   return null;
 }
  public void testSaveContextOnCommitForExistingTask() throws Exception {
    myTaskManager.getState().saveContextOnCommit = true;

    assertEquals(1, myTaskManager.getLocalTasks().size());

    Task task = myRepository.findTask("TEST-001");
    assertNotNull(task);
    assertEquals(
        1, myChangeListManager.getChangeListsCopy().size()); // default change list should be here
    activateAndCreateChangelist(task);
    myChangeListManager.waitUntilRefreshed();

    assertEquals(2, myTaskManager.getLocalTasks().size());
    List<LocalChangeList> copy = myChangeListManager.getChangeListsCopy();
    assertEquals(copy.toString(), 2, copy.size());
    LocalTask localTask = myTaskManager.getActiveTask();
    List<ChangeListInfo> changelists = localTask.getChangeLists();
    ChangeListInfo info = changelists.get(0);
    LocalChangeList changeList = myChangeListManager.getChangeList(info.id);
    assertNotNull(changeList);

    CommitChangeListDialog.commitChanges(
        getProject(), Collections.<Change>emptyList(), changeList, null, changeList.getName());

    assertEquals(2, myTaskManager.getLocalTasks().size()); // no extra task created
    assertEquals(2, myChangeListManager.getChangeListsCopy().size());

    assertEquals(
        localTask, myTaskManager.getAssociatedTask(changeList)); // association should survive
  }
  public void testRemoveChangelistViaVcsAction() throws Exception {
    Task task = myRepository.findTask("TEST-001");
    assertNotNull(task);
    activateAndCreateChangelist(task);
    myChangeListManager.waitUntilRefreshed();

    LocalTask defaultTask = myTaskManager.findTask(LocalTaskImpl.DEFAULT_TASK_ID);
    assertNotNull(defaultTask);
    activateAndCreateChangelist(defaultTask);
    myChangeListManager.waitUntilRefreshed();
    assertEquals(defaultTask, myTaskManager.getActiveTask());

    LocalTask anotherTask = myTaskManager.findTask("TEST-001");
    assertNotNull(anotherTask);

    LocalChangeList defaultChangeList =
        myChangeListManager.findChangeList(LocalChangeList.DEFAULT_NAME);
    assertNotNull(defaultChangeList);
    LocalChangeList anotherChangeList = myChangeListManager.findChangeList("TEST-001 Summary");
    assertNotNull(anotherChangeList);
    removeChangeList(anotherChangeList);

    assertEquals(1, anotherTask.getChangeLists().size());
    assertEquals(1, defaultTask.getChangeLists().size());
    assertEquals(1, myChangeListManager.getChangeListsCopy().size());

    assertEquals(defaultTask, myTaskManager.getAssociatedTask(defaultChangeList));
    assertEquals(LocalChangeList.DEFAULT_NAME, defaultChangeList.getName());
  }
 public List<LocalChangeList> getListsCopy() {
   final List<LocalChangeList> result = new ArrayList<LocalChangeList>();
   for (LocalChangeList list : myMap.values()) {
     result.add(list.copy());
   }
   return result;
 }
 private static String debugRealListContent(final LocalChangeList list) {
   final StringBuilder sb = new StringBuilder(list.getName() + ": ");
   final Collection<Change> changeCollection = list.getChanges();
   for (Change change : changeCollection) {
     sb.append(change.toString()).append(' ');
   }
   return sb.toString();
 }
 @Nullable
 public LocalChangeList getChangeList(String id) {
   for (LocalChangeList changeList : myMap.values()) {
     if (changeList.getId().equals(id)) {
       return changeList.copy();
     }
   }
   return null;
 }
 private void preparation() {
   for (LocalChangeList list : myMap.values()) {
     final Collection<Change> managerChanges = list.getChanges();
     final LocalChangeList copy = list.copy();
     for (Change change : managerChanges) {
       myInternalMap.put(keyForChange(change), copy);
     }
   }
 }
 @Override
 public void trackContext(LocalChangeList changeList) {
   ChangeListInfo changeListInfo = new ChangeListInfo(changeList);
   String changeListName = changeList.getName();
   LocalTaskImpl task = createLocalTask(changeListName);
   task.addChangelist(changeListInfo);
   addTask(task);
   if (changeList.isDefault()) {
     activateTask(task, false);
   }
 }
示例#15
0
  private Intersection getMergeAllIntersection(List<LocalChangeList> localChangeLists) {
    final Intersection intersection = new Intersection();

    for (LocalChangeList localChangeList : localChangeLists) {
      final Collection<Change> localChanges = localChangeList.getChanges();
      for (Change localChange : localChanges) {
        intersection.add(localChangeList.getName(), localChangeList.getComment(), localChange);
      }
    }
    return intersection;
  }
 protected void processInChange(Couple<String> key, Change change) {
   LocalChangeList tmpList = myInternalMap.get(key);
   if (tmpList == null) {
     tmpList = myDefaultCopy;
   }
   final String tmpName = tmpList.getName();
   List<Change> list = myListToChangesMap.get(tmpName);
   if (list == null) {
     list = new ArrayList<Change>();
     myListToChangesMap.put(tmpName, list);
     myIncludedListsCopies.put(tmpName, tmpList);
   }
   list.add(change);
 }
 private void createChangeList(LocalTask task, String name, @Nullable String comment) {
   LocalChangeList changeList = myChangeListManager.findChangeList(name);
   if (changeList == null) {
     changeList = myChangeListManager.addChangeList(name, comment);
   } else {
     final LocalTask associatedTask = getAssociatedTask(changeList);
     if (associatedTask != null) {
       associatedTask.removeChangelist(new ChangeListInfo(changeList));
     }
     changeList.setComment(comment);
   }
   task.addChangelist(new ChangeListInfo(changeList));
   myChangeListManager.setDefaultChangeList(changeList);
 }
 public LocalChangeList getListCopy(@NotNull final VirtualFile file) {
   for (LocalChangeList list : myMap.values()) {
     for (Change change : list.getChanges()) {
       if (change.getAfterRevision() != null
           && Comparing.equal(change.getAfterRevision().getFile().getVirtualFile(), file)) {
         return list.copy();
       }
       if (change.getBeforeRevision() != null
           && Comparing.equal(change.getBeforeRevision().getFile().getVirtualFile(), file)) {
         return list.copy();
       }
     }
   }
   return null;
 }
  LocalChangeList addChangeList(
      String id,
      @NotNull final String name,
      @Nullable final String description,
      final boolean inUpdate,
      @Nullable Object data) {
    final boolean contains = myMap.containsKey(name);
    LOG.assertTrue(!contains, "Attempt to create duplicate changelist " + name);
    final LocalChangeListImpl newList =
        (LocalChangeListImpl) LocalChangeList.createEmptyChangeList(myProject, name);
    newList.setData(data);

    if (description != null) {
      newList.setCommentImpl(description);
    }
    if (id != null) {
      newList.setId(id);
    }
    myMap.put(name, newList);
    if (inUpdate) {
      // scope is not important: nothing had been added jet, nothing to move to "old state" members
      newList.startProcessingChanges(
          myProject, null); // this is executed only when use through GATE
    }
    return newList.copy();
  }
 @Nullable
 public Change getChangeForPath(final FilePath file) {
   for (LocalChangeList list : myMap.values()) {
     for (Change change : list.getChanges()) {
       final ContentRevision afterRevision = change.getAfterRevision();
       if (afterRevision != null && afterRevision.getFile().equals(file)) {
         return change;
       }
       final ContentRevision beforeRevision = change.getBeforeRevision();
       if (beforeRevision != null && beforeRevision.getFile().equals(file)) {
         return change;
       }
     }
   }
   return null;
 }
 public boolean editName(@NotNull final String fromName, @NotNull final String toName) {
   if (fromName.equals(toName)) return false;
   final LocalChangeList list = myMap.get(fromName);
   final boolean canEdit = list != null && (!list.isReadOnly());
   if (canEdit) {
     final LocalChangeListImpl listImpl = (LocalChangeListImpl) list;
     listImpl.setNameImpl(toName);
     myMap.remove(fromName);
     myMap.put(toName, list);
     final ChangeListEditHandler editHandler = listImpl.getEditHandler();
     if (editHandler != null) {
       listImpl.setCommentImpl(
           editHandler.changeCommentOnChangeName(toName, listImpl.getComment()));
     }
   }
   return canEdit;
 }
 @Nullable
 private static Consumer<Collection<FilePath>> createMover(
     final Project project, final LocalChangeList targetChangeList) {
   final ChangeListManager clm = ChangeListManager.getInstance(project);
   if (targetChangeList == null || clm.getDefaultListName().equals(targetChangeList.getName()))
     return null;
   return new FilesMover(clm, targetChangeList);
 }
  public void removeRegisteredChangeFor(FilePath path) {
    myIdx.remove(path);

    for (LocalChangeList list : myMap.values()) {
      for (Change change : list.getChanges()) {
        final ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null && afterRevision.getFile().equals(path)) {
          ((LocalChangeListImpl) list).removeChange(change);
          return;
        }
        final ContentRevision beforeRevision = change.getBeforeRevision();
        if (beforeRevision != null && beforeRevision.getFile().equals(path)) {
          ((LocalChangeListImpl) list).removeChange(change);
          return;
        }
      }
    }
  }
  public boolean removeChangeList(@NotNull String name) {
    final LocalChangeList list = myMap.get(name);
    if (list == null) {
      return false;
    }
    if (list.isDefault()) {
      throw new RuntimeException(
          new IncorrectOperationException("Cannot remove default changelist"));
    }
    final String listName = list.getName();

    for (Change change : list.getChanges()) {
      ((LocalChangeListImpl) myDefault).addChange(change);
    }

    final LocalChangeList removed = myMap.remove(listName);
    return true;
  }
  public void notifyDoneProcessingChanges(final ChangeListListener dispatcher) {
    List<ChangeList> changedLists = new ArrayList<ChangeList>();
    final Map<LocalChangeListImpl, List<Change>> removedChanges =
        new HashMap<LocalChangeListImpl, List<Change>>();
    final Map<LocalChangeListImpl, List<Change>> addedChanges =
        new HashMap<LocalChangeListImpl, List<Change>>();
    for (LocalChangeList list : myMap.values()) {
      final List<Change> removed = new ArrayList<Change>();
      final List<Change> added = new ArrayList<Change>();
      final LocalChangeListImpl listImpl = (LocalChangeListImpl) list;
      if (listImpl.doneProcessingChanges(removed, added)) {
        changedLists.add(list);
      }
      if (!removed.isEmpty()) {
        removedChanges.put(listImpl, removed);
      }
      if (!added.isEmpty()) {
        addedChanges.put(listImpl, added);
      }
    }
    for (Map.Entry<LocalChangeListImpl, List<Change>> entry : removedChanges.entrySet()) {
      dispatcher.changesRemoved(entry.getValue(), entry.getKey());
    }
    for (Map.Entry<LocalChangeListImpl, List<Change>> entry : addedChanges.entrySet()) {
      dispatcher.changesAdded(entry.getValue(), entry.getKey());
    }
    for (ChangeList changeList : changedLists) {
      dispatcher.changeListChanged(changeList);
    }
    mySwitchedHolder.calculateChildren();

    for (String name : myListsToDisappear) {
      final LocalChangeList changeList = myMap.get(name);
      if ((changeList != null)
          && changeList.getChanges().isEmpty()
          && (!changeList.isReadOnly())
          && (!changeList.isDefault())) {
        removeChangeList(name);
      }
    }
    myListsToDisappear.clear();
  }
示例#26
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;
    }
  public static void checkFilesAreInList(
      final String listName, final ChangeListManager manager, final VirtualFile... files) {
    assert manager.findChangeList(listName) != null;
    final LocalChangeList list = manager.findChangeList(listName);
    final Collection<Change> changes = list.getChanges();
    assert changes.size() == files.length
        : "size: " + changes.size() + " " + debugRealListContent(list);

    for (Change change : changes) {
      final VirtualFile vf = change.getAfterRevision().getFile().getVirtualFile();
      boolean found = false;
      for (VirtualFile file : files) {
        if (file.equals(vf)) {
          found = true;
          break;
        }
      }
      assert found == true : debugRealListContent(list);
    }
  }
 @Override
 public void onChangeListSelected(LocalChangeList list) {
   Object data = list.getData();
   if (data instanceof VcsFullCommitDetails) {
     VcsFullCommitDetails commit = (VcsFullCommitDetails) data;
     String author =
         String.format("%s <%s>", commit.getAuthor().getName(), commit.getAuthor().getEmail());
     myAuthor.getEditor().setItem(author);
     myAuthorDate = new Date(commit.getTime());
   }
 }
  public static void checkDeletedFilesAreInList(
      final VirtualFile[] files, final String listName, final ChangeListManager manager) {
    assert manager.findChangeList(listName) != null;
    final LocalChangeList list = manager.findChangeList(listName);
    final Collection<Change> changes = list.getChanges();
    assert changes.size() == files.length : debugRealListContent(list);

    for (Change change : changes) {
      final File vf = change.getBeforeRevision().getFile().getIOFile();
      boolean found = false;
      for (VirtualFile vfile : files) {
        final File file = new File(vfile.getPath());
        if (file.equals(vf)) {
          found = true;
          break;
        }
      }
      assert found == true : debugRealListContent(list);
    }
  }
 @Nullable
 public MultiMap<LocalChangeList, Change> moveChangesTo(
     final String name, final Change[] changes) {
   final LocalChangeListImpl changeList = (LocalChangeListImpl) myMap.get(name);
   if (changeList != null) {
     final MultiMap<LocalChangeList, Change> result = new MultiMap<LocalChangeList, Change>();
     for (LocalChangeList list : myMap.values()) {
       if (list.equals(changeList)) continue;
       for (Change change : changes) {
         final Change removedChange = ((LocalChangeListImpl) list).removeChange(change);
         if (removedChange != null) {
           changeList.addChange(removedChange);
           result.putValue(list, removedChange);
         }
       }
     }
     return result;
   }
   return null;
 }