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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 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.revwalk;
  11. import java.io.IOException;
  12. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  13. import org.eclipse.jgit.errors.MissingObjectException;
  14. import org.eclipse.jgit.lib.AnyObjectId;
  15. import org.eclipse.jgit.lib.Constants;
  16. import org.eclipse.jgit.lib.ObjectId;
  17. import org.eclipse.jgit.lib.ObjectIdOwnerMap;
  18. /**
  19. * Base object type accessed during revision walking.
  20. */
  21. public abstract class RevObject extends ObjectIdOwnerMap.Entry {
  22. static final int PARSED = 1;
  23. int flags;
  24. RevObject(AnyObjectId name) {
  25. super(name);
  26. }
  27. abstract void parseHeaders(RevWalk walk) throws MissingObjectException,
  28. IncorrectObjectTypeException, IOException;
  29. abstract void parseBody(RevWalk walk) throws MissingObjectException,
  30. IncorrectObjectTypeException, IOException;
  31. /**
  32. * Get Git object type. See {@link org.eclipse.jgit.lib.Constants}.
  33. *
  34. * @return object type
  35. */
  36. public abstract int getType();
  37. /**
  38. * Get the name of this object.
  39. *
  40. * @return unique hash of this object.
  41. */
  42. public final ObjectId getId() {
  43. return this;
  44. }
  45. /**
  46. * Test to see if the flag has been set on this object.
  47. *
  48. * @param flag
  49. * the flag to test.
  50. * @return true if the flag has been added to this object; false if not.
  51. */
  52. public final boolean has(RevFlag flag) {
  53. return (flags & flag.mask) != 0;
  54. }
  55. /**
  56. * Test to see if any flag in the set has been set on this object.
  57. *
  58. * @param set
  59. * the flags to test.
  60. * @return true if any flag in the set has been added to this object; false
  61. * if not.
  62. */
  63. public final boolean hasAny(RevFlagSet set) {
  64. return (flags & set.mask) != 0;
  65. }
  66. /**
  67. * Test to see if all flags in the set have been set on this object.
  68. *
  69. * @param set
  70. * the flags to test.
  71. * @return true if all flags of the set have been added to this object;
  72. * false if some or none have been added.
  73. */
  74. public final boolean hasAll(RevFlagSet set) {
  75. return (flags & set.mask) == set.mask;
  76. }
  77. /**
  78. * Add a flag to this object.
  79. * <p>
  80. * If the flag is already set on this object then the method has no effect.
  81. *
  82. * @param flag
  83. * the flag to mark on this object, for later testing.
  84. */
  85. public final void add(RevFlag flag) {
  86. flags |= flag.mask;
  87. }
  88. /**
  89. * Add a set of flags to this object.
  90. *
  91. * @param set
  92. * the set of flags to mark on this object, for later testing.
  93. */
  94. public final void add(RevFlagSet set) {
  95. flags |= set.mask;
  96. }
  97. /**
  98. * Remove a flag from this object.
  99. * <p>
  100. * If the flag is not set on this object then the method has no effect.
  101. *
  102. * @param flag
  103. * the flag to remove from this object.
  104. */
  105. public final void remove(RevFlag flag) {
  106. flags &= ~flag.mask;
  107. }
  108. /**
  109. * Remove a set of flags from this object.
  110. *
  111. * @param set
  112. * the flag to remove from this object.
  113. */
  114. public final void remove(RevFlagSet set) {
  115. flags &= ~set.mask;
  116. }
  117. /** {@inheritDoc} */
  118. @Override
  119. public String toString() {
  120. final StringBuilder s = new StringBuilder();
  121. s.append(Constants.typeString(getType()));
  122. s.append(' ');
  123. s.append(name());
  124. s.append(' ');
  125. appendCoreFlags(s);
  126. return s.toString();
  127. }
  128. /**
  129. * Append a debug description of core RevFlags to a buffer.
  130. *
  131. * @param s
  132. * buffer to append a debug description of core RevFlags onto.
  133. */
  134. protected void appendCoreFlags(StringBuilder s) {
  135. s.append((flags & RevWalk.TOPO_QUEUED) != 0 ? 'o' : '-');
  136. s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');
  137. s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');
  138. s.append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');
  139. s.append((flags & RevWalk.SEEN) != 0 ? 's' : '-');
  140. s.append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');
  141. }
  142. }