private TreeResult processTree()

in git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/commitInfo/CommitTreeProcessor.java [68:105]


  private TreeResult processTree(@NotNull final AnyObjectId tree,
                                 @NotNull final String basePathPrefix,
                                 @Nullable final SubmodulesConfig baseConfig) throws IOException {
    final Map<String, AnyObjectId> pathToSubmoduleHash = new HashMap<String, AnyObjectId>();
    final Map<String, AnyObjectId> childTrees = new HashMap<String, AnyObjectId>();
    SubmodulesConfig submodules = baseConfig;

    final CanonicalTreeParser ps = new CanonicalTreeParser();
    ps.reset(myReader, tree);
    if (ps.eof()) return EMPTY;

    for (; !ps.eof(); ps.next()) {
      final FileMode mode = ps.getEntryFileMode();
      if (mode == FileMode.GITLINK) {
        pathToSubmoduleHash.put(basePathPrefix + ps.getEntryPathString(), ps.getEntryObjectId());
      }

      if (mode == FileMode.TREE) {
        childTrees.put(basePathPrefix + ps.getEntryPathString(), ps.getEntryObjectId());
      }

      if (submodules == null && mode == FileMode.REGULAR_FILE && DOT_GIT_MODULES.equals(ps.getEntryPathString())) {
        submodules = myModules.forBlob(ps.getEntryObjectId());
      }
    }

    if (submodules == null) return EMPTY;
    for (Map.Entry<String, AnyObjectId> e : childTrees.entrySet()) {
      final String path = e.getKey();
      if (!submodules.containsSubmodule(path)) continue;

      //TODO: may also cache parsed sub-strees as well
      final TreeResult sub = processTree(e.getValue(), path + "/", submodules);
      pathToSubmoduleHash.putAll(sub.getSubmoduleToPath());
    }

    return new TreeResult(pathToSubmoduleHash, submodules);
  }