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.

RefDirectory.java 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*
  2. * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
  3. * Copyright (C) 2009-2010, Google Inc.
  4. * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.internal.storage.file;
  47. import static org.eclipse.jgit.lib.Constants.CHARSET;
  48. import static org.eclipse.jgit.lib.Constants.HEAD;
  49. import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH;
  50. import static org.eclipse.jgit.lib.Constants.PACKED_REFS;
  51. import static org.eclipse.jgit.lib.Constants.R_HEADS;
  52. import static org.eclipse.jgit.lib.Constants.R_REFS;
  53. import static org.eclipse.jgit.lib.Constants.R_TAGS;
  54. import static org.eclipse.jgit.lib.Ref.Storage.LOOSE;
  55. import static org.eclipse.jgit.lib.Ref.Storage.NEW;
  56. import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
  57. import java.io.BufferedReader;
  58. import java.io.File;
  59. import java.io.FileInputStream;
  60. import java.io.FileNotFoundException;
  61. import java.io.IOException;
  62. import java.io.InputStreamReader;
  63. import java.security.DigestInputStream;
  64. import java.security.MessageDigest;
  65. import java.text.MessageFormat;
  66. import java.util.Arrays;
  67. import java.util.LinkedList;
  68. import java.util.List;
  69. import java.util.Map;
  70. import java.util.concurrent.atomic.AtomicInteger;
  71. import java.util.concurrent.atomic.AtomicReference;
  72. import org.eclipse.jgit.annotations.NonNull;
  73. import org.eclipse.jgit.errors.InvalidObjectIdException;
  74. import org.eclipse.jgit.errors.LockFailedException;
  75. import org.eclipse.jgit.errors.MissingObjectException;
  76. import org.eclipse.jgit.errors.ObjectWritingException;
  77. import org.eclipse.jgit.events.RefsChangedEvent;
  78. import org.eclipse.jgit.internal.JGitText;
  79. import org.eclipse.jgit.lib.Constants;
  80. import org.eclipse.jgit.lib.ObjectId;
  81. import org.eclipse.jgit.lib.ObjectIdRef;
  82. import org.eclipse.jgit.lib.Ref;
  83. import org.eclipse.jgit.lib.RefComparator;
  84. import org.eclipse.jgit.lib.RefDatabase;
  85. import org.eclipse.jgit.lib.RefUpdate;
  86. import org.eclipse.jgit.lib.RefWriter;
  87. import org.eclipse.jgit.lib.Repository;
  88. import org.eclipse.jgit.lib.SymbolicRef;
  89. import org.eclipse.jgit.revwalk.RevObject;
  90. import org.eclipse.jgit.revwalk.RevTag;
  91. import org.eclipse.jgit.revwalk.RevWalk;
  92. import org.eclipse.jgit.util.FS;
  93. import org.eclipse.jgit.util.FileUtils;
  94. import org.eclipse.jgit.util.IO;
  95. import org.eclipse.jgit.util.RawParseUtils;
  96. import org.eclipse.jgit.util.RefList;
  97. import org.eclipse.jgit.util.RefMap;
  98. import org.slf4j.Logger;
  99. import org.slf4j.LoggerFactory;
  100. /**
  101. * Traditional file system based {@link RefDatabase}.
  102. * <p>
  103. * This is the classical reference database representation for a Git repository.
  104. * References are stored in two formats: loose, and packed.
  105. * <p>
  106. * Loose references are stored as individual files within the {@code refs/}
  107. * directory. The file name matches the reference name and the file contents is
  108. * the current {@link ObjectId} in string form.
  109. * <p>
  110. * Packed references are stored in a single text file named {@code packed-refs}.
  111. * In the packed format, each reference is stored on its own line. This file
  112. * reduces the number of files needed for large reference spaces, reducing the
  113. * overall size of a Git repository on disk.
  114. */
  115. public class RefDirectory extends RefDatabase {
  116. private final static Logger LOG = LoggerFactory
  117. .getLogger(RefDirectory.class);
  118. /** Magic string denoting the start of a symbolic reference file. */
  119. public static final String SYMREF = "ref: "; //$NON-NLS-1$
  120. /** Magic string denoting the header of a packed-refs file. */
  121. public static final String PACKED_REFS_HEADER = "# pack-refs with:"; //$NON-NLS-1$
  122. /** If in the header, denotes the file has peeled data. */
  123. public static final String PACKED_REFS_PEELED = " peeled"; //$NON-NLS-1$
  124. /** The names of the additional refs supported by this class */
  125. private static final String[] additionalRefsNames = new String[] {
  126. Constants.MERGE_HEAD, Constants.FETCH_HEAD, Constants.ORIG_HEAD,
  127. Constants.CHERRY_PICK_HEAD };
  128. private final FileRepository parent;
  129. private final File gitDir;
  130. final File refsDir;
  131. private final ReflogWriter logWriter;
  132. private final File packedRefsFile;
  133. /**
  134. * Immutable sorted list of loose references.
  135. * <p>
  136. * Symbolic references in this collection are stored unresolved, that is
  137. * their target appears to be a new reference with no ObjectId. These are
  138. * converted into resolved references during a get operation, ensuring the
  139. * live value is always returned.
  140. */
  141. private final AtomicReference<RefList<LooseRef>> looseRefs = new AtomicReference<>();
  142. /** Immutable sorted list of packed references. */
  143. final AtomicReference<PackedRefList> packedRefs = new AtomicReference<>();
  144. /**
  145. * Number of modifications made to this database.
  146. * <p>
  147. * This counter is incremented when a change is made, or detected from the
  148. * filesystem during a read operation.
  149. */
  150. private final AtomicInteger modCnt = new AtomicInteger();
  151. /**
  152. * Last {@link #modCnt} that we sent to listeners.
  153. * <p>
  154. * This value is compared to {@link #modCnt}, and a notification is sent to
  155. * the listeners only when it differs.
  156. */
  157. private final AtomicInteger lastNotifiedModCnt = new AtomicInteger();
  158. RefDirectory(final FileRepository db) {
  159. final FS fs = db.getFS();
  160. parent = db;
  161. gitDir = db.getDirectory();
  162. logWriter = new ReflogWriter(db);
  163. refsDir = fs.resolve(gitDir, R_REFS);
  164. packedRefsFile = fs.resolve(gitDir, PACKED_REFS);
  165. looseRefs.set(RefList.<LooseRef> emptyList());
  166. packedRefs.set(PackedRefList.NO_PACKED_REFS);
  167. }
  168. Repository getRepository() {
  169. return parent;
  170. }
  171. ReflogWriter getLogWriter() {
  172. return logWriter;
  173. }
  174. @Override
  175. public void create() throws IOException {
  176. FileUtils.mkdir(refsDir);
  177. FileUtils.mkdir(new File(refsDir, R_HEADS.substring(R_REFS.length())));
  178. FileUtils.mkdir(new File(refsDir, R_TAGS.substring(R_REFS.length())));
  179. logWriter.create();
  180. }
  181. @Override
  182. public void close() {
  183. clearReferences();
  184. }
  185. private void clearReferences() {
  186. looseRefs.set(RefList.<LooseRef> emptyList());
  187. packedRefs.set(PackedRefList.NO_PACKED_REFS);
  188. }
  189. @Override
  190. public void refresh() {
  191. super.refresh();
  192. clearReferences();
  193. }
  194. @Override
  195. public boolean isNameConflicting(String name) throws IOException {
  196. RefList<Ref> packed = getPackedRefs();
  197. RefList<LooseRef> loose = getLooseRefs();
  198. // Cannot be nested within an existing reference.
  199. int lastSlash = name.lastIndexOf('/');
  200. while (0 < lastSlash) {
  201. String needle = name.substring(0, lastSlash);
  202. if (loose.contains(needle) || packed.contains(needle))
  203. return true;
  204. lastSlash = name.lastIndexOf('/', lastSlash - 1);
  205. }
  206. // Cannot be the container of an existing reference.
  207. String prefix = name + '/';
  208. int idx;
  209. idx = -(packed.find(prefix) + 1);
  210. if (idx < packed.size() && packed.get(idx).getName().startsWith(prefix))
  211. return true;
  212. idx = -(loose.find(prefix) + 1);
  213. if (idx < loose.size() && loose.get(idx).getName().startsWith(prefix))
  214. return true;
  215. return false;
  216. }
  217. private RefList<LooseRef> getLooseRefs() {
  218. final RefList<LooseRef> oldLoose = looseRefs.get();
  219. LooseScanner scan = new LooseScanner(oldLoose);
  220. scan.scan(ALL);
  221. RefList<LooseRef> loose;
  222. if (scan.newLoose != null) {
  223. loose = scan.newLoose.toRefList();
  224. if (looseRefs.compareAndSet(oldLoose, loose))
  225. modCnt.incrementAndGet();
  226. } else
  227. loose = oldLoose;
  228. return loose;
  229. }
  230. @Override
  231. public Ref exactRef(String name) throws IOException {
  232. RefList<Ref> packed = getPackedRefs();
  233. Ref ref;
  234. try {
  235. ref = readRef(name, packed);
  236. if (ref != null) {
  237. ref = resolve(ref, 0, null, null, packed);
  238. }
  239. } catch (IOException e) {
  240. if (name.contains("/") //$NON-NLS-1$
  241. || !(e.getCause() instanceof InvalidObjectIdException)) {
  242. throw e;
  243. }
  244. // While looking for a ref outside of refs/ (e.g., 'config'), we
  245. // found a non-ref file (e.g., a config file) instead. Treat this
  246. // as a ref-not-found condition.
  247. ref = null;
  248. }
  249. fireRefsChanged();
  250. return ref;
  251. }
  252. @Override
  253. public Ref getRef(final String needle) throws IOException {
  254. final RefList<Ref> packed = getPackedRefs();
  255. Ref ref = null;
  256. for (String prefix : SEARCH_PATH) {
  257. try {
  258. ref = readRef(prefix + needle, packed);
  259. if (ref != null) {
  260. ref = resolve(ref, 0, null, null, packed);
  261. }
  262. if (ref != null) {
  263. break;
  264. }
  265. } catch (IOException e) {
  266. if (!(!needle.contains("/") && "".equals(prefix) && e //$NON-NLS-1$ //$NON-NLS-2$
  267. .getCause() instanceof InvalidObjectIdException)) {
  268. throw e;
  269. }
  270. }
  271. }
  272. fireRefsChanged();
  273. return ref;
  274. }
  275. @Override
  276. public Map<String, Ref> getRefs(String prefix) throws IOException {
  277. final RefList<LooseRef> oldLoose = looseRefs.get();
  278. LooseScanner scan = new LooseScanner(oldLoose);
  279. scan.scan(prefix);
  280. final RefList<Ref> packed = getPackedRefs();
  281. RefList<LooseRef> loose;
  282. if (scan.newLoose != null) {
  283. scan.newLoose.sort();
  284. loose = scan.newLoose.toRefList();
  285. if (looseRefs.compareAndSet(oldLoose, loose))
  286. modCnt.incrementAndGet();
  287. } else
  288. loose = oldLoose;
  289. fireRefsChanged();
  290. RefList.Builder<Ref> symbolic = scan.symbolic;
  291. for (int idx = 0; idx < symbolic.size();) {
  292. final Ref symbolicRef = symbolic.get(idx);
  293. final Ref resolvedRef = resolve(symbolicRef, 0, prefix, loose, packed);
  294. if (resolvedRef != null && resolvedRef.getObjectId() != null) {
  295. symbolic.set(idx, resolvedRef);
  296. idx++;
  297. } else {
  298. // A broken symbolic reference, we have to drop it from the
  299. // collections the client is about to receive. Should be a
  300. // rare occurrence so pay a copy penalty.
  301. symbolic.remove(idx);
  302. final int toRemove = loose.find(symbolicRef.getName());
  303. if (0 <= toRemove)
  304. loose = loose.remove(toRemove);
  305. }
  306. }
  307. symbolic.sort();
  308. return new RefMap(prefix, packed, upcast(loose), symbolic.toRefList());
  309. }
  310. @Override
  311. public List<Ref> getAdditionalRefs() throws IOException {
  312. List<Ref> ret = new LinkedList<>();
  313. for (String name : additionalRefsNames) {
  314. Ref r = getRef(name);
  315. if (r != null)
  316. ret.add(r);
  317. }
  318. return ret;
  319. }
  320. @SuppressWarnings("unchecked")
  321. private RefList<Ref> upcast(RefList<? extends Ref> loose) {
  322. return (RefList<Ref>) loose;
  323. }
  324. private class LooseScanner {
  325. private final RefList<LooseRef> curLoose;
  326. private int curIdx;
  327. final RefList.Builder<Ref> symbolic = new RefList.Builder<>(4);
  328. RefList.Builder<LooseRef> newLoose;
  329. LooseScanner(final RefList<LooseRef> curLoose) {
  330. this.curLoose = curLoose;
  331. }
  332. void scan(String prefix) {
  333. if (ALL.equals(prefix)) {
  334. scanOne(HEAD);
  335. scanTree(R_REFS, refsDir);
  336. // If any entries remain, they are deleted, drop them.
  337. if (newLoose == null && curIdx < curLoose.size())
  338. newLoose = curLoose.copy(curIdx);
  339. } else if (prefix.startsWith(R_REFS) && prefix.endsWith("/")) { //$NON-NLS-1$
  340. curIdx = -(curLoose.find(prefix) + 1);
  341. File dir = new File(refsDir, prefix.substring(R_REFS.length()));
  342. scanTree(prefix, dir);
  343. // Skip over entries still within the prefix; these have
  344. // been removed from the directory.
  345. while (curIdx < curLoose.size()) {
  346. if (!curLoose.get(curIdx).getName().startsWith(prefix))
  347. break;
  348. if (newLoose == null)
  349. newLoose = curLoose.copy(curIdx);
  350. curIdx++;
  351. }
  352. // Keep any entries outside of the prefix space, we
  353. // do not know anything about their status.
  354. if (newLoose != null) {
  355. while (curIdx < curLoose.size())
  356. newLoose.add(curLoose.get(curIdx++));
  357. }
  358. }
  359. }
  360. private boolean scanTree(String prefix, File dir) {
  361. final String[] entries = dir.list(LockFile.FILTER);
  362. if (entries == null) // not a directory or an I/O error
  363. return false;
  364. if (0 < entries.length) {
  365. for (int i = 0; i < entries.length; ++i) {
  366. String e = entries[i];
  367. File f = new File(dir, e);
  368. if (f.isDirectory())
  369. entries[i] += '/';
  370. }
  371. Arrays.sort(entries);
  372. for (String name : entries) {
  373. if (name.charAt(name.length() - 1) == '/')
  374. scanTree(prefix + name, new File(dir, name));
  375. else
  376. scanOne(prefix + name);
  377. }
  378. }
  379. return true;
  380. }
  381. private void scanOne(String name) {
  382. LooseRef cur;
  383. if (curIdx < curLoose.size()) {
  384. do {
  385. cur = curLoose.get(curIdx);
  386. int cmp = RefComparator.compareTo(cur, name);
  387. if (cmp < 0) {
  388. // Reference is not loose anymore, its been deleted.
  389. // Skip the name in the new result list.
  390. if (newLoose == null)
  391. newLoose = curLoose.copy(curIdx);
  392. curIdx++;
  393. cur = null;
  394. continue;
  395. }
  396. if (cmp > 0) // Newly discovered loose reference.
  397. cur = null;
  398. break;
  399. } while (curIdx < curLoose.size());
  400. } else
  401. cur = null; // Newly discovered loose reference.
  402. LooseRef n;
  403. try {
  404. n = scanRef(cur, name);
  405. } catch (IOException notValid) {
  406. n = null;
  407. }
  408. if (n != null) {
  409. if (cur != n && newLoose == null)
  410. newLoose = curLoose.copy(curIdx);
  411. if (newLoose != null)
  412. newLoose.add(n);
  413. if (n.isSymbolic())
  414. symbolic.add(n);
  415. } else if (cur != null) {
  416. // Tragically, this file is no longer a loose reference.
  417. // Kill our cached entry of it.
  418. if (newLoose == null)
  419. newLoose = curLoose.copy(curIdx);
  420. }
  421. if (cur != null)
  422. curIdx++;
  423. }
  424. }
  425. @Override
  426. public Ref peel(final Ref ref) throws IOException {
  427. final Ref leaf = ref.getLeaf();
  428. if (leaf.isPeeled() || leaf.getObjectId() == null)
  429. return ref;
  430. ObjectIdRef newLeaf = doPeel(leaf);
  431. // Try to remember this peeling in the cache, so we don't have to do
  432. // it again in the future, but only if the reference is unchanged.
  433. if (leaf.getStorage().isLoose()) {
  434. RefList<LooseRef> curList = looseRefs.get();
  435. int idx = curList.find(leaf.getName());
  436. if (0 <= idx && curList.get(idx) == leaf) {
  437. LooseRef asPeeled = ((LooseRef) leaf).peel(newLeaf);
  438. RefList<LooseRef> newList = curList.set(idx, asPeeled);
  439. looseRefs.compareAndSet(curList, newList);
  440. }
  441. }
  442. return recreate(ref, newLeaf);
  443. }
  444. private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException,
  445. IOException {
  446. try (RevWalk rw = new RevWalk(getRepository())) {
  447. RevObject obj = rw.parseAny(leaf.getObjectId());
  448. if (obj instanceof RevTag) {
  449. return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf
  450. .getName(), leaf.getObjectId(), rw.peel(obj).copy());
  451. } else {
  452. return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf
  453. .getName(), leaf.getObjectId());
  454. }
  455. }
  456. }
  457. private static Ref recreate(final Ref old, final ObjectIdRef leaf) {
  458. if (old.isSymbolic()) {
  459. Ref dst = recreate(old.getTarget(), leaf);
  460. return new SymbolicRef(old.getName(), dst);
  461. }
  462. return leaf;
  463. }
  464. void storedSymbolicRef(RefDirectoryUpdate u, FileSnapshot snapshot,
  465. String target) {
  466. putLooseRef(newSymbolicRef(snapshot, u.getRef().getName(), target));
  467. fireRefsChanged();
  468. }
  469. @Override
  470. public RefDirectoryUpdate newUpdate(String name, boolean detach)
  471. throws IOException {
  472. boolean detachingSymbolicRef = false;
  473. final RefList<Ref> packed = getPackedRefs();
  474. Ref ref = readRef(name, packed);
  475. if (ref != null)
  476. ref = resolve(ref, 0, null, null, packed);
  477. if (ref == null)
  478. ref = new ObjectIdRef.Unpeeled(NEW, name, null);
  479. else {
  480. detachingSymbolicRef = detach && ref.isSymbolic();
  481. }
  482. RefDirectoryUpdate refDirUpdate = new RefDirectoryUpdate(this, ref);
  483. if (detachingSymbolicRef)
  484. refDirUpdate.setDetachingSymbolicRef();
  485. return refDirUpdate;
  486. }
  487. @Override
  488. public RefDirectoryRename newRename(String fromName, String toName)
  489. throws IOException {
  490. RefDirectoryUpdate from = newUpdate(fromName, false);
  491. RefDirectoryUpdate to = newUpdate(toName, false);
  492. return new RefDirectoryRename(from, to);
  493. }
  494. void stored(RefDirectoryUpdate update, FileSnapshot snapshot) {
  495. final ObjectId target = update.getNewObjectId().copy();
  496. final Ref leaf = update.getRef().getLeaf();
  497. putLooseRef(new LooseUnpeeled(snapshot, leaf.getName(), target));
  498. }
  499. private void putLooseRef(LooseRef ref) {
  500. RefList<LooseRef> cList, nList;
  501. do {
  502. cList = looseRefs.get();
  503. nList = cList.put(ref);
  504. } while (!looseRefs.compareAndSet(cList, nList));
  505. modCnt.incrementAndGet();
  506. fireRefsChanged();
  507. }
  508. void delete(RefDirectoryUpdate update) throws IOException {
  509. Ref dst = update.getRef();
  510. String name = dst.getName();
  511. // Write the packed-refs file using an atomic update. We might
  512. // wind up reading it twice, before and after the lock, to ensure
  513. // we don't miss an edit made externally.
  514. final PackedRefList packed = getPackedRefs();
  515. if (packed.contains(name)) {
  516. LockFile lck = new LockFile(packedRefsFile);
  517. if (!lck.lock())
  518. throw new LockFailedException(packedRefsFile);
  519. try {
  520. PackedRefList cur = readPackedRefs();
  521. int idx = cur.find(name);
  522. if (0 <= idx)
  523. commitPackedRefs(lck, cur.remove(idx), packed);
  524. } finally {
  525. lck.unlock();
  526. }
  527. }
  528. RefList<LooseRef> curLoose, newLoose;
  529. do {
  530. curLoose = looseRefs.get();
  531. int idx = curLoose.find(name);
  532. if (idx < 0)
  533. break;
  534. newLoose = curLoose.remove(idx);
  535. } while (!looseRefs.compareAndSet(curLoose, newLoose));
  536. int levels = levelsIn(name) - 2;
  537. delete(logWriter.logFor(name), levels);
  538. if (dst.getStorage().isLoose()) {
  539. update.unlock();
  540. delete(fileFor(name), levels);
  541. }
  542. modCnt.incrementAndGet();
  543. fireRefsChanged();
  544. }
  545. /**
  546. * Adds a set of refs to the set of packed-refs. Only non-symbolic refs are
  547. * added. If a ref with the given name already existed in packed-refs it is
  548. * updated with the new value. Each loose ref which was added to the
  549. * packed-ref file is deleted. If a given ref can't be locked it will not be
  550. * added to the pack file.
  551. *
  552. * @param refs
  553. * the refs to be added. Must be fully qualified.
  554. * @throws IOException
  555. */
  556. public void pack(List<String> refs) throws IOException {
  557. if (refs.size() == 0)
  558. return;
  559. FS fs = parent.getFS();
  560. // Lock the packed refs file and read the content
  561. LockFile lck = new LockFile(packedRefsFile);
  562. if (!lck.lock())
  563. throw new IOException(MessageFormat.format(
  564. JGitText.get().cannotLock, packedRefsFile));
  565. try {
  566. final PackedRefList packed = getPackedRefs();
  567. RefList<Ref> cur = readPackedRefs();
  568. // Iterate over all refs to be packed
  569. boolean dirty = false;
  570. for (String refName : refs) {
  571. Ref oldRef = readRef(refName, cur);
  572. if (oldRef.isSymbolic()) {
  573. continue; // can't pack symbolic refs
  574. }
  575. // Add/Update it to packed-refs
  576. Ref newRef = peeledPackedRef(oldRef);
  577. if (newRef == oldRef) {
  578. // No-op; peeledPackedRef returns the input ref only if it's already
  579. // packed, and readRef returns a packed ref only if there is no loose
  580. // ref.
  581. continue;
  582. }
  583. dirty = true;
  584. int idx = cur.find(refName);
  585. if (idx >= 0) {
  586. cur = cur.set(idx, newRef);
  587. } else {
  588. cur = cur.add(idx, newRef);
  589. }
  590. }
  591. if (!dirty) {
  592. // All requested refs were already packed accurately
  593. return;
  594. }
  595. // The new content for packed-refs is collected. Persist it.
  596. commitPackedRefs(lck, cur, packed);
  597. // Now delete the loose refs which are now packed
  598. for (String refName : refs) {
  599. // Lock the loose ref
  600. File refFile = fileFor(refName);
  601. if (!fs.exists(refFile))
  602. continue;
  603. LockFile rLck = new LockFile(refFile);
  604. if (!rLck.lock())
  605. continue;
  606. try {
  607. LooseRef currentLooseRef = scanRef(null, refName);
  608. if (currentLooseRef == null || currentLooseRef.isSymbolic())
  609. continue;
  610. Ref packedRef = cur.get(refName);
  611. ObjectId clr_oid = currentLooseRef.getObjectId();
  612. if (clr_oid != null
  613. && clr_oid.equals(packedRef.getObjectId())) {
  614. RefList<LooseRef> curLoose, newLoose;
  615. do {
  616. curLoose = looseRefs.get();
  617. int idx = curLoose.find(refName);
  618. if (idx < 0)
  619. break;
  620. newLoose = curLoose.remove(idx);
  621. } while (!looseRefs.compareAndSet(curLoose, newLoose));
  622. int levels = levelsIn(refName) - 2;
  623. delete(refFile, levels, rLck);
  624. }
  625. } finally {
  626. rLck.unlock();
  627. }
  628. }
  629. // Don't fire refsChanged. The refs have not change, only their
  630. // storage.
  631. } finally {
  632. lck.unlock();
  633. }
  634. }
  635. /**
  636. * Make sure a ref is peeled and has the Storage PACKED. If the given ref
  637. * has this attributes simply return it. Otherwise create a new peeled
  638. * {@link ObjectIdRef} where Storage is set to PACKED.
  639. *
  640. * @param f
  641. * @return a ref for Storage PACKED having the same name, id, peeledId as f
  642. * @throws MissingObjectException
  643. * @throws IOException
  644. */
  645. private Ref peeledPackedRef(Ref f)
  646. throws MissingObjectException, IOException {
  647. if (f.getStorage().isPacked() && f.isPeeled()) {
  648. return f;
  649. }
  650. if (!f.isPeeled()) {
  651. f = peel(f);
  652. }
  653. ObjectId peeledObjectId = f.getPeeledObjectId();
  654. if (peeledObjectId != null) {
  655. return new ObjectIdRef.PeeledTag(PACKED, f.getName(),
  656. f.getObjectId(), peeledObjectId);
  657. } else {
  658. return new ObjectIdRef.PeeledNonTag(PACKED, f.getName(),
  659. f.getObjectId());
  660. }
  661. }
  662. void log(final RefUpdate update, final String msg, final boolean deref)
  663. throws IOException {
  664. logWriter.log(update, msg, deref);
  665. }
  666. private Ref resolve(final Ref ref, int depth, String prefix,
  667. RefList<LooseRef> loose, RefList<Ref> packed) throws IOException {
  668. if (ref.isSymbolic()) {
  669. Ref dst = ref.getTarget();
  670. if (MAX_SYMBOLIC_REF_DEPTH <= depth)
  671. return null; // claim it doesn't exist
  672. // If the cached value can be assumed to be current due to a
  673. // recent scan of the loose directory, use it.
  674. if (loose != null && dst.getName().startsWith(prefix)) {
  675. int idx;
  676. if (0 <= (idx = loose.find(dst.getName())))
  677. dst = loose.get(idx);
  678. else if (0 <= (idx = packed.find(dst.getName())))
  679. dst = packed.get(idx);
  680. else
  681. return ref;
  682. } else {
  683. dst = readRef(dst.getName(), packed);
  684. if (dst == null)
  685. return ref;
  686. }
  687. dst = resolve(dst, depth + 1, prefix, loose, packed);
  688. if (dst == null)
  689. return null;
  690. return new SymbolicRef(ref.getName(), dst);
  691. }
  692. return ref;
  693. }
  694. private PackedRefList getPackedRefs() throws IOException {
  695. final PackedRefList curList = packedRefs.get();
  696. if (!curList.snapshot.isModified(packedRefsFile))
  697. return curList;
  698. final PackedRefList newList = readPackedRefs();
  699. if (packedRefs.compareAndSet(curList, newList)
  700. && !curList.id.equals(newList.id))
  701. modCnt.incrementAndGet();
  702. return newList;
  703. }
  704. private PackedRefList readPackedRefs() throws IOException {
  705. int maxStaleRetries = 5;
  706. int retries = 0;
  707. while (true) {
  708. final FileSnapshot snapshot = FileSnapshot.save(packedRefsFile);
  709. final BufferedReader br;
  710. final MessageDigest digest = Constants.newMessageDigest();
  711. try {
  712. br = new BufferedReader(new InputStreamReader(
  713. new DigestInputStream(new FileInputStream(packedRefsFile),
  714. digest), CHARSET));
  715. } catch (FileNotFoundException noPackedRefs) {
  716. if (packedRefsFile.exists()) {
  717. throw noPackedRefs;
  718. }
  719. // Ignore it and leave the new list empty.
  720. return PackedRefList.NO_PACKED_REFS;
  721. }
  722. try {
  723. return new PackedRefList(parsePackedRefs(br), snapshot,
  724. ObjectId.fromRaw(digest.digest()));
  725. } catch (IOException e) {
  726. if (FileUtils.isStaleFileHandleInCausalChain(e)
  727. && retries < maxStaleRetries) {
  728. if (LOG.isDebugEnabled()) {
  729. LOG.debug(MessageFormat.format(
  730. JGitText.get().packedRefsHandleIsStale,
  731. Integer.valueOf(retries)), e);
  732. }
  733. retries++;
  734. continue;
  735. }
  736. throw e;
  737. } finally {
  738. br.close();
  739. }
  740. }
  741. }
  742. private RefList<Ref> parsePackedRefs(final BufferedReader br)
  743. throws IOException {
  744. RefList.Builder<Ref> all = new RefList.Builder<>();
  745. Ref last = null;
  746. boolean peeled = false;
  747. boolean needSort = false;
  748. String p;
  749. while ((p = br.readLine()) != null) {
  750. if (p.charAt(0) == '#') {
  751. if (p.startsWith(PACKED_REFS_HEADER)) {
  752. p = p.substring(PACKED_REFS_HEADER.length());
  753. peeled = p.contains(PACKED_REFS_PEELED);
  754. }
  755. continue;
  756. }
  757. if (p.charAt(0) == '^') {
  758. if (last == null)
  759. throw new IOException(JGitText.get().peeledLineBeforeRef);
  760. ObjectId id = ObjectId.fromString(p.substring(1));
  761. last = new ObjectIdRef.PeeledTag(PACKED, last.getName(), last
  762. .getObjectId(), id);
  763. all.set(all.size() - 1, last);
  764. continue;
  765. }
  766. int sp = p.indexOf(' ');
  767. if (sp < 0) {
  768. throw new IOException(MessageFormat.format(
  769. JGitText.get().packedRefsCorruptionDetected,
  770. packedRefsFile.getAbsolutePath()));
  771. }
  772. ObjectId id = ObjectId.fromString(p.substring(0, sp));
  773. String name = copy(p, sp + 1, p.length());
  774. ObjectIdRef cur;
  775. if (peeled)
  776. cur = new ObjectIdRef.PeeledNonTag(PACKED, name, id);
  777. else
  778. cur = new ObjectIdRef.Unpeeled(PACKED, name, id);
  779. if (last != null && RefComparator.compareTo(last, cur) > 0)
  780. needSort = true;
  781. all.add(cur);
  782. last = cur;
  783. }
  784. if (needSort)
  785. all.sort();
  786. return all.toRefList();
  787. }
  788. private static String copy(final String src, final int off, final int end) {
  789. // Don't use substring since it could leave a reference to the much
  790. // larger existing string. Force construction of a full new object.
  791. return new StringBuilder(end - off).append(src, off, end).toString();
  792. }
  793. private void commitPackedRefs(final LockFile lck, final RefList<Ref> refs,
  794. final PackedRefList oldPackedList) throws IOException {
  795. new RefWriter(refs) {
  796. @Override
  797. protected void writeFile(String name, byte[] content)
  798. throws IOException {
  799. lck.setFSync(true);
  800. lck.setNeedSnapshot(true);
  801. try {
  802. lck.write(content);
  803. } catch (IOException ioe) {
  804. throw new ObjectWritingException(MessageFormat.format(JGitText.get().unableToWrite, name), ioe);
  805. }
  806. try {
  807. lck.waitForStatChange();
  808. } catch (InterruptedException e) {
  809. lck.unlock();
  810. throw new ObjectWritingException(MessageFormat.format(JGitText.get().interruptedWriting, name));
  811. }
  812. if (!lck.commit())
  813. throw new ObjectWritingException(MessageFormat.format(JGitText.get().unableToWrite, name));
  814. byte[] digest = Constants.newMessageDigest().digest(content);
  815. PackedRefList newPackedList = new PackedRefList(
  816. refs, lck.getCommitSnapshot(), ObjectId.fromRaw(digest));
  817. // This thread holds the file lock, so no other thread or process should
  818. // be able to modify the packed-refs file on disk. If the list changed,
  819. // it means something is very wrong, so throw an exception.
  820. //
  821. // However, we can't use a naive compareAndSet to check whether the
  822. // update was successful, because another thread might _read_ the
  823. // packed refs file that was written out by this thread while holding
  824. // the lock, and update the packedRefs reference to point to that. So
  825. // compare the actual contents instead.
  826. PackedRefList afterUpdate = packedRefs.updateAndGet(
  827. p -> p.id.equals(oldPackedList.id) ? newPackedList : p);
  828. if (!afterUpdate.id.equals(newPackedList.id)) {
  829. throw new ObjectWritingException(
  830. MessageFormat.format(JGitText.get().unableToWrite, name));
  831. }
  832. }
  833. }.writePackedRefs();
  834. }
  835. private Ref readRef(String name, RefList<Ref> packed) throws IOException {
  836. final RefList<LooseRef> curList = looseRefs.get();
  837. final int idx = curList.find(name);
  838. if (0 <= idx) {
  839. final LooseRef o = curList.get(idx);
  840. final LooseRef n = scanRef(o, name);
  841. if (n == null) {
  842. if (looseRefs.compareAndSet(curList, curList.remove(idx)))
  843. modCnt.incrementAndGet();
  844. return packed.get(name);
  845. }
  846. if (o == n)
  847. return n;
  848. if (looseRefs.compareAndSet(curList, curList.set(idx, n)))
  849. modCnt.incrementAndGet();
  850. return n;
  851. }
  852. final LooseRef n = scanRef(null, name);
  853. if (n == null)
  854. return packed.get(name);
  855. // check whether the found new ref is the an additional ref. These refs
  856. // should not go into looseRefs
  857. for (int i = 0; i < additionalRefsNames.length; i++)
  858. if (name.equals(additionalRefsNames[i]))
  859. return n;
  860. if (looseRefs.compareAndSet(curList, curList.add(idx, n)))
  861. modCnt.incrementAndGet();
  862. return n;
  863. }
  864. LooseRef scanRef(LooseRef ref, String name) throws IOException {
  865. final File path = fileFor(name);
  866. FileSnapshot currentSnapshot = null;
  867. if (ref != null) {
  868. currentSnapshot = ref.getSnapShot();
  869. if (!currentSnapshot.isModified(path))
  870. return ref;
  871. name = ref.getName();
  872. }
  873. final int limit = 4096;
  874. final byte[] buf;
  875. FileSnapshot otherSnapshot = FileSnapshot.save(path);
  876. try {
  877. buf = IO.readSome(path, limit);
  878. } catch (FileNotFoundException noFile) {
  879. if (path.exists() && path.isFile()) {
  880. throw noFile;
  881. }
  882. return null; // doesn't exist or no file; not a reference.
  883. }
  884. int n = buf.length;
  885. if (n == 0)
  886. return null; // empty file; not a reference.
  887. if (isSymRef(buf, n)) {
  888. if (n == limit)
  889. return null; // possibly truncated ref
  890. // trim trailing whitespace
  891. while (0 < n && Character.isWhitespace(buf[n - 1]))
  892. n--;
  893. if (n < 6) {
  894. String content = RawParseUtils.decode(buf, 0, n);
  895. throw new IOException(MessageFormat.format(JGitText.get().notARef, name, content));
  896. }
  897. final String target = RawParseUtils.decode(buf, 5, n);
  898. if (ref != null && ref.isSymbolic()
  899. && ref.getTarget().getName().equals(target)) {
  900. assert(currentSnapshot != null);
  901. currentSnapshot.setClean(otherSnapshot);
  902. return ref;
  903. }
  904. return newSymbolicRef(otherSnapshot, name, target);
  905. }
  906. if (n < OBJECT_ID_STRING_LENGTH)
  907. return null; // impossibly short object identifier; not a reference.
  908. final ObjectId id;
  909. try {
  910. id = ObjectId.fromString(buf, 0);
  911. if (ref != null && !ref.isSymbolic()
  912. && id.equals(ref.getTarget().getObjectId())) {
  913. assert(currentSnapshot != null);
  914. currentSnapshot.setClean(otherSnapshot);
  915. return ref;
  916. }
  917. } catch (IllegalArgumentException notRef) {
  918. while (0 < n && Character.isWhitespace(buf[n - 1]))
  919. n--;
  920. String content = RawParseUtils.decode(buf, 0, n);
  921. IOException ioException = new IOException(MessageFormat.format(JGitText.get().notARef,
  922. name, content));
  923. ioException.initCause(notRef);
  924. throw ioException;
  925. }
  926. return new LooseUnpeeled(otherSnapshot, name, id);
  927. }
  928. private static boolean isSymRef(final byte[] buf, int n) {
  929. if (n < 6)
  930. return false;
  931. return /**/buf[0] == 'r' //
  932. && buf[1] == 'e' //
  933. && buf[2] == 'f' //
  934. && buf[3] == ':' //
  935. && buf[4] == ' ';
  936. }
  937. /** If the parent should fire listeners, fires them. */
  938. private void fireRefsChanged() {
  939. final int last = lastNotifiedModCnt.get();
  940. final int curr = modCnt.get();
  941. if (last != curr && lastNotifiedModCnt.compareAndSet(last, curr) && last != 0)
  942. parent.fireEvent(new RefsChangedEvent());
  943. }
  944. /**
  945. * Create a reference update to write a temporary reference.
  946. *
  947. * @return an update for a new temporary reference.
  948. * @throws IOException
  949. * a temporary name cannot be allocated.
  950. */
  951. RefDirectoryUpdate newTemporaryUpdate() throws IOException {
  952. File tmp = File.createTempFile("renamed_", "_ref", refsDir); //$NON-NLS-1$ //$NON-NLS-2$
  953. String name = Constants.R_REFS + tmp.getName();
  954. Ref ref = new ObjectIdRef.Unpeeled(NEW, name, null);
  955. return new RefDirectoryUpdate(this, ref);
  956. }
  957. /**
  958. * Locate the file on disk for a single reference name.
  959. *
  960. * @param name
  961. * name of the ref, relative to the Git repository top level
  962. * directory (so typically starts with refs/).
  963. * @return the loose file location.
  964. */
  965. File fileFor(String name) {
  966. if (name.startsWith(R_REFS)) {
  967. name = name.substring(R_REFS.length());
  968. return new File(refsDir, name);
  969. }
  970. return new File(gitDir, name);
  971. }
  972. static int levelsIn(final String name) {
  973. int count = 0;
  974. for (int p = name.indexOf('/'); p >= 0; p = name.indexOf('/', p + 1))
  975. count++;
  976. return count;
  977. }
  978. static void delete(final File file, final int depth) throws IOException {
  979. delete(file, depth, null);
  980. }
  981. private static void delete(final File file, final int depth, LockFile rLck)
  982. throws IOException {
  983. if (!file.delete() && file.isFile()) {
  984. throw new IOException(MessageFormat.format(
  985. JGitText.get().fileCannotBeDeleted, file));
  986. }
  987. if (rLck != null) {
  988. rLck.unlock(); // otherwise cannot delete dir below
  989. }
  990. File dir = file.getParentFile();
  991. for (int i = 0; i < depth; ++i) {
  992. if (!dir.delete()) {
  993. break; // ignore problem here
  994. }
  995. dir = dir.getParentFile();
  996. }
  997. }
  998. private static class PackedRefList extends RefList<Ref> {
  999. static final PackedRefList NO_PACKED_REFS = new PackedRefList(
  1000. RefList.emptyList(), FileSnapshot.MISSING_FILE,
  1001. ObjectId.zeroId());
  1002. final FileSnapshot snapshot;
  1003. final ObjectId id;
  1004. PackedRefList(RefList<Ref> src, FileSnapshot s, ObjectId i) {
  1005. super(src);
  1006. snapshot = s;
  1007. id = i;
  1008. }
  1009. }
  1010. private static LooseSymbolicRef newSymbolicRef(FileSnapshot snapshot,
  1011. String name, String target) {
  1012. Ref dst = new ObjectIdRef.Unpeeled(NEW, target, null);
  1013. return new LooseSymbolicRef(snapshot, name, dst);
  1014. }
  1015. private static interface LooseRef extends Ref {
  1016. FileSnapshot getSnapShot();
  1017. LooseRef peel(ObjectIdRef newLeaf);
  1018. }
  1019. private final static class LoosePeeledTag extends ObjectIdRef.PeeledTag
  1020. implements LooseRef {
  1021. private final FileSnapshot snapShot;
  1022. LoosePeeledTag(FileSnapshot snapshot, @NonNull String refName,
  1023. @NonNull ObjectId id, @NonNull ObjectId p) {
  1024. super(LOOSE, refName, id, p);
  1025. this.snapShot = snapshot;
  1026. }
  1027. @Override
  1028. public FileSnapshot getSnapShot() {
  1029. return snapShot;
  1030. }
  1031. @Override
  1032. public LooseRef peel(ObjectIdRef newLeaf) {
  1033. return this;
  1034. }
  1035. }
  1036. private final static class LooseNonTag extends ObjectIdRef.PeeledNonTag
  1037. implements LooseRef {
  1038. private final FileSnapshot snapShot;
  1039. LooseNonTag(FileSnapshot snapshot, @NonNull String refName,
  1040. @NonNull ObjectId id) {
  1041. super(LOOSE, refName, id);
  1042. this.snapShot = snapshot;
  1043. }
  1044. @Override
  1045. public FileSnapshot getSnapShot() {
  1046. return snapShot;
  1047. }
  1048. @Override
  1049. public LooseRef peel(ObjectIdRef newLeaf) {
  1050. return this;
  1051. }
  1052. }
  1053. private final static class LooseUnpeeled extends ObjectIdRef.Unpeeled
  1054. implements LooseRef {
  1055. private FileSnapshot snapShot;
  1056. LooseUnpeeled(FileSnapshot snapShot, @NonNull String refName,
  1057. @NonNull ObjectId id) {
  1058. super(LOOSE, refName, id);
  1059. this.snapShot = snapShot;
  1060. }
  1061. @Override
  1062. public FileSnapshot getSnapShot() {
  1063. return snapShot;
  1064. }
  1065. @NonNull
  1066. @Override
  1067. public ObjectId getObjectId() {
  1068. ObjectId id = super.getObjectId();
  1069. assert id != null; // checked in constructor
  1070. return id;
  1071. }
  1072. @Override
  1073. public LooseRef peel(ObjectIdRef newLeaf) {
  1074. ObjectId peeledObjectId = newLeaf.getPeeledObjectId();
  1075. ObjectId objectId = getObjectId();
  1076. if (peeledObjectId != null) {
  1077. return new LoosePeeledTag(snapShot, getName(),
  1078. objectId, peeledObjectId);
  1079. } else {
  1080. return new LooseNonTag(snapShot, getName(),
  1081. objectId);
  1082. }
  1083. }
  1084. }
  1085. private final static class LooseSymbolicRef extends SymbolicRef implements
  1086. LooseRef {
  1087. private final FileSnapshot snapShot;
  1088. LooseSymbolicRef(FileSnapshot snapshot, @NonNull String refName,
  1089. @NonNull Ref target) {
  1090. super(refName, target);
  1091. this.snapShot = snapshot;
  1092. }
  1093. @Override
  1094. public FileSnapshot getSnapShot() {
  1095. return snapShot;
  1096. }
  1097. @Override
  1098. public LooseRef peel(ObjectIdRef newLeaf) {
  1099. // We should never try to peel the symbolic references.
  1100. throw new UnsupportedOperationException();
  1101. }
  1102. }
  1103. }