Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 64b182e17d651622f4df96217c13051c8e1fcf10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright (C) 2010, Google Inc.
 * Copyright (C) 2008, Jonas Fonseca <fonseca@diku.dk>
 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.pgm;

import java.io.IOException;
import java.util.List;

import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefComparator;

@Command(usage = "usage_ShowRef")
class ShowRef extends TextBuiltin {
	@Override
	protected void run() {
		try {
			for (Ref r : getSortedRefs()) {
				show(r.getObjectId(), r.getName());
				if (r.getPeeledObjectId() != null) {
					show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$
				}
			}
		} catch (IOException e) {
			throw die(e.getMessage(), e);
		}
	}

	private Iterable<Ref> getSortedRefs() throws IOException {
		List<Ref> all = db.getRefDatabase().getRefs();
		// TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
		// SortedList
		return RefComparator.sort(all);
	}

	private void show(AnyObjectId id, String name)
			throws IOException {
		outw.print(id.name());
		outw.print('\t');
		outw.print(name);
		outw.println();
	}
}

Back to the top