Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevObject


        ObjectId.fromString("aabf2ffaec9b497f0950352b3e582d73035c2035"),
        ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"),
        ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"),
        ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") };
    final RevWalk parser = new RevWalk(db);
    final RevObject forcedOrderRevs[] = new RevObject[forcedOrder.length];
    for (int i = 0; i < forcedOrder.length; i++)
      forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);

    createVerifyOpenPack(Arrays.asList(forcedOrderRevs));
View Full Code Here


      if (cmd.getType() == ReceiveCommand.Type.DELETE)
        continue;
      ow.markStart(ow.parseAny(cmd.getNewId()));
    }
    for (final ObjectId have : advertisedHaves) {
      RevObject o = ow.parseAny(have);
      ow.markUninteresting(o);

      if (baseObjects != null && !baseObjects.isEmpty()) {
        o = ow.peel(o);
        if (o instanceof RevCommit)
          o = ((RevCommit) o).getTree();
        if (o instanceof RevTree)
          ow.markUninteresting(o);
      }
    }

    checking.beginTask(JGitText.get().countingObjects, ProgressMonitor.UNKNOWN);
    RevCommit c;
    while ((c = ow.next()) != null) {
      checking.update(1);
      if (providedObjects != null //
          && !c.has(RevFlag.UNINTERESTING) //
          && !providedObjects.contains(c))
        throw new MissingObjectException(c, Constants.TYPE_COMMIT);
    }

    RevObject o;
    while ((o = ow.nextObject()) != null) {
      checking.update(1);
      if (o.has(RevFlag.UNINTERESTING))
        continue;

      if (providedObjects != null) {
        if (providedObjects.contains(o))
          continue;
        else
          throw new MissingObjectException(o, o.getType());
      }

      if (o instanceof RevBlob && !db.hasObject(o))
        throw new MissingObjectException(o, Constants.TYPE_BLOB);
    }
    checking.endTask();

    if (baseObjects != null) {
      for (ObjectId id : baseObjects) {
        o = ow.parseAny(id);
        if (!o.has(RevFlag.UNINTERESTING))
          throw new MissingObjectException(o, o.getType());
      }
    }
  }
View Full Code Here

          continue;
        }

        // Is this possibly a non-fast-forward style update?
        //
        RevObject oldObj, newObj;
        try {
          oldObj = walk.parseAny(cmd.getOldId());
        } catch (IOException e) {
          cmd.setResult(Result.REJECTED_MISSING_OBJECT, cmd
              .getOldId().name());
View Full Code Here

  private int maxTimeWanted(final Collection<Ref> wants) {
    int maxTime = 0;
    for (final Ref r : wants) {
      try {
        final RevObject obj = walk.parseAny(r.getObjectId());
        if (obj instanceof RevCommit) {
          final int cTime = ((RevCommit) obj).getCommitTime();
          if (maxTime < cTime)
            maxTime = cTime;
        }
View Full Code Here

      // - both old and new ref must point to commits, AND
      // - both of them must be known for us, exist in repository, AND
      // - old commit must be ancestor of new commit
      boolean fastForward = true;
      try {
        RevObject oldRev = walker.parseAny(advertisedOld);
        final RevObject newRev = walker.parseAny(rru.getNewObjectId());
        if (!(oldRev instanceof RevCommit)
            || !(newRev instanceof RevCommit)
            || !walker.isMergedInto((RevCommit) oldRev,
                (RevCommit) newRev))
          fastForward = false;
View Full Code Here

  private ObjectId objectId;

  @Override
  protected void run() throws Exception {
    ObjectReader reader = db.newObjectReader();
    RevObject obj = new RevWalk(reader).parseAny(objectId);
    byte[] delta = getDelta(reader, obj);

    // We're crossing our fingers that this will be a delta. Double
    // check the size field in the header, it should match.
    //
    long size = reader.getObjectSize(obj, obj.getType());
    try {
      if (BinaryDelta.getResultSize(delta) != size)
        throw die("Object " + obj.name() + " is not a delta");
    } catch (ArrayIndexOutOfBoundsException bad) {
      throw die("Object " + obj.name() + " is not a delta");
    }

    outw.println(BinaryDelta.format(delta));
  }
View Full Code Here

  }

  private RevCommit parseCommit() {
    if (this.commit == null) {
      RevWalk rw = new RevWalk(db);
      RevObject any;
      try {
        any = rw.parseAny(this.ref.getObjectId());
        if (any instanceof RevTag) {
          this.tag = (RevTag) any;
          this.commit = (RevCommit) rw.peel(any);
View Full Code Here

    Set<RevObject> notAdvertisedWants = null;
    int haveCnt = 0;
    AsyncRevObjectQueue q = walk.parseAny(toParse, needMissing);
    try {
      for (;;) {
        RevObject obj;
        try {
          obj = q.next();
        } catch (MissingObjectException notFound) {
          ObjectId id = notFound.getObjectId();
          if (wantIds.contains(id)) {
            String msg = MessageFormat.format(
                JGitText.get().wantNotValid, id.name());
            throw new PackProtocolException(msg, notFound);
          }
          continue;
        }
        if (obj == null)
          break;

        // If the object is still found in wantIds, the want
        // list wasn't parsed earlier, and was done in this batch.
        //
        if (wantIds.remove(obj)) {
          if (!advertised.contains(obj) && requestPolicy != RequestPolicy.ANY) {
            if (notAdvertisedWants == null)
              notAdvertisedWants = new HashSet<RevObject>();
            notAdvertisedWants.add(obj);
          }

          if (!obj.has(WANT)) {
            obj.add(WANT);
            wantAll.add(obj);
          }

          if (!(obj instanceof RevCommit))
            obj.add(SATISFIED);

          if (obj instanceof RevTag) {
            RevObject target = walk.peel(obj);
            if (target instanceof RevCommit) {
              if (!target.has(WANT)) {
                target.add(WANT);
                wantAll.add(target);
              }
            }
          }
View Full Code Here

    }
  }

  private ObjectId resolve(final RevWalk rw, final String revstr) throws IOException {
    char[] rev = revstr.toCharArray();
    RevObject ref = null;
    for (int i = 0; i < rev.length; ++i) {
      switch (rev[i]) {
      case '^':
        if (ref == null) {
          ref = parseSimple(rw, new String(rev, 0, i));
          if (ref == null)
            return null;
        }
        if (i + 1 < rev.length) {
          switch (rev[i + 1]) {
          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            int j;
            ref = rw.parseCommit(ref);
            for (j = i + 1; j < rev.length; ++j) {
              if (!Character.isDigit(rev[j]))
                break;
            }
            String parentnum = new String(rev, i + 1, j - i - 1);
            int pnum;
            try {
              pnum = Integer.parseInt(parentnum);
            } catch (NumberFormatException e) {
              throw new RevisionSyntaxException(
                  JGitText.get().invalidCommitParentNumber,
                  revstr);
            }
            if (pnum != 0) {
              RevCommit commit = (RevCommit) ref;
              if (pnum > commit.getParentCount())
                ref = null;
              else
                ref = commit.getParent(pnum - 1);
            }
            i = j - 1;
            break;
          case '{':
            int k;
            String item = null;
            for (k = i + 2; k < rev.length; ++k) {
              if (rev[k] == '}') {
                item = new String(rev, i + 2, k - i - 2);
                break;
              }
            }
            i = k;
            if (item != null)
              if (item.equals("tree")) {
                ref = rw.parseTree(ref);
              } else if (item.equals("commit")) {
                ref = rw.parseCommit(ref);
              } else if (item.equals("blob")) {
                ref = rw.peel(ref);
                if (!(ref instanceof RevBlob))
                  throw new IncorrectObjectTypeException(ref,
                      Constants.TYPE_BLOB);
              } else if (item.equals("")) {
                ref = rw.peel(ref);
              } else
                throw new RevisionSyntaxException(revstr);
            else
              throw new RevisionSyntaxException(revstr);
            break;
          default:
            ref = rw.parseAny(ref);
            if (ref instanceof RevCommit) {
              RevCommit commit = ((RevCommit) ref);
              if (commit.getParentCount() == 0)
                ref = null;
              else
                ref = commit.getParent(0);
            } else
              throw new IncorrectObjectTypeException(ref,
                  Constants.TYPE_COMMIT);

          }
        } else {
          ref = rw.peel(ref);
          if (ref instanceof RevCommit) {
            RevCommit commit = ((RevCommit) ref);
            if (commit.getParentCount() == 0)
              ref = null;
            else
              ref = commit.getParent(0);
          } else
            throw new IncorrectObjectTypeException(ref,
                Constants.TYPE_COMMIT);
        }
        break;
      case '~':
        if (ref == null) {
          ref = parseSimple(rw, new String(rev, 0, i));
          if (ref == null)
            return null;
        }
        ref = rw.peel(ref);
        if (!(ref instanceof RevCommit))
          throw new IncorrectObjectTypeException(ref,
              Constants.TYPE_COMMIT);
        int l;
        for (l = i + 1; l < rev.length; ++l) {
          if (!Character.isDigit(rev[l]))
            break;
        }
        String distnum = new String(rev, i + 1, l - i - 1);
        int dist;
        try {
          dist = Integer.parseInt(distnum);
        } catch (NumberFormatException e) {
          throw new RevisionSyntaxException(
              JGitText.get().invalidAncestryLength, revstr);
        }
        while (dist > 0) {
          RevCommit commit = (RevCommit) ref;
          if (commit.getParentCount() == 0) {
            ref = null;
            break;
          }
          commit = commit.getParent(0);
          rw.parseHeaders(commit);
          ref = commit;
          --dist;
        }
        i = l - 1;
        break;
      case '@':
        int m;
        String time = null;
        for (m = i + 2; m < rev.length; ++m) {
          if (rev[m] == '}') {
            time = new String(rev, i + 2, m - i - 2);
            break;
          }
        }
        if (time != null)
          throw new RevisionSyntaxException(
              JGitText.get().reflogsNotYetSupportedByRevisionParser,
              revstr);
        i = m - 1;
        break;
      case ':': {
        RevTree tree;
        if (ref == null) {
          // We might not yet have parsed the left hand side.
          ObjectId id;
          try {
            if (i == 0)
              id = resolve(rw, Constants.HEAD);
            else
              id = resolve(rw, new String(rev, 0, i));
          } catch (RevisionSyntaxException badSyntax) {
            throw new RevisionSyntaxException(revstr);
          }
          if (id == null)
            return null;
          tree = rw.parseTree(id);
        } else {
          tree = rw.parseTree(ref);
        }

        if (i == rev.length - i)
          return tree.copy();

        TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(),
            new String(rev, i + 1, rev.length - i - 1), tree);
        return tw != null ? tw.getObjectId(0) : null;
      }

      default:
        if (ref != null)
          throw new RevisionSyntaxException(revstr);
      }
    }
    return ref != null ? ref.copy() : resolveSimple(revstr);
  }
View Full Code Here

          // If the object was already requested, skip it.
          if (wantAll.isEmpty()) {
            if (wantIds.contains(objectId))
              continue;
          } else {
            RevObject obj = rw.lookupOrNull(objectId);
            if (obj != null && obj.has(WANT))
              continue;
          }

          if (!ref.isPeeled())
            ref = db.peel(ref);
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.revwalk.RevObject

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.