コード例 #1
0
  void saveRemainingPatches(
      final ShelvedChangeList changeList,
      final List<FilePatch> remainingPatches,
      final List<ShelvedBinaryFile> remainingBinaries,
      CommitContext commitContext) {
    final File newPath = getPatchPath(changeList.DESCRIPTION);
    try {
      FileUtil.copy(new File(changeList.PATH), newPath);
    } catch (IOException e) {
      // do not delete if cannot recycle
      return;
    }
    final ShelvedChangeList listCopy =
        new ShelvedChangeList(
            newPath.getAbsolutePath(),
            changeList.DESCRIPTION,
            new ArrayList<ShelvedBinaryFile>(changeList.getBinaryFiles()));
    listCopy.DATE = (changeList.DATE == null) ? null : new Date(changeList.DATE.getTime());

    writePatchesToFile(myProject, changeList.PATH, remainingPatches, commitContext);

    changeList.getBinaryFiles().retainAll(remainingBinaries);
    changeList.clearLoadedChanges();
    recycleChangeList(listCopy, changeList);
    notifyStateChanged();
  }
コード例 #2
0
  public static void readExternal(
      final Element element,
      final List<ShelvedChangeList> changes,
      final List<ShelvedChangeList> recycled)
      throws InvalidDataException {
    changes.addAll(ShelvedChangeList.readChanges(element, false, true));

    recycled.addAll(ShelvedChangeList.readChanges(element, true, true));
  }
コード例 #3
0
 private static void readList(final List<Element> children, final List<ShelvedChangeList> sink)
     throws InvalidDataException {
   for (Element child : children) {
     ShelvedChangeList data = new ShelvedChangeList();
     data.readExternal(child);
     if (new File(data.PATH).exists()) {
       sink.add(data);
     }
   }
 }
コード例 #4
0
 private static List<ShelvedBinaryFile> getBinaryFilesToUnshelve(
     final ShelvedChangeList changeList,
     final List<ShelvedBinaryFile> binaryFiles,
     final List<ShelvedBinaryFile> remainingBinaries) {
   if (binaryFiles == null) {
     return new ArrayList<ShelvedBinaryFile>(changeList.getBinaryFiles());
   }
   ArrayList<ShelvedBinaryFile> result = new ArrayList<ShelvedBinaryFile>();
   for (ShelvedBinaryFile file : changeList.getBinaryFiles()) {
     if (binaryFiles.contains(file)) {
       result.add(file);
     } else {
       remainingBinaries.add(file);
     }
   }
   return result;
 }
コード例 #5
0
 public void deleteChangeList(final ShelvedChangeList changeList) {
   deleteListImpl(changeList);
   if (!changeList.isRecycled()) {
     myShelvedChangeLists.remove(changeList);
   } else {
     myRecycledShelvedChangeLists.remove(changeList);
   }
   notifyStateChanged();
 }
コード例 #6
0
  private void deleteListImpl(final ShelvedChangeList changeList) {
    File file = new File(changeList.PATH);
    myFileProcessor.delete(file.getName());

    for (ShelvedBinaryFile binaryFile : changeList.getBinaryFiles()) {
      final String path = binaryFile.SHELVED_PATH;
      if (path != null) {
        File binFile = new File(path);
        myFileProcessor.delete(binFile.getName());
      }
    }
  }
コード例 #7
0
  private void recycleChangeList(
      final ShelvedChangeList listCopy, final ShelvedChangeList newList) {
    if (newList != null) {
      for (Iterator<ShelvedBinaryFile> shelvedChangeListIterator =
              listCopy.getBinaryFiles().iterator();
          shelvedChangeListIterator.hasNext(); ) {
        final ShelvedBinaryFile binaryFile = shelvedChangeListIterator.next();
        for (ShelvedBinaryFile newBinary : newList.getBinaryFiles()) {
          if (Comparing.equal(newBinary.BEFORE_PATH, binaryFile.BEFORE_PATH)
              && Comparing.equal(newBinary.AFTER_PATH, binaryFile.AFTER_PATH)) {
            shelvedChangeListIterator.remove();
          }
        }
      }
      for (Iterator<ShelvedChange> iterator = listCopy.getChanges(myProject).iterator();
          iterator.hasNext(); ) {
        final ShelvedChange change = iterator.next();
        for (ShelvedChange newChange : newList.getChanges(myProject)) {
          if (Comparing.equal(change.getBeforePath(), newChange.getBeforePath())
              && Comparing.equal(change.getAfterPath(), newChange.getAfterPath())) {
            iterator.remove();
          }
        }
      }

      // needed only if partial unshelve
      try {
        final CommitContext commitContext = new CommitContext();
        final List<FilePatch> patches = new ArrayList<FilePatch>();
        for (ShelvedChange change : listCopy.getChanges(myProject)) {
          patches.add(change.loadFilePatch(myProject, commitContext));
        }
        writePatchesToFile(myProject, listCopy.PATH, patches, commitContext);
      } catch (IOException e) {
        LOG.info(e);
        // left file as is
      } catch (PatchSyntaxException e) {
        LOG.info(e);
        // left file as is
      }
    }

    if ((!listCopy.getBinaryFiles().isEmpty()) || (!listCopy.getChanges(myProject).isEmpty())) {
      listCopy.setRecycled(true);
      myRecycledShelvedChangeLists.add(listCopy);
      notifyStateChanged();
    }
  }
コード例 #8
0
 public void renameChangeList(final ShelvedChangeList changeList, final String newName) {
   changeList.DESCRIPTION = newName;
   notifyStateChanged();
 }
コード例 #9
0
 public void restoreList(final ShelvedChangeList changeList) {
   myShelvedChangeLists.add(changeList);
   myRecycledShelvedChangeLists.remove(changeList);
   changeList.setRecycled(false);
   notifyStateChanged();
 }
コード例 #10
0
 public void writeExternal(Element element) throws WriteExternalException {
   element.setAttribute(ATTRIBUTE_SHOW_RECYCLED, Boolean.toString(myShowRecycled));
   ShelvedChangeList.writeChanges(myShelvedChangeLists, myRecycledShelvedChangeLists, element);
 }