Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.Ref


  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

   * @return a {@link ReflogReader} for the supplied refname, or null if the
   *         named ref does not exist.
   * @throws IOException the ref could not be accessed.
   */
  public ReflogReader getReflogReader(String refName) throws IOException {
    Ref ref = getRef(refName);
    if (ref != null)
      return new ReflogReader(this, ref.getName());
    return null;
  }
View Full Code Here

        rru.setStatus(Status.REJECTED_NODELETE);
        continue;
      }

      final StringBuilder sb = new StringBuilder();
      final Ref advertisedRef = getRef(rru.getRemoteName());
      final ObjectId oldId = (advertisedRef == null ? ObjectId.zeroId()
          : advertisedRef.getObjectId());
      sb.append(oldId.name());
      sb.append(' ');
      sb.append(rru.getNewObjectId().name());
      sb.append(' ');
      sb.append(rru.getRemoteName());
View Full Code Here

      }
    }
  }

  private void deleteCommand(final RemoteRefUpdate u) {
    final Ref r = newRefs.remove(u.getRemoteName());
    if (r == null) {
      // Already gone.
      //
      u.setStatus(Status.OK);
      return;
    }

    if (r.getStorage().isPacked())
      packedRefUpdates.add(u);

    if (r.getStorage().isLoose()) {
      try {
        dest.deleteRef(u.getRemoteName());
        u.setStatus(Status.OK);
      } catch (IOException e) {
        u.setStatus(Status.REJECTED_OTHER_REASON);
View Full Code Here

          // should really not happen
          throw new JGitInternalException(e.getMessage(), e);
        }
      }

      Ref head = repo.getRef(Constants.HEAD);
      if (head == null)
        throw new NoHeadException(
            JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);

      // determine the current HEAD and the commit it is referring to
View Full Code Here

      if (s == null)
        throw new TransportException(getURI(), MessageFormat.format(JGitText.get().transportExceptionEmptyRef, rn));

      if (s.startsWith("ref: ")) {
        final String target = s.substring("ref: ".length());
        Ref r = avail.get(target);
        if (r == null)
          r = readRef(avail, target);
        if (r == null)
          r = new ObjectIdRef.Unpeeled(Ref.Storage.NEW, target, null);
        r = new SymbolicRef(rn, r);
        avail.put(r.getName(), r);
        return r;
      }

      if (ObjectId.isId(s)) {
        final Ref r = new ObjectIdRef.Unpeeled(loose(avail.get(rn)),
            rn, ObjectId.fromString(s));
        avail.put(r.getName(), r);
        return r;
      }

      throw new TransportException(getURI(), MessageFormat.format(JGitText.get().transportExceptionBadRef, rn, s));
    }
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.