com.intellij.vcsUtil.VcsUtil Java Examples

The following examples show how to use com.intellij.vcsUtil.VcsUtil. 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: StructureFilteringStrategy.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private List<FilePath> getFilePathsUnder(@Nonnull ChangesBrowserNode<?> node) {
  List<FilePath> result = Collections.emptyList();
  Object userObject = node.getUserObject();

  if (userObject instanceof FilePath) {
    result = ContainerUtil.list(((FilePath)userObject));
  }
  else if (userObject instanceof Module) {
    result = Arrays.stream(ModuleRootManager.getInstance((Module)userObject).getContentRoots())
            .map(VcsUtil::getFilePath)
            .collect(Collectors.toList());
  }

  return result;
}
 
Example #2
Source File: ManageWorkspacesModel.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
public void reloadWorkspacesWithProgress(final Server selectedServer) {
    logger.info("Reloading workspaces for server " + selectedServer.getName());

    try {
        VcsUtil.runVcsProcessWithProgress(new VcsRunnable() {
            public void run() throws VcsException {
                reloadWorkspaces(selectedServer);
            }
        }, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_MANAGE_WORKSPACES_RELOAD_MSG, selectedServer.getName()), true, project);
    } catch (VcsException e) {
        logger.warn("Exception while trying to reload workspaces", e);
        Messages.showErrorDialog(project, e.getMessage(),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_MANAGE_WORKSPACES_RELOAD_ERROR_TITLE));
    } finally {
        // always refresh list
        setChangedAndNotify(REFRESH_SERVER);
    }
}
 
Example #3
Source File: ResolveConflictsModel.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * Load the conflicts into the table model
 */
public void loadConflicts() {
    logger.debug("Loading conflicts into the table");
    try {
        final VcsRunnable resolveRunnable = new VcsRunnable() {
            public void run() throws VcsException {
                IdeaHelper.setProgress(ProgressManager.getInstance().getProgressIndicator(), 0.1, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_LOADING_CONFLICTS));
                conflictHelper.findConflicts(ResolveConflictsModel.this);
            }
        };
        VcsUtil.runVcsProcessWithProgress(resolveRunnable, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_LOADING_PROGRESS_BAR), false, project);
    } catch (VcsException e) {
        logger.error("Error while loading conflicts: " + e.getMessage());
        addError(ModelValidationInfo.createWithMessage(TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CONFLICT_LOAD_ERROR)));
    }
}
 
Example #4
Source File: AddAction.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getData(CommonDataKeys.PROJECT);
    final VirtualFile[] files = VcsUtil.getVirtualFiles(anActionEvent);

    final List<VcsException> errors = new ArrayList<VcsException>();
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
        public void run() {
            ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
            errors.addAll(TFSVcs.getInstance(project).getCheckinEnvironment().scheduleUnversionedFilesForAddition(Arrays.asList(files)));
        }
    }, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_ADD_SCHEDULING), false, project);

    if (!errors.isEmpty()) {
        AbstractVcsHelper.getInstance(project).showErrors(errors, TFSVcs.TFVC_NAME);
    }
}
 
Example #5
Source File: ManageWorkspacesModel.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
public void editWorkspaceWithProgress(final Workspace selectedWorkspace, final Runnable update) {
    logger.info("Editing workspace " + selectedWorkspace.getName());

    try {
        VcsUtil.runVcsProcessWithProgress(new VcsRunnable() {
            public void run() throws VcsException {
                editWorkspace(selectedWorkspace, update);
            }
        }, TfPluginBundle.message(TfPluginBundle.KEY_TFVC_MANAGE_WORKSPACES_EDIT_MSG, selectedWorkspace.getName()), true, project);
    } catch (VcsException e) {
        logger.warn("Exception while trying to edit workspace", e);
        Messages.showErrorDialog(project, e.getMessage(),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_MANAGE_WORKSPACES_EDIT_ERROR_TITLE));
    }
    // no refresh needs to be called here because we pass it to the edit workspace dialog to run after the save is complete
}
 
Example #6
Source File: VcsVFSListener.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeFileDeletion(@Nonnull final VirtualFileEvent event) {
  final VirtualFile file = event.getFile();
  if (isEventIgnored(event, true)) {
    return;
  }
  if (!myChangeListManager.isIgnoredFile(file)) {
    addFileToDelete(file);
    return;
  }
  // files are ignored, directories are handled recursively
  if (event.getFile().isDirectory()) {
    final List<VirtualFile> list = new LinkedList<>();
    VcsUtil.collectFiles(file, list, true, isDirectoryVersioningSupported());
    for (VirtualFile child : list) {
      if (!myChangeListManager.isIgnoredFile(child)) {
        addFileToDelete(child);
      }
    }
  }
}
 
Example #7
Source File: PathsVerifier.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean check() throws IOException {
  final String[] pieces = RelativePathCalculator.split(myAfterName);
  final VirtualFile parent = makeSureParentPathExists(pieces);
  if (parent == null) {
    setErrorMessage(fileNotFoundMessage(myAfterName));
    return false;
  }
  String name = pieces[pieces.length - 1];
  File afterFile = new File(parent.getPath(), name);
  //if user already accepted overwriting, we shouldn't have created a new one
  final VirtualFile file = myDelayedPrecheckContext.getOverridenPaths().contains(VcsUtil.getFilePath(afterFile))
                           ? parent.findChild(name)
                           : createFile(parent, name);
  if (file == null) {
    setErrorMessage(fileNotFoundMessage(myAfterName));
    return false;
  }
  myAddedPaths.add(VcsUtil.getFilePath(file));
  if (! checkExistsAndValid(file, myAfterName)) {
    return false;
  }
  addPatch(myPatch, file);
  return true;
}
 
Example #8
Source File: AnnotateRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected VirtualFile getFile(@Nonnull AnActionEvent e) {
  VcsFileRevision revision = getFileRevision(e);
  if (revision == null) return null;

  final FileType currentFileType = myAnnotation.getFile().getFileType();
  FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile()));
  return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) {
    @Nonnull
    @Override
    public FileType getFileType() {
      FileType type = super.getFileType();
      if (!type.isBinary()) return type;
      if (!currentFileType.isBinary()) return currentFileType;
      return PlainTextFileType.INSTANCE;
    }
  };
}
 
Example #9
Source File: DiffShelvedChangesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void processBinaryFiles(@Nonnull final Project project,
                                       @Nonnull List<ShelvedBinaryFile> files,
                                       @Nonnull List<MyDiffRequestProducer> diffRequestProducers) {
  final String base = project.getBaseDir().getPath();
  for (final ShelvedBinaryFile shelvedChange : files) {
    final File file = new File(base, shelvedChange.AFTER_PATH == null ? shelvedChange.BEFORE_PATH : shelvedChange.AFTER_PATH);
    final FilePath filePath = VcsUtil.getFilePath(file);
    diffRequestProducers.add(new MyDiffRequestProducer(shelvedChange, filePath) {
      @Nonnull
      @Override
      public DiffRequest process(@Nonnull UserDataHolder context, @Nonnull ProgressIndicator indicator)
              throws DiffRequestProducerException, ProcessCanceledException {
        Change change = shelvedChange.createChange(project);
        return PatchDiffRequestFactory.createDiffRequest(project, change, getName(), context, indicator);
      }
    });
  }
}
 
Example #10
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Before
public void setUp() throws VcsException {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(CommandUtils.class, ConflictsEnvironment.class, ProgressManager.class, VcsUtil.class,
            TFSVcs.class, TfsFileUtil.class, TFSContentRevision.class, CurrentContentRevision.class, VersionControlPath.class);

    when(mockFile.isFile()).thenReturn(true);
    when(mockFile.isDirectory()).thenReturn(false);
    when(mockUpdatedFiles.getGroupById(anyString())).thenReturn(mockFileGroup);
    when(mockTFSVcs.getServerContext(anyBoolean())).thenReturn(mockServerContext);
    when(mockResolveConflictsModel.getConflictsTableModel()).thenReturn(mockConflictsTableModel);
    when(mockProgressManager.getProgressIndicator()).thenReturn(mockProgressIndicator);

    when(ProgressManager.getInstance()).thenReturn(mockProgressManager);
    when(TFSVcs.getInstance(mockProject)).thenReturn(mockTFSVcs);
    when(ConflictsEnvironment.getNameMerger()).thenReturn(mockNameMerger);
    when(ConflictsEnvironment.getContentMerger()).thenReturn(mockContentMerger);

    helper = new ResolveConflictHelper(mockProject, mockUpdatedFiles, updateRoots);
}
 
Example #11
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Test
public void testMerge_Content() throws Exception {
    helper = spy(new ResolveConflictHelper(mockProject, mockUpdatedFiles, updateRoots));
    FilePath mockLocalPath = mock(FilePath.class);
    VirtualFile mockVirtualFile = mock(VirtualFile.class);
    when(mockLocalPath.getPath()).thenReturn(CONFLICT_CONTEXT.getLocalPath());
    when(VersionControlPath.getFilePath(CONFLICT_CONTEXT.getLocalPath(), false)).thenReturn(mockLocalPath);
    when(VcsUtil.getVirtualFileWithRefresh(any(File.class))).thenReturn(mockVirtualFile);
    when(mockContentMerger.mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class))).thenReturn(true);

    helper.acceptMerge(CONFLICT_CONTEXT, mockResolveConflictsModel);
    verify(helper).populateThreeWayDiffWithProgress(CONFLICT_CONTEXT, new File(CONFLICT_CONTEXT.getLocalPath()), mockLocalPath, mockServerContext);
    verify(mockContentMerger).mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class));
    verify(helper).resolveConflictWithProgress(Matchers.eq(CONFLICT_CONTEXT.getLocalPath()), Matchers.eq(ResolveConflictsCommand.AutoResolveType.KeepYours), Matchers.eq(mockServerContext), Matchers.eq(mockResolveConflictsModel), Matchers.eq(true), any(NameMergerResolution.class));
    verify(helper, never()).processBothConflicts(any(Conflict.class), any(ServerContext.class), any(ResolveConflictsModel.class), any(File.class), any(ContentTriplet.class), any(NameMergerResolution.class));
    verify(helper, never()).processRenameConflict(any(Conflict.class), any(ServerContext.class), any(ResolveConflictsModel.class), any(NameMergerResolution.class));
}
 
Example #12
Source File: ResolveConflictHelperTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
public void bothTest(final String selectedName) throws Exception {
    helper = spy(new ResolveConflictHelper(mockProject, mockUpdatedFiles, updateRoots));

    FilePath mockLocalPath = mock(FilePath.class);
    when(mockLocalPath.getPath()).thenReturn(CONFLICT_BOTH.getLocalPath());

    FilePath mockServerPath = mock(FilePath.class);
    when(mockServerPath.getPath()).thenReturn(((RenameConflict) CONFLICT_BOTH).getServerPath());

    VirtualFile mockVirtualFile = mock(VirtualFile.class);
    when(VcsUtil.getVirtualFileWithRefresh(any(File.class))).thenReturn(mockVirtualFile);

    when(mockNameMerger.mergeName(anyString(), anyString(), Matchers.eq(mockProject))).thenReturn(selectedName);

    when(VersionControlPath.getFilePath(eq(((RenameConflict) CONFLICT_BOTH).getServerPath()), anyBoolean())).thenReturn(mockServerPath);

    when(VersionControlPath.getFilePath(CONFLICT_BOTH.getLocalPath(), false)).thenReturn(mockLocalPath);
    when(mockContentMerger.mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class))).thenReturn(true);

    helper.acceptMerge(CONFLICT_BOTH, mockResolveConflictsModel);
    verify(helper).populateThreeWayDiffWithProgress(CONFLICT_BOTH, new File(CONFLICT_BOTH.getLocalPath()), mockLocalPath, mockServerContext);
    verify(mockNameMerger).mergeName(anyString(), anyString(), eq(mockProject));
    verify(mockContentMerger).mergeContent(any(ContentTriplet.class), eq(mockProject), eq(mockVirtualFile), isNull(VcsRevisionNumber.class));
    verify(helper).resolveConflictWithProgress(eq(selectedName), eq(ResolveConflictsCommand.AutoResolveType.KeepYours), eq(mockServerContext), eq(mockResolveConflictsModel), eq(true), any(NameMergerResolution.class));
}
 
Example #13
Source File: FileGroup.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static VcsRevisionNumber getRevision(final ProjectLevelVcsManager vcsManager, final UpdatedFile file) {
  final String vcsName = file.getVcsName();
  final String revision = file.getRevision();
  if (vcsName != null && revision != null) {
    AbstractVcs vcs = vcsManager.findVcsByName(vcsName);
    if (vcs != null) {
      try {
        return vcs.parseRevisionNumber(revision, VcsUtil.getFilePath(file.getPath()));
      }
      catch (VcsException e) {
        //
      }
    }
  }
  return null;
}
 
Example #14
Source File: TFSChangeListTest.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    PowerMockito.mockStatic(VcsUtil.class);

    when(VcsUtil.getFilePath(addedFilePath1.getPath(), addedFilePath1.isDirectory())).thenReturn(addedFilePath1);
    when(VcsUtil.getFilePath(addedFilePath2.getPath(), addedFilePath2.isDirectory())).thenReturn(addedFilePath2);
    when(VcsUtil.getFilePath(addedFilePath3.getPath(), addedFilePath3.isDirectory())).thenReturn(addedFilePath3);
    when(VcsUtil.getFilePath(deletedFilePath1.getPath(), deletedFilePath1.isDirectory())).thenReturn(deletedFilePath1);
    when(VcsUtil.getFilePath(deletedFilePath2.getPath(), deletedFilePath2.isDirectory())).thenReturn(deletedFilePath2);
    when(VcsUtil.getFilePath(renamedFilePath1.getPath(), renamedFilePath1.isDirectory())).thenReturn(renamedFilePath1);
    when(VcsUtil.getFilePath(editedFilePath1.getPath(), editedFilePath1.isDirectory())).thenReturn(addedFilePath1);
    when(VcsUtil.getFilePath(editedFilePath2.getPath(), editedFilePath2.isDirectory())).thenReturn(editedFilePath2);
    when(VcsUtil.getFilePath(editedFilePath3.getPath(), editedFilePath3.isDirectory())).thenReturn(editedFilePath3);

    changeList = new TFSChangeList(addedFiles, deletedFiles, renamedFiles,
            editedFiles, CHANGESET_ID, AUTHOR, COMMENT,
            CHANGESET_DATE, PREVIOUS_CHANGESET_ID, PREVIOUS_CHANGESET_DATE,
            mockVcs, WORKSPACE_NAME);
}
 
Example #15
Source File: AbstractFilePatchInProgress.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setNewBase(final VirtualFile base) {
  myBase = base;
  myNewContentRevision = null;
  myCurrentRevision = null;
  myConflicts = null;

  final String beforeName = myPatch.getBeforeName();
  if (beforeName != null) {
    myIoCurrentBase = PathMerger.getFile(new File(myBase.getPath()), beforeName);
    myCurrentBase = myIoCurrentBase == null ? null : VcsUtil.getVirtualFileWithRefresh(myIoCurrentBase);
    myBaseExists = (myCurrentBase != null) && myCurrentBase.exists();
  }
  else {
    // creation
    final String afterName = myPatch.getAfterName();
    myBaseExists = true;
    myIoCurrentBase = PathMerger.getFile(new File(myBase.getPath()), afterName);
    myCurrentBase = VcsUtil.getVirtualFileWithRefresh(myIoCurrentBase);
  }
}
 
Example #16
Source File: VcsDirtyScopeManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private MultiMap<AbstractVcs, FilePath> getEverythingDirtyRoots() {
  MultiMap<AbstractVcs, FilePath> dirtyRoots = MultiMap.createSet();
  dirtyRoots.putAllValues(groupByVcs(toFilePaths(DefaultVcsRootPolicy.getInstance(myProject).getDirtyRoots())));

  List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
  for (VcsDirectoryMapping mapping : mappings) {
    if (!mapping.isDefaultMapping() && mapping.getVcs() != null) {
      AbstractVcs vcs = myVcsManager.findVcsByName(mapping.getVcs());
      if (vcs != null) {
        dirtyRoots.putValue(vcs, VcsUtil.getFilePath(mapping.getDirectory(), true));
      }
    }
  }
  return dirtyRoots;
}
 
Example #17
Source File: PluginSetup.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
public ClientConfigRoot addClientConfigRoot(TemporaryFolder tmp, String clientRootDir) {
    File base = tmp.newFile(clientRootDir);
    if (!base.mkdirs()) {
        throw new RuntimeException("Could not create directory " + base);
    }

    MockConfigPart cp1 = new MockConfigPart()
            .withClientname("cn")
            .withUsername("u")
            .withServerName("s:123");
    ClientConfig cc = ClientConfig.createFrom(ServerConfig.createFrom(cp1), cp1);
    FilePath fp = VcsUtil.getFilePath(base);
    VirtualFile rootDir = Objects.requireNonNull(fp.getVirtualFile());
    registry.addClientConfig(cc, rootDir);
    roots.add(rootDir);
    return Objects.requireNonNull(registry.getClientFor(rootDir));
}
 
Example #18
Source File: VcsUtils.java    From Crucible4IDEA with MIT License 6 votes vote down vote up
@Nullable
public static CommittedChangeList loadRevisions(@NotNull final Project project, final VcsRevisionNumber number, final FilePath filePath) {
  final CommittedChangeList[] list = new CommittedChangeList[1];
  final ThrowableRunnable<VcsException> runnable = () -> {
    final AbstractVcs vcs = VcsUtil.getVcsFor(project, filePath);

    if (vcs == null) {
      return;
    }

    list[0] = vcs.loadRevisions(filePath.getVirtualFile(), number);
  };

  final boolean success = VcsSynchronousProgressWrapper.wrap(runnable, project, "Load Revision Contents");

  return success ? list[0] : null;
}
 
Example #19
Source File: VcsRootCacheStore.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public VcsRootCacheStore(@NotNull State root, @Nullable ClassLoader classLoader) {
    // It's possible for a mis-configuration to setup a null root directory.
    this.rootDirectory = root.rootDirectory == null ? null : VcsUtil.getVirtualFile(root.rootDirectory);
    if (root.configParts == null) {
        this.configParts = new ArrayList<>();
    } else {
        this.configParts = new ArrayList<>(root.configParts.size());
        for (ConfigPartState configPart : root.configParts) {
            this.configParts.add(convert(configPart, rootDirectory, classLoader));
        }
    }
}
 
Example #20
Source File: ChangeListWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public LocalChangeList getListCopy(@Nonnull final VirtualFile file) {
  FilePath filePath = VcsUtil.getFilePath(file);
  for (LocalChangeList list : myMap.values()) {
    for (Change change : list.getChanges()) {
      if (change.getAfterRevision() != null && Comparing.equal(change.getAfterRevision().getFile(), filePath) ||
          change.getBeforeRevision() != null && Comparing.equal(change.getBeforeRevision().getFile(), filePath)) {
        return list.copy();
      }
    }
  }
  return null;
}
 
Example #21
Source File: P4CommandUtil.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public byte[] loadContents(IClient client, IFileSpec spec)
        throws P4JavaException, IOException {
    // For fetching the local File information, we need a client to perform the mapping.
    IServer server = client.getServer();
    server.setCurrentClient(client);
    int maxFileSize = VcsUtil.getMaxVcsLoadedFileSize();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GetFileContentsOptions fileContentsOptions = new GetFileContentsOptions(false, true);
    // setting "don't annotate files" to true means we ignore the revision
    fileContentsOptions.setDontAnnotateFiles(false);
    InputStream inp = server.getFileContents(Collections.singletonList(spec),
            fileContentsOptions);
    if (inp == null) {
        return null;
    }

    try {
        byte[] buff = new byte[BUFFER_SIZE];
        int len;
        while ((len = inp.read(buff, 0, BUFFER_SIZE)) > 0 && baos.size() < maxFileSize) {
            baos.write(buff, 0, len);
        }
    } finally {
        // Note: be absolutely sure to close the InputStream that is returned.
        inp.close();
    }
    return baos.toByteArray();
}
 
Example #22
Source File: OpenedFilesChangesFactory.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
static List<FilePath> getLocalFiles(@NotNull List<IExtendedFileSpec> files) {
    List<FilePath> ret = new ArrayList<>(files.size());

    // For this particular call, the path to the file is stored in the localPath.
    for (IExtendedFileSpec file : files) {
        // Local paths do not need to be stripped of annotations or unescaped.
        ret.add(VcsUtil.getFilePath(file.getLocalPath().getPathString(), false));
    }

    return ret;
}
 
Example #23
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canShowHistoryFor(@NotNull VirtualFile file) {
    if (file.isDirectory() || !file.isValid()) {
        return false;
    }
    FilePath fp = VcsUtil.getFilePath(file);
    return fp != null && getRootFor(fp) != null;
}
 
Example #24
Source File: AbstractVcsHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void openCommittedChangesTab(final AbstractVcs vcs,
                                    final VirtualFile root,
                                    final ChangeBrowserSettings settings,
                                    final int maxCount,
                                    String title) {
  RepositoryLocationCache cache = CommittedChangesCache.getInstance(myProject).getLocationCache();
  RepositoryLocation location = cache.getLocation(vcs, VcsUtil.getFilePath(root), false);
  openCommittedChangesTab(vcs.getCommittedChangesProvider(), location, settings, maxCount, title);
}
 
Example #25
Source File: RecursiveFileHolder.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean isFileDirty(final VcsDirtyScope scope, final VirtualFile file) {
  if (!file.isValid()) return true;
  final AbstractVcs[] vcsArr = new AbstractVcs[1];
  if (scope.belongsTo(VcsUtil.getFilePath(file), vcs -> vcsArr[0] = vcs)) {
    return true;
  }
  return vcsArr[0] == null;
}
 
Example #26
Source File: AnnotateAction.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Override
public void update(@NotNull final AnActionEvent e) {
    final VirtualFile file = VcsUtil.getOneVirtualFile(e);

    // disable for directories
    if (file == null || file.isDirectory()) {
        e.getPresentation().setEnabled(false);
        return;
    }
    // this will disable all new files
    super.update(e);
}
 
Example #27
Source File: PrimitiveMap.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
List<FilePath> getFilePathList(@NotNull String key)
        throws UnmarshalException {
    return getStringList(key)
            .stream()
            .map(VcsUtil::getFilePath)
            .collect(Collectors.toList());
}
 
Example #28
Source File: RootSettingsUtil.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
public static VirtualFile getDirectory(@NotNull Project project, @NotNull VcsDirectoryMapping directoryMapping) {
    String dir = directoryMapping.getDirectory();
    if (dir == null || dir.length() <= 0) {
        return ProjectUtil.guessProjectBaseDir(project);
    }
    VirtualFile ret = VcsUtil.getVirtualFile(dir);
    if (ret == null) {
        ret = ProjectUtil.guessProjectBaseDir(project);
        LOG.info("VcsDirectoryMapping has directory " + dir +
                " which could not be turned into a virtual file; using " + ret);
    }
    return ret;
}
 
Example #29
Source File: UpdatingChangeListBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void processRootSwitch(VirtualFile file, String branch) {
  if (file == null) return;
  checkIfDisposed();
  if (myScope.belongsTo(VcsUtil.getFilePath(file))) {
    ((SwitchedFileHolder)myComposite.get(FileHolder.HolderType.ROOT_SWITCH)).addFile(file, branch, false);
  }
}
 
Example #30
Source File: RemoteFileUtil.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
public static FilePath findRelativeRemotePath(@NotNull P4LocalFile local, @Nullable P4RemoteFile remote) {
    if (remote == null) {
        LOG.info("No remote file, so just assuming local file.");
        return local.getFilePath();
    }
    FilePath ret = null;
    if (remote.equals(local.getDepotPath())) {
        ret = local.getFilePath();
    }
    if (ret == null && remote.getLocalPath().isPresent()) {
        ret = VcsUtil.getFilePath(remote.getLocalPath().get());
    }

    // Attempt to construct a relative path.  This is error prone, and just a guess, but should
    // make the UI show up a bit better.
    if (ret == null && local.getClientDepotPath().isPresent()) {
        ret = createRelativePath(local.getFilePath(), local.getClientDepotPath().get(), remote);
    }
    if (ret == null && local.getDepotPath() != null) {
        ret = createRelativePath(local.getFilePath(), local.getDepotPath(), remote);
    }

    if (ret == null) {
        // FIXME This causes a source file location bug.  The UI shows a relative path to the depot path.
        LOG.warn("FIXME returning a remote path, which causes a bad UI relative path");
        ret = new RemoteFilePath(remote.getDisplayName(), false);
    }
    return ret;
}