You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShowCacheTree.java 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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_ShowCacheTree")
  21. class ShowCacheTree extends TextBuiltin {
  22. /** {@inheritDoc} */
  23. @Override
  24. protected void run() throws Exception {
  25. final DirCache cache = db.readDirCache();
  26. final DirCacheTree tree = cache.getCacheTree(false);
  27. if (tree == null)
  28. throw die(CLIText.get().noTREESectionInIndex);
  29. show(tree);
  30. }
  31. private void show(DirCacheTree tree) throws IOException {
  32. outw.println(MessageFormat.format(CLIText.get().cacheTreePathInfo,
  33. tree.getPathString(), valueOf(tree.getEntrySpan()),
  34. valueOf(tree.getChildCount())));
  35. for (int i = 0; i < tree.getChildCount(); i++)
  36. show(tree.getChild(i));
  37. }
  38. }