Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.revwalk;
  44. import java.io.IOException;
  45. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  46. import org.eclipse.jgit.errors.MissingObjectException;
  47. import org.eclipse.jgit.lib.AnyObjectId;
  48. import org.eclipse.jgit.lib.Constants;
  49. import org.eclipse.jgit.lib.ObjectId;
  50. import org.eclipse.jgit.lib.ObjectIdOwnerMap;
  51. /**
  52. * Base object type accessed during revision walking.
  53. */
  54. public abstract class RevObject extends ObjectIdOwnerMap.Entry {
  55. static final int PARSED = 1;
  56. int flags;
  57. RevObject(final AnyObjectId name) {
  58. super(name);
  59. }
  60. abstract void parseHeaders(RevWalk walk) throws MissingObjectException,
  61. IncorrectObjectTypeException, IOException;
  62. abstract void parseBody(RevWalk walk) throws MissingObjectException,
  63. IncorrectObjectTypeException, IOException;
  64. /**
  65. * Get Git object type. See {@link org.eclipse.jgit.lib.Constants}.
  66. *
  67. * @return object type
  68. */
  69. public abstract int getType();
  70. /**
  71. * Get the name of this object.
  72. *
  73. * @return unique hash of this object.
  74. */
  75. public final ObjectId getId() {
  76. return this;
  77. }
  78. /**
  79. * Test to see if the flag has been set on this object.
  80. *
  81. * @param flag
  82. * the flag to test.
  83. * @return true if the flag has been added to this object; false if not.
  84. */
  85. public final boolean has(final RevFlag flag) {
  86. return (flags & flag.mask) != 0;
  87. }
  88. /**
  89. * Test to see if any flag in the set has been set on this object.
  90. *
  91. * @param set
  92. * the flags to test.
  93. * @return true if any flag in the set has been added to this object; false
  94. * if not.
  95. */
  96. public final boolean hasAny(final RevFlagSet set) {
  97. return (flags & set.mask) != 0;
  98. }
  99. /**
  100. * Test to see if all flags in the set have been set on this object.
  101. *
  102. * @param set
  103. * the flags to test.
  104. * @return true if all flags of the set have been added to this object;
  105. * false if some or none have been added.
  106. */
  107. public final boolean hasAll(final RevFlagSet set) {
  108. return (flags & set.mask) == set.mask;
  109. }
  110. /**
  111. * Add a flag to this object.
  112. * <p>
  113. * If the flag is already set on this object then the method has no effect.
  114. *
  115. * @param flag
  116. * the flag to mark on this object, for later testing.
  117. */
  118. public final void add(final RevFlag flag) {
  119. flags |= flag.mask;
  120. }
  121. /**
  122. * Add a set of flags to this object.
  123. *
  124. * @param set
  125. * the set of flags to mark on this object, for later testing.
  126. */
  127. public final void add(final RevFlagSet set) {
  128. flags |= set.mask;
  129. }
  130. /**
  131. * Remove a flag from this object.
  132. * <p>
  133. * If the flag is not set on this object then the method has no effect.
  134. *
  135. * @param flag
  136. * the flag to remove from this object.
  137. */
  138. public final void remove(final RevFlag flag) {
  139. flags &= ~flag.mask;
  140. }
  141. /**
  142. * Remove a set of flags from this object.
  143. *
  144. * @param set
  145. * the flag to remove from this object.
  146. */
  147. public final void remove(final RevFlagSet set) {
  148. flags &= ~set.mask;
  149. }
  150. /** {@inheritDoc} */
  151. @Override
  152. public String toString() {
  153. final StringBuilder s = new StringBuilder();
  154. s.append(Constants.typeString(getType()));
  155. s.append(' ');
  156. s.append(name());
  157. s.append(' ');
  158. appendCoreFlags(s);
  159. return s.toString();
  160. }
  161. /**
  162. * Append a debug description of core RevFlags to a buffer.
  163. *
  164. * @param s
  165. * buffer to append a debug description of core RevFlags onto.
  166. */
  167. protected void appendCoreFlags(final StringBuilder s) {
  168. s.append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-');
  169. s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');
  170. s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');
  171. s.append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');
  172. s.append((flags & RevWalk.SEEN) != 0 ? 's' : '-');
  173. s.append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');
  174. }
  175. }