MakeCacheTree.java

  1. /*
  2.  * Copyright (C) 2008, Google Inc.
  3.  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */

  11. package org.eclipse.jgit.pgm.debug;

  12. import static java.lang.Integer.valueOf;

  13. import java.io.IOException;
  14. import java.text.MessageFormat;

  15. import org.eclipse.jgit.dircache.DirCache;
  16. import org.eclipse.jgit.dircache.DirCacheTree;
  17. import org.eclipse.jgit.pgm.Command;
  18. import org.eclipse.jgit.pgm.TextBuiltin;
  19. import org.eclipse.jgit.pgm.internal.CLIText;

  20. @Command(usage = "usage_MakeCacheTree")
  21. class MakeCacheTree extends TextBuiltin {
  22.     /** {@inheritDoc} */
  23.     @Override
  24.     protected void run() throws Exception {
  25.         final DirCache cache = db.readDirCache();
  26.         final DirCacheTree tree = cache.getCacheTree(true);
  27.         show(tree);
  28.     }

  29.     private void show(DirCacheTree tree) throws IOException {
  30.         outw.println(MessageFormat.format(CLIText.get().cacheTreePathInfo,
  31.                 tree.getPathString(), valueOf(tree.getEntrySpan()),
  32.                 valueOf(tree.getChildCount())));

  33.         for (int i = 0; i < tree.getChildCount(); i++)
  34.             show(tree.getChild(i));
  35.     }
  36. }