Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Ref


    protected boolean compareAndPut(Ref oldRef, Ref newRef)
        throws IOException {
      String name = newRef.getName();
      if (oldRef == null || oldRef.getStorage() == Storage.NEW)
        return refs.putIfAbsent(name, newRef) == null;
      Ref cur = refs.get(name);
      if (cur != null && eq(cur, oldRef))
        return refs.replace(name, cur, newRef);
      else
        return false;
View Full Code Here


    }

    @Override
    protected boolean compareAndRemove(Ref oldRef) throws IOException {
      String name = oldRef.getName();
      Ref cur = refs.get(name);
      if (cur != null && eq(cur, oldRef))
        return refs.remove(name, cur);
      else
        return false;
    }
View Full Code Here

  }

  @Override
  public Ref getRef(final String needle) throws IOException {
    final RefList<Ref> packed = getPackedRefs();
    Ref ref = null;
    for (String prefix : SEARCH_PATH) {
      ref = readRef(prefix + needle, packed);
      if (ref != null) {
        ref = resolve(ref, 0, null, null, packed);
        break;
View Full Code Here

      loose = oldLoose;
    fireRefsChanged();

    RefList.Builder<Ref> symbolic = scan.symbolic;
    for (int idx = 0; idx < symbolic.size();) {
      final Ref symbolicRef = symbolic.get(idx);
      final Ref resolvedRef = resolve(symbolicRef, 0, prefix, loose, packed);
      if (resolvedRef != null && resolvedRef.getObjectId() != null) {
        symbolic.set(idx, resolvedRef);
        idx++;
      } else {
        // A broken symbolic reference, we have to drop it from the
        // collections the client is about to receive. Should be a
View Full Code Here

  @Override
  public List<Ref> getAdditionalRefs() throws IOException {
    List<Ref> ret = new LinkedList<Ref>();
    for (String name : additionalRefsNames) {
      Ref r = getRef(name);
      if (r != null)
        ret.add(r);
    }
    return ret;
  }
View Full Code Here

    }
  }

  @Override
  public Ref peel(final Ref ref) throws IOException {
    final Ref leaf = ref.getLeaf();
    if (leaf.isPeeled() || leaf.getObjectId() == null)
      return ref;

    ObjectIdRef newLeaf = doPeel(leaf);

    // Try to remember this peeling in the cache, so we don't have to do
    // it again in the future, but only if the reference is unchanged.
    if (leaf.getStorage().isLoose()) {
      RefList<LooseRef> curList = looseRefs.get();
      int idx = curList.find(leaf.getName());
      if (0 <= idx && curList.get(idx) == leaf) {
        LooseRef asPeeled = ((LooseRef) leaf).peel(newLeaf);
        RefList<LooseRef> newList = curList.set(idx, asPeeled);
        looseRefs.compareAndSet(curList, newList);
      }
View Full Code Here

    }
  }

  private static Ref recreate(final Ref old, final ObjectIdRef leaf) {
    if (old.isSymbolic()) {
      Ref dst = recreate(old.getTarget(), leaf);
      return new SymbolicRef(old.getName(), dst);
    }
    return leaf;
  }
View Full Code Here

  public RefDirectoryUpdate newUpdate(String name, boolean detach)
      throws IOException {
    boolean detachingSymbolicRef = false;
    final RefList<Ref> packed = getPackedRefs();
    Ref ref = readRef(name, packed);
    if (ref != null)
      ref = resolve(ref, 0, null, null, packed);
    if (ref == null)
      ref = new ObjectIdRef.Unpeeled(NEW, name, null);
    else {
      detachingSymbolicRef = detach && ref.isSymbolic();
      if (detachingSymbolicRef)
        ref = new ObjectIdRef.Unpeeled(LOOSE, name, ref.getObjectId());
    }
    RefDirectoryUpdate refDirUpdate = new RefDirectoryUpdate(this, ref);
    if (detachingSymbolicRef)
      refDirUpdate.setDetachingSymbolicRef();
    return refDirUpdate;
View Full Code Here

    return new RefDirectoryRename(from, to);
  }

  void stored(RefDirectoryUpdate update, FileSnapshot snapshot) {
    final ObjectId target = update.getNewObjectId().copy();
    final Ref leaf = update.getRef().getLeaf();
    putLooseRef(new LooseUnpeeled(snapshot, leaf.getName(), target));
  }
View Full Code Here

    modCnt.incrementAndGet();
    fireRefsChanged();
  }

  void delete(RefDirectoryUpdate update) throws IOException {
    Ref dst = update.getRef().getLeaf();
    String name = dst.getName();

    // Write the packed-refs file using an atomic update. We might
    // wind up reading it twice, before and after the lock, to ensure
    // we don't miss an edit made externally.
    final PackedRefList packed = getPackedRefs();
    if (packed.contains(name)) {
      LockFile lck = new LockFile(packedRefsFile,
          update.getRepository().getFS());
      if (!lck.lock())
        throw new LockFailedException(packedRefsFile);
      try {
        PackedRefList cur = readPackedRefs();
        int idx = cur.find(name);
        if (0 <= idx)
          commitPackedRefs(lck, cur.remove(idx), packed);
      } finally {
        lck.unlock();
      }
    }

    RefList<LooseRef> curLoose, newLoose;
    do {
      curLoose = looseRefs.get();
      int idx = curLoose.find(name);
      if (idx < 0)
        break;
      newLoose = curLoose.remove(idx);
    } while (!looseRefs.compareAndSet(curLoose, newLoose));

    int levels = levelsIn(name) - 2;
    delete(logFor(name), levels);
    if (dst.getStorage().isLoose()) {
      update.unlock();
      delete(fileFor(name), levels);
    }

    modCnt.incrementAndGet();
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.Ref

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.