您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ObjectIdRef.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.lib;
  45. /** A {@link Ref} that points directly at an {@link ObjectId}. */
  46. public abstract class ObjectIdRef implements Ref {
  47. /** Any reference whose peeled value is not yet known. */
  48. public static class Unpeeled extends ObjectIdRef {
  49. /**
  50. * Create a new ref pairing.
  51. *
  52. * @param st
  53. * method used to store this ref.
  54. * @param name
  55. * name of this ref.
  56. * @param id
  57. * current value of the ref. May be null to indicate a ref
  58. * that does not exist yet.
  59. */
  60. public Unpeeled(Storage st, String name, ObjectId id) {
  61. super(st, name, id);
  62. }
  63. public ObjectId getPeeledObjectId() {
  64. return null;
  65. }
  66. public boolean isPeeled() {
  67. return false;
  68. }
  69. }
  70. /** An annotated tag whose peeled object has been cached. */
  71. public static class PeeledTag extends ObjectIdRef {
  72. private final ObjectId peeledObjectId;
  73. /**
  74. * Create a new ref pairing.
  75. *
  76. * @param st
  77. * method used to store this ref.
  78. * @param name
  79. * name of this ref.
  80. * @param id
  81. * current value of the ref.
  82. * @param p
  83. * the first non-tag object that tag {@code id} points to.
  84. */
  85. public PeeledTag(Storage st, String name, ObjectId id, ObjectId p) {
  86. super(st, name, id);
  87. peeledObjectId = p;
  88. }
  89. public ObjectId getPeeledObjectId() {
  90. return peeledObjectId;
  91. }
  92. public boolean isPeeled() {
  93. return true;
  94. }
  95. }
  96. /** A reference to a non-tag object coming from a cached source. */
  97. public static class PeeledNonTag extends ObjectIdRef {
  98. /**
  99. * Create a new ref pairing.
  100. *
  101. * @param st
  102. * method used to store this ref.
  103. * @param name
  104. * name of this ref.
  105. * @param id
  106. * current value of the ref. May be null to indicate a ref
  107. * that does not exist yet.
  108. */
  109. public PeeledNonTag(Storage st, String name, ObjectId id) {
  110. super(st, name, id);
  111. }
  112. public ObjectId getPeeledObjectId() {
  113. return null;
  114. }
  115. public boolean isPeeled() {
  116. return true;
  117. }
  118. }
  119. private final String name;
  120. private final Storage storage;
  121. private final ObjectId objectId;
  122. /**
  123. * Create a new ref pairing.
  124. *
  125. * @param st
  126. * method used to store this ref.
  127. * @param name
  128. * name of this ref.
  129. * @param id
  130. * current value of the ref. May be null to indicate a ref that
  131. * does not exist yet.
  132. */
  133. protected ObjectIdRef(Storage st, String name, ObjectId id) {
  134. this.name = name;
  135. this.storage = st;
  136. this.objectId = id;
  137. }
  138. public String getName() {
  139. return name;
  140. }
  141. public boolean isSymbolic() {
  142. return false;
  143. }
  144. public Ref getLeaf() {
  145. return this;
  146. }
  147. public Ref getTarget() {
  148. return this;
  149. }
  150. public ObjectId getObjectId() {
  151. return objectId;
  152. }
  153. public Storage getStorage() {
  154. return storage;
  155. }
  156. @Override
  157. public String toString() {
  158. StringBuilder r = new StringBuilder();
  159. r.append("Ref["); //$NON-NLS-1$
  160. r.append(getName());
  161. r.append('=');
  162. r.append(ObjectId.toString(getObjectId()));
  163. r.append(']');
  164. return r.toString();
  165. }
  166. }