View Javadoc
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  
12  package org.eclipse.jgit.pgm.debug;
13  
14  import static java.lang.Integer.valueOf;
15  
16  import java.io.IOException;
17  import java.text.MessageFormat;
18  
19  import org.eclipse.jgit.dircache.DirCache;
20  import org.eclipse.jgit.dircache.DirCacheTree;
21  import org.eclipse.jgit.pgm.Command;
22  import org.eclipse.jgit.pgm.TextBuiltin;
23  import org.eclipse.jgit.pgm.internal.CLIText;
24  
25  @Command(usage = "usage_ShowCacheTree")
26  class ShowCacheTree extends TextBuiltin {
27  	/** {@inheritDoc} */
28  	@Override
29  	protected void run() throws Exception {
30  		final DirCache cache = db.readDirCache();
31  		final DirCacheTree tree = cache.getCacheTree(false);
32  		if (tree == null)
33  			throw die(CLIText.get().noTREESectionInIndex);
34  		show(tree);
35  	}
36  
37  	private void show(DirCacheTree tree) throws IOException {
38  		outw.println(MessageFormat.format(CLIText.get().cacheTreePathInfo,
39  				tree.getPathString(), valueOf(tree.getEntrySpan()),
40  				valueOf(tree.getChildCount())));
41  
42  		for (int i = 0; i < tree.getChildCount(); i++)
43  			show(tree.getChild(i));
44  	}
45  }