Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AbstractFetchCommand.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2008, Charles O'Farrell <charleso@charleso.org>
  3. * Copyright (C) 2008-2010, Google Inc.
  4. * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
  5. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.pgm;
  47. import org.kohsuke.args4j.Option;
  48. import org.eclipse.jgit.lib.Constants;
  49. import org.eclipse.jgit.lib.ObjectId;
  50. import org.eclipse.jgit.lib.RefUpdate;
  51. import org.eclipse.jgit.transport.FetchResult;
  52. import org.eclipse.jgit.transport.TrackingRefUpdate;
  53. import org.eclipse.jgit.transport.Transport;
  54. abstract class AbstractFetchCommand extends TextBuiltin {
  55. @Option(name = "--verbose", aliases = { "-v" }, usage = "be more verbose")
  56. private boolean verbose;
  57. protected void showFetchResult(final Transport tn, final FetchResult r) {
  58. boolean shownURI = false;
  59. for (final TrackingRefUpdate u : r.getTrackingRefUpdates()) {
  60. if (!verbose && u.getResult() == RefUpdate.Result.NO_CHANGE)
  61. continue;
  62. final char type = shortTypeOf(u.getResult());
  63. final String longType = longTypeOf(u);
  64. final String src = abbreviateRef(u.getRemoteName(), false);
  65. final String dst = abbreviateRef(u.getLocalName(), true);
  66. if (!shownURI) {
  67. out.print("From ");
  68. out.print(tn.getURI());
  69. out.println();
  70. shownURI = true;
  71. }
  72. out.format(" %c %-17s %-10s -> %s", type, longType, src, dst);
  73. out.println();
  74. }
  75. showRemoteMessages(r.getMessages());
  76. }
  77. static void showRemoteMessages(String pkt) {
  78. while (0 < pkt.length()) {
  79. final int lf = pkt.indexOf('\n');
  80. final int cr = pkt.indexOf('\r');
  81. final int s;
  82. if (0 <= lf && 0 <= cr)
  83. s = Math.min(lf, cr);
  84. else if (0 <= lf)
  85. s = lf;
  86. else if (0 <= cr)
  87. s = cr;
  88. else {
  89. System.err.println("remote: " + pkt);
  90. break;
  91. }
  92. if (pkt.charAt(s) == '\r')
  93. System.err.print("remote: " + pkt.substring(0, s) + "\r");
  94. else
  95. System.err.println("remote: " + pkt.substring(0, s));
  96. pkt = pkt.substring(s + 1);
  97. }
  98. System.err.flush();
  99. }
  100. private String longTypeOf(final TrackingRefUpdate u) {
  101. final RefUpdate.Result r = u.getResult();
  102. if (r == RefUpdate.Result.LOCK_FAILURE)
  103. return "[lock fail]";
  104. if (r == RefUpdate.Result.IO_FAILURE)
  105. return "[i/o error]";
  106. if (r == RefUpdate.Result.REJECTED)
  107. return "[rejected]";
  108. if (ObjectId.zeroId().equals(u.getNewObjectId()))
  109. return "[deleted]";
  110. if (r == RefUpdate.Result.NEW) {
  111. if (u.getRemoteName().startsWith(Constants.R_HEADS))
  112. return "[new branch]";
  113. else if (u.getLocalName().startsWith(Constants.R_TAGS))
  114. return "[new tag]";
  115. return "[new]";
  116. }
  117. if (r == RefUpdate.Result.FORCED) {
  118. final String aOld = u.getOldObjectId().abbreviate(db).name();
  119. final String aNew = u.getNewObjectId().abbreviate(db).name();
  120. return aOld + "..." + aNew;
  121. }
  122. if (r == RefUpdate.Result.FAST_FORWARD) {
  123. final String aOld = u.getOldObjectId().abbreviate(db).name();
  124. final String aNew = u.getNewObjectId().abbreviate(db).name();
  125. return aOld + ".." + aNew;
  126. }
  127. if (r == RefUpdate.Result.NO_CHANGE)
  128. return "[up to date]";
  129. return "[" + r.name() + "]";
  130. }
  131. private static char shortTypeOf(final RefUpdate.Result r) {
  132. if (r == RefUpdate.Result.LOCK_FAILURE)
  133. return '!';
  134. if (r == RefUpdate.Result.IO_FAILURE)
  135. return '!';
  136. if (r == RefUpdate.Result.NEW)
  137. return '*';
  138. if (r == RefUpdate.Result.FORCED)
  139. return '+';
  140. if (r == RefUpdate.Result.FAST_FORWARD)
  141. return ' ';
  142. if (r == RefUpdate.Result.REJECTED)
  143. return '!';
  144. if (r == RefUpdate.Result.NO_CHANGE)
  145. return '=';
  146. return ' ';
  147. }
  148. }