Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Ref


    }
  }

  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 IOException(MessageFormat.format(
          JGitText.get().cannotLockFile, 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

  void log(final RefUpdate update, final String msg, final boolean deref)
      throws IOException {
    final ObjectId oldId = update.getOldObjectId();
    final ObjectId newId = update.getNewObjectId();
    final Ref ref = update.getRef();

    PersonIdent ident = update.getRefLogIdent();
    if (ident == null)
      ident = new PersonIdent(parent);
    else
      ident = new PersonIdent(ident);

    final StringBuilder r = new StringBuilder();
    r.append(ObjectId.toString(oldId));
    r.append(' ');
    r.append(ObjectId.toString(newId));
    r.append(' ');
    r.append(ident.toExternalString());
    r.append('\t');
    r.append(msg);
    r.append('\n');
    final byte[] rec = encode(r.toString());

    if (deref && ref.isSymbolic()) {
      log(ref.getName(), rec);
      log(ref.getLeaf().getName(), rec);
    } else {
      log(ref.getName(), rec);
    }
  }
View Full Code Here

  }

  private Ref resolve(final Ref ref, int depth, String prefix,
      RefList<LooseRef> loose, RefList<Ref> packed) throws IOException {
    if (ref.isSymbolic()) {
      Ref dst = ref.getTarget();

      if (MAX_SYMBOLIC_REF_DEPTH <= depth)
        return null; // claim it doesn't exist

      // If the cached value can be assumed to be current due to a
      // recent scan of the loose directory, use it.
      if (loose != null && dst.getName().startsWith(prefix)) {
        int idx;
        if (0 <= (idx = loose.find(dst.getName())))
          dst = loose.get(idx);
        else if (0 <= (idx = packed.find(dst.getName())))
          dst = packed.get(idx);
        else
          return ref;
      } else {
        dst = readRef(dst.getName(), packed);
        if (dst == null)
          return ref;
      }

      dst = resolve(dst, depth + 1, prefix, loose, packed);
View Full Code Here

  }

  private RefList<Ref> parsePackedRefs(final BufferedReader br)
      throws IOException {
    RefList.Builder<Ref> all = new RefList.Builder<Ref>();
    Ref last = null;
    boolean peeled = false;
    boolean needSort = false;

    String p;
    while ((p = br.readLine()) != null) {
      if (p.charAt(0) == '#') {
        if (p.startsWith(PACKED_REFS_HEADER)) {
          p = p.substring(PACKED_REFS_HEADER.length());
          peeled = p.contains(PACKED_REFS_PEELED);
        }
        continue;
      }

      if (p.charAt(0) == '^') {
        if (last == null)
          throw new IOException(JGitText.get().peeledLineBeforeRef);

        ObjectId id = ObjectId.fromString(p.substring(1));
        last = new ObjectIdRef.PeeledTag(PACKED, last.getName(), last
            .getObjectId(), id);
        all.set(all.size() - 1, last);
        continue;
      }
View Full Code Here

   *             a temporary name cannot be allocated.
   */
  RefDirectoryUpdate newTemporaryUpdate() throws IOException {
    File tmp = File.createTempFile("renamed_", "_ref", refsDir);
    String name = Constants.R_REFS + tmp.getName();
    Ref ref = new ObjectIdRef.Unpeeled(NEW, name, null);
    return new RefDirectoryUpdate(this, ref);
  }
View Full Code Here

    }
  }

  private static LooseSymbolicRef newSymbolicRef(FileSnapshot snapshot,
      String name, String target) {
    Ref dst = new ObjectIdRef.Unpeeled(NEW, target, null);
    return new LooseSymbolicRef(snapshot, name, dst);
  }
View Full Code Here

  private RebaseResult initFilesAndRewind() throws RefNotFoundException,
      IOException, NoHeadException, JGitInternalException {
    // we need to store everything into files so that we can implement
    // --skip, --continue, and --abort

    Ref head = repo.getRef(Constants.HEAD);
    if (head == null || head.getObjectId() == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));

    String headName;
    if (head.isSymbolic())
      headName = head.getTarget().getName();
    else
      headName = "detached HEAD";
    ObjectId headId = head.getObjectId();
    if (headId == null)
      throw new RefNotFoundException(MessageFormat.format(
          JGitText.get().refNotResolved, Constants.HEAD));
    RevCommit headCommit = walk.lookupCommit(headId);
    RevCommit upstream = walk.lookupCommit(upstreamCommit.getId());
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.