private GitChangesCollectionResult collectChangesInternal()

in git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/GitCollectChangesPolicy.java [104:151]


  private GitChangesCollectionResult collectChangesInternal(@NotNull VcsRoot root,
                                                @NotNull RepositoryStateData fromState,
                                                @NotNull RepositoryStateData toState,
                                                boolean allowMissingTips) throws VcsException {
    SProject project = retrieveProject(root);
    String operationId = UUID.randomUUID().toString().substring(0, 8); // used for logging
    try (Stoppable stoppable = myCollectChangesMetric.startMsecsTimer()) {
      final GitProxySettings proxyCredentials = myGitProxyChangesCollector.getGitProxyInfo(root, project);
      if (!GitProxyChangesCollector.isGitProxyEnabled(project) || proxyCredentials == null) {
        GitChangesCollectionResult jgitResult = runCollectChangesWithTimer("jgit", operationId, root, project, false, () -> collectGitChangesJgit(root, fromState, toState));
        if (project != null && GitProxyChangesCollector.isComparisonLoggingEnabled(project) && proxyCredentials != null) {
          try {
            Map<String, List<String>> submodulePrefixesMap = new HashMap<>();
            GitChangesCollectionResult gitProxyResult = runCollectChangesWithTimer("gitProxy", operationId, root, project, true,
                                                                               () -> myGitProxyChangesCollector.collectChangesGitProxy(myConfig, root, fromState, toState, proxyCredentials, operationId, submodulePrefixesMap, false, allowMissingTips));
            GitApiClient<GitRepoApi> api = myGitProxyChangesCollector.getClient(proxyCredentials, root, operationId);
            myGitProxyChangesCollector.logAnyDifferences(jgitResult.getModificationDataList(), gitProxyResult.getModificationDataList(), fromState, toState, root, Objects.requireNonNull(api, "Git repo api can't be null"), submodulePrefixesMap);
          } catch (IgnoredCollectChangesFailure ignored) {
          } catch (Throwable t) {
            LOG.error(String.format("Failed to compare gitProxy and jgit changes collection results. Operation id %s. %s", operationId, GitProxyChangesCollector.getStateDiff(fromState, toState)), t);
          }
        }
        return jgitResult;
      } else {
        // we try to collect changes with gitProxy, if it fails(for example if there were some changes in submodule), then we fall back to jgit changes collection
        try {
          return runCollectChangesWithTimer("gitProxy", operationId, root, project, false,
                                            () -> myGitProxyChangesCollector.collectChangesGitProxy(myConfig, root, fromState, toState, proxyCredentials, operationId, null, true, allowMissingTips));
        } catch (Throwable t) {
          boolean shouldRunFallbackChangesCollections = TeamCityProperties.getBooleanOrTrue(GitProxyChangesCollector.ENABLE_JGIT_FALLBACK_CHANGES_COLLECTION);
          if (t instanceof GitProxyChangesCollector.GitProxySubmoduleChangesNotSupported) {
            LOG.info(String.format("Will not collect changes with gitProxy because changes in submodule were detected, will use jgit changes collection. " +
                                   "State %s. Operation id %s",
                                   GitProxyChangesCollector.getStateDiff(fromState, toState), operationId));
            shouldRunFallbackChangesCollections = true;
          } else {
            LOG.warn(String.format("Failed to collect changes with gitProxy%s. Operation id %s",
                                   shouldRunFallbackChangesCollections ? ", will collect changes with jgit" : "", operationId), t);
          }
          if (shouldRunFallbackChangesCollections) {
            return runCollectChangesWithTimer("jgitFallback", operationId, root, project, false, () -> collectGitChangesJgit(root, fromState, toState));
          } else {
            throw t;
          }
        }
      }
    }
  }