Example #1
0
  // ----------------------------------------------------------
  private NSArray<GitRef> filteredRefs(RefFilter filter) {
    NSMutableArray<GitRef> result = new NSMutableArray<GitRef>();

    Map<String, Ref> refs = repository.getAllRefs();

    for (Ref ref : RefComparator.sort(refs.values())) {
      if (filter == null || filter.accepts(ref)) {
        result.addObject(new GitRef(this, ref));
      }
    }

    return result;
  }
Example #2
0
  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;
      }

      int sp = p.indexOf(' ');
      if (sp < 0) {
        throw new IOException(
            MessageFormat.format(
                JGitText.get().packedRefsCorruptionDetected, packedRefsFile.getAbsolutePath()));
      }
      ObjectId id = ObjectId.fromString(p.substring(0, sp));
      String name = copy(p, sp + 1, p.length());
      ObjectIdRef cur;
      if (peeled) cur = new ObjectIdRef.PeeledNonTag(PACKED, name, id);
      else cur = new ObjectIdRef.Unpeeled(PACKED, name, id);
      if (last != null && RefComparator.compareTo(last, cur) > 0) needSort = true;
      all.add(cur);
      last = cur;
    }

    if (needSort) all.sort();
    return all.toRefList();
  }
Example #3
0
    private void scanOne(String name) {
      LooseRef cur;

      if (curIdx < curLoose.size()) {
        do {
          cur = curLoose.get(curIdx);
          int cmp = RefComparator.compareTo(cur, name);
          if (cmp < 0) {
            // Reference is not loose anymore, its been deleted.
            // Skip the name in the new result list.
            if (newLoose == null) newLoose = curLoose.copy(curIdx);
            curIdx++;
            cur = null;
            continue;
          }

          if (cmp > 0) // Newly discovered loose reference.
          cur = null;
          break;
        } while (curIdx < curLoose.size());
      } else cur = null; // Newly discovered loose reference.

      LooseRef n;
      try {
        n = scanRef(cur, name);
      } catch (IOException notValid) {
        n = null;
      }

      if (n != null) {
        if (cur != n && newLoose == null) newLoose = curLoose.copy(curIdx);
        if (newLoose != null) newLoose.add(n);
        if (n.isSymbolic()) symbolic.add(n);
      } else if (cur != null) {
        // Tragically, this file is no longer a loose reference.
        // Kill our cached entry of it.
        if (newLoose == null) newLoose = curLoose.copy(curIdx);
      }

      if (cur != null) curIdx++;
    }