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.

RevObject.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /** Base object type accessed during revision walking. */
  52. public abstract class RevObject extends ObjectIdOwnerMap.Entry {
  53. static final int PARSED = 1;
  54. int flags;
  55. RevObject(final AnyObjectId name) {
  56. super(name);
  57. }
  58. abstract void parseHeaders(RevWalk walk) throws MissingObjectException,
  59. IncorrectObjectTypeException, IOException;
  60. abstract void parseBody(RevWalk walk) throws MissingObjectException,
  61. IncorrectObjectTypeException, IOException;
  62. /**
  63. * Get Git object type. See {@link Constants}.
  64. *
  65. * @return object type
  66. */
  67. public abstract int getType();
  68. /**
  69. * Get the name of this object.
  70. *
  71. * @return unique hash of this object.
  72. */
  73. public final ObjectId getId() {
  74. return this;
  75. }
  76. /**
  77. * Test to see if the flag has been set on this object.
  78. *
  79. * @param flag
  80. * the flag to test.
  81. * @return true if the flag has been added to this object; false if not.
  82. */
  83. public final boolean has(final RevFlag flag) {
  84. return (flags & flag.mask) != 0;
  85. }
  86. /**
  87. * Test to see if any flag in the set has been set on this object.
  88. *
  89. * @param set
  90. * the flags to test.
  91. * @return true if any flag in the set has been added to this object; false
  92. * if not.
  93. */
  94. public final boolean hasAny(final RevFlagSet set) {
  95. return (flags & set.mask) != 0;
  96. }
  97. /**
  98. * Test to see if all flags in the set have been set on this object.
  99. *
  100. * @param set
  101. * the flags to test.
  102. * @return true if all flags of the set have been added to this object;
  103. * false if some or none have been added.
  104. */
  105. public final boolean hasAll(final RevFlagSet set) {
  106. return (flags & set.mask) == set.mask;
  107. }
  108. /**
  109. * Add a flag to this object.
  110. * <p>
  111. * If the flag is already set on this object then the method has no effect.
  112. *
  113. * @param flag
  114. * the flag to mark on this object, for later testing.
  115. */
  116. public final void add(final RevFlag flag) {
  117. flags |= flag.mask;
  118. }
  119. /**
  120. * Add a set of flags to this object.
  121. *
  122. * @param set
  123. * the set of flags to mark on this object, for later testing.
  124. */
  125. public final void add(final RevFlagSet set) {
  126. flags |= set.mask;
  127. }
  128. /**
  129. * Remove a flag from this object.
  130. * <p>
  131. * If the flag is not set on this object then the method has no effect.
  132. *
  133. * @param flag
  134. * the flag to remove from this object.
  135. */
  136. public final void remove(final RevFlag flag) {
  137. flags &= ~flag.mask;
  138. }
  139. /**
  140. * Remove a set of flags from this object.
  141. *
  142. * @param set
  143. * the flag to remove from this object.
  144. */
  145. public final void remove(final RevFlagSet set) {
  146. flags &= ~set.mask;
  147. }
  148. @Override
  149. public String toString() {
  150. final StringBuilder s = new StringBuilder();
  151. s.append(Constants.typeString(getType()));
  152. s.append(' ');
  153. s.append(name());
  154. s.append(' ');
  155. appendCoreFlags(s);
  156. return s.toString();
  157. }
  158. /**
  159. * @param s
  160. * buffer to append a debug description of core RevFlags onto.
  161. */
  162. protected void appendCoreFlags(final StringBuilder s) {
  163. s.append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-');
  164. s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');
  165. s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');
  166. s.append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');
  167. s.append((flags & RevWalk.SEEN) != 0 ? 's' : '-');
  168. s.append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');
  169. }
  170. }