Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2012, Tomasz Zarna <tomasz.zarna@tasktop.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.pgm;
  11. import java.io.IOException;
  12. import java.util.Collection;
  13. import org.eclipse.jgit.api.Git;
  14. import org.eclipse.jgit.api.ReflogCommand;
  15. import org.eclipse.jgit.api.errors.GitAPIException;
  16. import org.eclipse.jgit.lib.Constants;
  17. import org.eclipse.jgit.lib.ReflogEntry;
  18. import org.eclipse.jgit.lib.Repository;
  19. import org.kohsuke.args4j.Argument;
  20. @Command(common = true, usage = "usage_manageReflogInformation")
  21. class Reflog extends TextBuiltin {
  22. @Argument(metaVar = "metaVar_ref")
  23. private String ref;
  24. /** {@inheritDoc} */
  25. @Override
  26. protected void run() {
  27. try (Git git = new Git(db)) {
  28. ReflogCommand cmd = git.reflog();
  29. if (ref != null)
  30. cmd.setRef(ref);
  31. Collection<ReflogEntry> entries = cmd.call();
  32. int i = 0;
  33. for (ReflogEntry entry : entries) {
  34. outw.println(toString(entry, i++));
  35. }
  36. } catch (GitAPIException | IOException e) {
  37. throw die(e.getMessage(), e);
  38. }
  39. }
  40. private String toString(ReflogEntry entry, int i) {
  41. final StringBuilder s = new StringBuilder();
  42. s.append(entry.getNewId().abbreviate(7).name());
  43. s.append(" "); //$NON-NLS-1$
  44. s.append(ref == null ? Constants.HEAD : Repository.shortenRefName(ref));
  45. s.append("@{" + i + "}:"); //$NON-NLS-1$ //$NON-NLS-2$
  46. s.append(" "); //$NON-NLS-1$
  47. s.append(entry.getComment());
  48. return s.toString();
  49. }
  50. }