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.

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