@Nullable
  private byte[] loadFromVersionControl(long date, VirtualFile f) {
    try {
      final AbstractVcs vcs = VcsUtil.getVcsFor(myProject, f);
      if (vcs == null) return null;

      final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
      if (historyProvider == null) return null;

      final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
      final VcsHistorySession session = historyProvider.createSessionFor(filePath);
      if (session == null) return null;

      final List<VcsFileRevision> list = session.getRevisionList();

      if (list != null) {
        for (VcsFileRevision revision : list) {
          final Date revisionDate = revision.getRevisionDate();
          if (revisionDate == null) {
            return null;
          }

          if (revisionDate.getTime() < date) {
            return revision.loadContent();
          }
        }
      }
    } catch (Exception e) {
      LOG.info(e);
      return null;
    }
    return null;
  }
  @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()]);
  }
 public UpdateOrStatusOptionsDialog(Project project, Map<Configurable, AbstractVcs> confs) {
   super(project);
   setTitle(getRealTitle());
   myProject = project;
   if (confs.size() == 1) {
     myMainPanel = new JPanel(new BorderLayout());
     final Configurable configurable = confs.keySet().iterator().next();
     addComponent(confs.get(configurable), configurable, BorderLayout.CENTER);
     myMainPanel.add(Box.createVerticalStrut(10), BorderLayout.SOUTH);
   } else {
     myMainPanel = new JBTabbedPane();
     final ArrayList<AbstractVcs> vcses = new ArrayList<>(confs.values());
     Collections.sort(
         vcses,
         new Comparator<AbstractVcs>() {
           public int compare(final AbstractVcs o1, final AbstractVcs o2) {
             return o1.getDisplayName().compareTo(o2.getDisplayName());
           }
         });
     Map<AbstractVcs, Configurable> vcsToConfigurable = revertMap(confs);
     for (AbstractVcs vcs : vcses) {
       addComponent(vcs, vcsToConfigurable.get(vcs), vcs.getDisplayName());
     }
   }
   init();
 }
 public void minus(Pair<String, AbstractVcs> pair) {
   final AbstractVcs vcs = pair.getSecond();
   if (RemoteDifferenceStrategy.ASK_TREE_PROVIDER.equals(vcs.getRemoteDifferenceStrategy())) {
     myRemoteRevisionsStateCache.minus(pair);
   } else {
     myRemoteRevisionsNumbersCache.minus(pair);
   }
 }
 protected boolean checkVcs(final Project project, final Change change) {
   final VirtualFile virtualFile = ChangesUtil.getFilePath(change).getVirtualFile();
   if (virtualFile == null) {
     return false;
   }
   final AbstractVcs vcs = ChangesUtil.getVcsForFile(virtualFile, project);
   return (vcs != null) && SvnVcs17.VCS_NAME.equals(vcs.getName());
 }
 /** @return false if not up to date */
 public boolean isUpToDate(final Change change) {
   final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, myProject);
   if (vcs == null) return true;
   final RemoteDifferenceStrategy strategy = vcs.getRemoteDifferenceStrategy();
   if (RemoteDifferenceStrategy.ASK_TREE_PROVIDER.equals(strategy)) {
     return myRemoteRevisionsStateCache.isUpToDate(change);
   } else {
     return myRemoteRevisionsNumbersCache.isUpToDate(change);
   }
 }
 @Override
 public boolean dvcsUsedInProject() {
   AbstractVcs[] allActiveVcss = getAllActiveVcss();
   for (AbstractVcs activeVcs : allActiveVcss) {
     if (VcsType.distributed.equals(activeVcs.getType())) {
       return true;
     }
   }
   return false;
 }
 public void unregisterVcs(@NotNull AbstractVcs vcs) {
   if (!ApplicationManager.getApplication().isUnitTestMode()
       && myMappings.haveActiveVcs(vcs.getName())) {
     // unlikely
     LOG.warn(
         "Active vcs '" + vcs.getName() + "' is being unregistered. Remove from mappings first.");
   }
   myMappings.beingUnregistered(vcs.getName());
   AllVcses.getInstance(myProject).unregisterManually(vcs);
 }
 @Override
 public AbstractVcs getActiveVcs() {
   AbstractVcs[] vcss = ProjectLevelVcsManager.getInstance(myProject).getAllActiveVcss();
   if (vcss.length == 0) return null;
   for (AbstractVcs vcs : vcss) {
     if (vcs.getType() == VcsType.distributed) {
       return vcs;
     }
   }
   return vcss[0];
 }
 private void updateRoots() {
   final VcsRoot[] roots = myVcsManager.getAllVcsRoots();
   synchronized (myLock) {
     for (VcsRoot root : roots) {
       final AbstractVcs vcs = root.getVcs();
       if (!myKinds.containsKey(vcs.getName())) {
         myKinds.put(vcs.getName(), vcs.getRemoteDifferenceStrategy());
       }
     }
   }
 }
 private static boolean isActionEnabled(final AnActionEvent e) {
   Project project = e.getData(CommonDataKeys.PROJECT);
   if (project == null) return false;
   VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
   if (vFile == null) return false;
   AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
   if (vcs == null || vcs.getCommittedChangesProvider() == null || !vcs.allowsRemoteCalls(vFile)) {
     return false;
   }
   FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(vFile);
   return AbstractVcs.fileInVcsByFileStatus(project, filePath);
 }
  @Override
  protected void actionPerformed(@NotNull VcsContext context) {
    Project project = context.getProject();
    Pair<FilePath, VirtualFile> pair = getPathAndParentFile(context);
    FilePath path = assertNotNull(pair.first);
    VirtualFile fileOrParent = assertNotNull(pair.second);
    AbstractVcs vcs = assertNotNull(ChangesUtil.getVcsForFile(fileOrParent, project));
    VcsHistoryProvider provider = assertNotNull(vcs.getVcsHistoryProvider());

    AbstractVcsHelper.getInstance(project)
        .showFileHistory(provider, vcs.getAnnotationProvider(), path, null, vcs);
  }
  private String getCheckinActionName(final VcsContext dataContext) {
    final Project project = dataContext.getProject();
    if (project == null) return VcsBundle.message("vcs.command.name.checkin");

    final AbstractVcs vcs = getCommonVcsFor(getRoots(dataContext), project);
    if (vcs == null) {
      return VcsBundle.message("vcs.command.name.checkin");
    } else {
      final CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment();
      if (checkinEnvironment == null) {
        return VcsBundle.message("vcs.command.name.checkin");
      }
      return checkinEnvironment.getCheckinOperationName();
    }
  }
    @Override
    public void doAction(int lineNum) {
      LastRevision revision = myRevisions.get(lineNum);
      if (revision == null) return;

      VirtualFile file = getHyperlinkVirtualFile(myHyperlinks.findAllHyperlinksOnLine(lineNum));
      if (file == null) return;

      AbstractVcs vcs = ProjectLevelVcsManager.getInstance(myProject).getVcsFor(file);
      if (vcs != null) {
        VcsRevisionNumber number = revision.getNumber();
        VcsKey vcsKey = vcs.getKeyInstanceMethod();
        ShowAllAffectedGenericAction.showSubmittedFiles(myProject, number, file, vcsKey);
      }
    }
Ejemplo n.º 15
0
 @NotNull
 public Map<VirtualFile, VcsLogProvider> findLogProviders() {
   Map<VirtualFile, VcsLogProvider> logProviders = ContainerUtil.newHashMap();
   VcsLogProvider[] allLogProviders = Extensions.getExtensions(LOG_PROVIDER_EP, myProject);
   for (AbstractVcs vcs : myVcsManager.getAllActiveVcss()) {
     for (VcsLogProvider provider : allLogProviders) {
       if (provider.getSupportedVcs().equals(vcs.getKeyInstanceMethod())) {
         for (VirtualFile root : myVcsManager.getRootsUnderVcs(vcs)) {
           logProviders.put(root, provider);
         }
         break;
       }
     }
   }
   return logProviders;
 }
Ejemplo n.º 16
0
  @Override
  public void deactivate() {
    if (null != myHgRemoteStatusUpdater) {
      myHgRemoteStatusUpdater.deactivate();
      myHgRemoteStatusUpdater = null;
    }
    if (null != myHgCurrentBranchStatusUpdater) {
      myHgCurrentBranchStatusUpdater.deactivate();
      myHgCurrentBranchStatusUpdater = null;
    }
    if (null != myStatusWidget) {
      myStatusWidget.deactivate();
      myStatusWidget = null;
    }
    if (null != myIncomingWidget) {
      myIncomingWidget.deactivate();
      myIncomingWidget = null;
    }
    if (null != myOutgoingWidget) {
      myOutgoingWidget.deactivate();
      myOutgoingWidget = null;
    }
    if (messageBusConnection != null) {
      messageBusConnection.disconnect();
    }

    if (myVFSListener != null) {
      Disposer.dispose(myVFSListener);
      myVFSListener = null;
    }

    super.deactivate();
  }
 @NotNull
 private FileHistoryPanelImpl createFileHistoryPanel(@NotNull VcsHistorySession copy) {
   ContentManager contentManager =
       ProjectLevelVcsManagerEx.getInstanceEx(myVcs.getProject()).getContentManager();
   return new FileHistoryPanelImpl(
       myVcs, myPath, copy, myVcsHistoryProvider, contentManager, myRefresherI);
 }
  private static boolean isEnabled(
      @NotNull Project project, @NotNull FilePath path, @NotNull VirtualFile fileOrParent) {
    boolean result = false;
    AbstractVcs vcs = ChangesUtil.getVcsForFile(fileOrParent, project);

    if (vcs != null) {
      VcsHistoryProvider provider = vcs.getVcsHistoryProvider();

      result =
          provider != null
              && (provider.supportsHistoryForDirectories() || !path.isDirectory())
              && AbstractVcs.fileInVcsByFileStatus(project, fileOrParent)
              && provider.canShowHistoryFor(fileOrParent);
    }

    return result;
  }
 public void reportException(VcsException exception) {
   VcsBalloonProblemNotifier.showOverVersionControlView(
       myVcs.getProject(),
       VcsBundle.message("message.title.could.not.load.file.history")
           + ": "
           + exception.getMessage(),
       MessageType.ERROR);
 }
Ejemplo n.º 20
0
 private static void correctListForRevision(
     final ProjectLevelVcsManager plVcsManager,
     final ContentRevision revision,
     final SVNChangelistClient client,
     final String name) {
   if (revision != null) {
     final FilePath path = revision.getFile();
     final AbstractVcs vcs = plVcsManager.getVcsFor(path);
     if (vcs != null && VCS_NAME.equals(vcs.getName())) {
       try {
         client.doAddToChangelist(new File[] {path.getIOFile()}, SVNDepth.EMPTY, name, null);
       } catch (SVNException e) {
         // left in default list
       }
     }
   }
 }
Ejemplo n.º 21
0
 @Override
 public int hashCode() {
   if (hashcode == 0) {
     hashcode = myPath != null ? myPath.hashCode() : 0;
     hashcode = 31 * hashcode + (myVcs != null ? myVcs.getName().hashCode() : 0);
   }
   return hashcode;
 }
  public void readDirectoryMappings(final Element element) {
    myMappings.clear();

    final List<VcsDirectoryMapping> mappingsList = new ArrayList<VcsDirectoryMapping>();
    boolean haveNonEmptyMappings = false;
    for (Element child : element.getChildren(ELEMENT_MAPPING)) {
      final String vcs = child.getAttributeValue(ATTRIBUTE_VCS);
      if (vcs != null && !vcs.isEmpty()) {
        haveNonEmptyMappings = true;
      }
      VcsDirectoryMapping mapping =
          new VcsDirectoryMapping(child.getAttributeValue(ATTRIBUTE_DIRECTORY), vcs);
      mappingsList.add(mapping);

      Element rootSettingsElement = child.getChild(ELEMENT_ROOT_SETTINGS);
      if (rootSettingsElement != null) {
        String className = rootSettingsElement.getAttributeValue(ATTRIBUTE_CLASS);
        AbstractVcs vcsInstance = findVcsByName(mapping.getVcs());
        if (vcsInstance != null && className != null) {
          final VcsRootSettings rootSettings = vcsInstance.createEmptyVcsRootSettings();
          if (rootSettings != null) {
            try {
              rootSettings.readExternal(rootSettingsElement);
              mapping.setRootSettings(rootSettings);
            } catch (InvalidDataException e) {
              LOG.error(
                  "Failed to load VCS root settings class "
                      + className
                      + " for VCS "
                      + vcsInstance.getClass().getName(),
                  e);
            }
          }
        }
      }
    }
    boolean defaultProject =
        Boolean.TRUE.toString().equals(element.getAttributeValue(ATTRIBUTE_DEFAULT_PROJECT));
    // run autodetection if there's no VCS in default project and
    if (haveNonEmptyMappings || !defaultProject) {
      myMappingsLoaded = true;
    }
    myMappings.setDirectoryMappings(mappingsList);
  }
 private void baseRevisionsOfDvcsIntoContext(
     List<Change> textChanges, CommitContext commitContext) {
   ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(myProject);
   if (vcsManager.dvcsUsedInProject()
       && VcsConfiguration.getInstance(myProject).INCLUDE_TEXT_INTO_SHELF) {
     final Set<Change> big = SelectFilesToAddTextsToPatchPanel.getBig(textChanges);
     final ArrayList<FilePath> toKeep = new ArrayList<FilePath>();
     for (Change change : textChanges) {
       if (change.getBeforeRevision() == null || change.getAfterRevision() == null) continue;
       if (big.contains(change)) continue;
       FilePath filePath = ChangesUtil.getFilePath(change);
       final AbstractVcs vcs = vcsManager.getVcsFor(filePath);
       if (vcs != null && VcsType.distibuted.equals(vcs.getType())) {
         toKeep.add(filePath);
       }
     }
     commitContext.putUserData(BaseRevisionTextPatchEP.ourPutBaseRevisionTextKey, true);
     commitContext.putUserData(BaseRevisionTextPatchEP.ourBaseRevisionPaths, toKeep);
   }
 }
Ejemplo n.º 24
0
 @NotNull
 public static Collection<VcsDirectoryMapping> findRoots(
     @NotNull VirtualFile rootDir, @NotNull Project project) throws IllegalArgumentException {
   if (!rootDir.isDirectory()) {
     throw new IllegalArgumentException(
         "Can't find VCS at the target file system path. Reason: expected to find a directory there but it's not. The path: "
             + rootDir.getParent());
   }
   Collection<VcsRoot> roots =
       ServiceManager.getService(project, VcsRootDetector.class).detect(rootDir);
   Collection<VcsDirectoryMapping> result = ContainerUtilRt.newArrayList();
   for (VcsRoot vcsRoot : roots) {
     VirtualFile vFile = vcsRoot.getPath();
     AbstractVcs rootVcs = vcsRoot.getVcs();
     if (rootVcs != null && vFile != null) {
       result.add(new VcsDirectoryMapping(vFile.getPath(), rootVcs.getName()));
     }
   }
   return result;
 }
Ejemplo n.º 25
0
 @Nullable
 public static PushSupport getPushSupport(@NotNull final AbstractVcs vcs) {
   return ContainerUtil.find(
       Extensions.getExtensions(PushSupport.PUSH_SUPPORT_EP, vcs.getProject()),
       new Condition<PushSupport>() {
         @Override
         public boolean value(final PushSupport support) {
           return support.getVcs().equals(vcs);
         }
       });
 }
  public Map<VirtualFile, RepositoryLocation> getRoots() {
    myContentRoots = myPlManager.getRootsUnderVcs(myVcs);

    List<VirtualFile> roots = new ArrayList<>();
    final List<VcsDirectoryMapping> mappings = myPlManager.getDirectoryMappings(myVcs);
    for (VcsDirectoryMapping mapping : mappings) {
      if (mapping.isDefaultMapping()) {
        if (myVcs.equals(myPlManager.getVcsFor(myProject.getBaseDir()))) {
          roots.add(myProject.getBaseDir());
        }
      } else {
        VirtualFile newFile = LocalFileSystem.getInstance().findFileByPath(mapping.getDirectory());
        if (newFile == null) {
          newFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(mapping.getDirectory());
        }
        if (newFile != null) {
          roots.add(newFile);
        } else {
          LOG.info("Can not file virtual file for root: " + mapping.getDirectory());
        }
      }
    }
    ContainerUtil.addAll(roots, myContentRoots);
    final Map<VirtualFile, RepositoryLocation> result = new HashMap<>();
    for (Iterator<VirtualFile> iterator = roots.iterator(); iterator.hasNext(); ) {
      final VirtualFile vf = iterator.next();
      final RepositoryLocation location =
          myLocationCache.getLocation(myVcs, VcsUtil.getFilePath(vf), false);
      if (location != null) {
        result.put(vf, location);
      } else {
        iterator.remove();
      }
    }
    roots = myVcs.filterUniqueRoots(roots, IntoSelfVirtualFileConvertor.getInstance());
    result.keySet().retainAll(roots);

    logRoots(roots);
    return result;
  }
 private void createOrSelectContentIfNeeded() {
   ToolWindow toolWindow = getToolWindow(myVcs.getProject());
   if (myRefresherI.isFirstTime()) {
     ContentManager manager = toolWindow.getContentManager();
     boolean selectedExistingContent =
         ContentUtilEx.selectContent(manager, myFileHistoryPanel, true);
     if (!selectedExistingContent) {
       ContentUtilEx.addTabbedContent(
           manager, myFileHistoryPanel, "History", myPath.getName(), true);
     }
     toolWindow.activate(null);
   }
 }
Ejemplo n.º 28
0
  @Nullable
  private static VirtualFile guessRootForVcs(
      @NotNull Project project, @Nullable AbstractVcs vcs, @Nullable String defaultRootPathValue) {
    if (project.isDisposed()) return null;
    LOG.debug("Guessing vcs root...");
    ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    if (vcs == null) {
      LOG.debug("Vcs not found.");
      return null;
    }
    String vcsName = vcs.getDisplayName();
    VirtualFile[] vcsRoots = vcsManager.getRootsUnderVcs(vcs);
    if (vcsRoots.length == 0) {
      LOG.debug("No " + vcsName + " roots in the project.");
      return null;
    }

    if (vcsRoots.length == 1) {
      VirtualFile onlyRoot = vcsRoots[0];
      LOG.debug("Only one " + vcsName + " root in the project, returning: " + onlyRoot);
      return onlyRoot;
    }

    // get remembered last visited repository root
    if (defaultRootPathValue != null) {
      VirtualFile recentRoot = VcsUtil.getVirtualFile(defaultRootPathValue);
      if (recentRoot != null) {
        LOG.debug("Returning the recent root: " + recentRoot);
        return recentRoot;
      }
    }

    // otherwise return the root of the project dir or the root containing the project dir, if there
    // is such
    VirtualFile projectBaseDir = project.getBaseDir();
    if (projectBaseDir == null) {
      VirtualFile firstRoot = vcsRoots[0];
      LOG.debug("Project base dir is null, returning the first root: " + firstRoot);
      return firstRoot;
    }
    VirtualFile rootCandidate;
    for (VirtualFile root : vcsRoots) {
      if (root.equals(projectBaseDir) || VfsUtilCore.isAncestor(root, projectBaseDir, true)) {
        LOG.debug("The best candidate: " + root);
        return root;
      }
    }
    rootCandidate = vcsRoots[0];
    LOG.debug("Returning the best candidate: " + rootCandidate);
    return rootCandidate;
  }
Ejemplo n.º 29
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    FilePathUnderVcs that = (FilePathUnderVcs) o;

    if (myPath != null ? !myPath.equals(that.myPath) : that.myPath != null) return false;
    if (myVcs != null
        ? !Comparing.equal(myVcs.getName(), that.myVcs.getName())
        : that.myVcs != null) return false;

    return true;
  }
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    assert vFile != null;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    assert vcs != null;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    assert provider != null;
    ChangeBrowserSettings settings = provider.createDefaultSettings();
    CommittedChangesFilterDialog dlg =
        new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    dlg.show();
    if (!dlg.isOK()) return;

    int maxCount = 0;
    if (!settings.isAnyFilterSpecified()) {
      int rc =
          Messages.showYesNoCancelDialog(
              project,
              VcsBundle.message("browse.changes.no.filter.prompt"),
              VcsBundle.message("browse.changes.title"),
              VcsBundle.message("browse.changes.show.recent.button"),
              VcsBundle.message("browse.changes.show.all.button"),
              CommonBundle.getCancelButtonText(),
              Messages.getQuestionIcon());
      if (rc == Messages.CANCEL) {
        return;
      }
      if (rc == Messages.YES) {
        maxCount = 50;
      }
    }

    AbstractVcsHelper.getInstance(project)
        .openCommittedChangesTab(vcs, vFile, settings, maxCount, null);
  }