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.

ShowRef.java 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * Copyright (C) 2008, Jonas Fonseca <fonseca@diku.dk>
  4. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  5. *
  6. * This program and the accompanying materials are made available under the
  7. * terms of the Eclipse Distribution License v. 1.0 which is available at
  8. * https://www.eclipse.org/org/documents/edl-v10.php.
  9. *
  10. * SPDX-License-Identifier: BSD-3-Clause
  11. */
  12. package org.eclipse.jgit.pgm;
  13. import java.io.IOException;
  14. import java.util.List;
  15. import org.eclipse.jgit.lib.AnyObjectId;
  16. import org.eclipse.jgit.lib.Ref;
  17. import org.eclipse.jgit.lib.RefComparator;
  18. @Command(usage = "usage_ShowRef")
  19. class ShowRef extends TextBuiltin {
  20. /** {@inheritDoc} */
  21. @Override
  22. protected void run() {
  23. try {
  24. for (Ref r : getSortedRefs()) {
  25. show(r.getObjectId(), r.getName());
  26. if (r.getPeeledObjectId() != null) {
  27. show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$
  28. }
  29. }
  30. } catch (IOException e) {
  31. throw die(e.getMessage(), e);
  32. }
  33. }
  34. private Iterable<Ref> getSortedRefs() throws IOException {
  35. List<Ref> all = db.getRefDatabase().getRefs();
  36. // TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
  37. // SortedList
  38. return RefComparator.sort(all);
  39. }
  40. private void show(AnyObjectId id, String name)
  41. throws IOException {
  42. outw.print(id.name());
  43. outw.print('\t');
  44. outw.print(name);
  45. outw.println();
  46. }
  47. }