Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevObject


  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


      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 (checkReferencedIsReachable && !baseObjects.isEmpty()) {
        o = ow.peel(o);
        if (o instanceof RevCommit)
          o = ((RevCommit) o).getTree();
        if (o instanceof RevTree)
          ow.markUninteresting(o);
      }
    }

    RevCommit c;
    while ((c = ow.next()) != null) {
      if (checkReferencedIsReachable //
          && !c.has(RevFlag.UNINTERESTING) //
          && !providedObjects.contains(c))
        throw new MissingObjectException(c, Constants.TYPE_COMMIT);
    }

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

      if (checkReferencedIsReachable) {
        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);
    }

    if (checkReferencedIsReachable) {
      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

    AsyncRevObjectQueue q = walker.parseAny(all, true);
    try {
      for (;;) {
        try {
          RevObject o = q.next();
          if (o == null)
            break;

          if (tipToPack.containsKey(o))
            o.add(inCachedPack);

          if (have.contains(o)) {
            haveObjs.add(o);
          } else if (want.contains(o)) {
            o.add(include);
            wantObjs.add(o);
            if (o instanceof RevTag)
              wantTags.add((RevTag) o);
          }
        } catch (MissingObjectException e) {
          if (ignoreMissingUninteresting
              && have.contains(e.getObjectId()))
            continue;
          throw e;
        }
      }
    } finally {
      q.release();
    }

    if (!wantTags.isEmpty()) {
      all = new ArrayList<ObjectId>(wantTags.size());
      for (RevTag tag : wantTags)
        all.add(tag.getObject());
      q = walker.parseAny(all, true);
      try {
        while (q.next() != null) {
          // Just need to pop the queue item to parse the object.
        }
      } finally {
        q.release();
      }
    }

    for (RevObject obj : wantObjs)
      walker.markStart(obj);
    for (RevObject obj : haveObjs)
      walker.markUninteresting(obj);

    final int maxBases = config.getDeltaSearchWindowSize();
    Set<RevTree> baseTrees = new HashSet<RevTree>();
    BlockList<RevCommit> commits = new BlockList<RevCommit>();
    RevCommit c;
    while ((c = walker.next()) != null) {
      if (c.has(inCachedPack)) {
        CachedPack pack = tipToPack.get(c);
        if (includesAllTips(pack, include, walker)) {
          useCachedPack(walker, keepOnRestart, //
              wantObjs, haveObjs, pack);
          commits = new BlockList<RevCommit>();

          countingMonitor.endTask();
          countingMonitor.beginTask(JGitText.get().countingObjects,
              ProgressMonitor.UNKNOWN);
          continue;
        }
      }

      if (c.has(RevFlag.UNINTERESTING)) {
        if (baseTrees.size() <= maxBases)
          baseTrees.add(c.getTree());
        continue;
      }

      commits.add(c);
      countingMonitor.update(1);
    }

    int commitCnt = 0;
    boolean putTagTargets = false;
    for (RevCommit cmit : commits) {
      if (!cmit.has(added)) {
        cmit.add(added);
        addObject(cmit, 0);
        commitCnt++;
      }

      for (int i = 0; i < cmit.getParentCount(); i++) {
        RevCommit p = cmit.getParent(i);
        if (!p.has(added) && !p.has(RevFlag.UNINTERESTING)) {
          p.add(added);
          addObject(p, 0);
          commitCnt++;
        }
      }

      if (!putTagTargets && 4096 < commitCnt) {
        for (ObjectId id : tagTargets) {
          RevObject obj = walker.lookupOrNull(id);
          if (obj instanceof RevCommit
              && obj.has(include)
              && !obj.has(RevFlag.UNINTERESTING)
              && !obj.has(added)) {
            obj.add(added);
            addObject(obj, 0);
          }
        }
        putTagTargets = true;
      }
    }
    commits = null;

    BaseSearch bases = new BaseSearch(countingMonitor, baseTrees, //
        objectsMap, edgeObjects, reader);
    RevObject o;
    while ((o = walker.nextObject()) != null) {
      if (o.has(RevFlag.UNINTERESTING))
        continue;

      int pathHash = walker.getPathHashCode();
      byte[] pathBuf = walker.getPathBuffer();
      int pathLen = walker.getPathLength();

      bases.addBase(o.getType(), pathBuf, pathLen, pathHash);
      addObject(o, pathHash);
      countingMonitor.update(1);
    }

    for (CachedPack pack : cachedPacks)
View Full Code Here

    }
  }

  private Result updateImpl(final RevWalk walk, final Store store)
      throws IOException {
    RevObject newObj;
    RevObject oldObj;

    if (getRefDatabase().isNameConflicting(getName()))
      return Result.LOCK_FAILURE;
    try {
      if (!tryLock(true))
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

  private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException,
      IOException {
    RevWalk rw = new RevWalk(getRepository());
    try {
      RevObject obj = rw.parseAny(leaf.getObjectId());
      if (obj instanceof RevTag) {
        return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf
            .getName(), leaf.getObjectId(), rw.peel(obj).copy());
      } else {
        return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf
View Full Code Here

  }

  class PlotRefComparator implements Comparator<Ref> {
    public int compare(Ref o1, Ref o2) {
      try {
        RevObject obj1 = parseAny(o1.getObjectId());
        RevObject obj2 = parseAny(o2.getObjectId());
        long t1 = timeof(obj1);
        long t2 = timeof(obj2);
        if (t1 > t2)
          return -1;
        if (t1 < t2)
View Full Code Here

    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());
            pckOut.writeString("ERR " + msg);
            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)) {
            String msg = MessageFormat.format(
                JGitText.get().wantNotValid, obj.name());
            pckOut.writeString("ERR " + msg);
            throw new PackProtocolException(msg);
          }

          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

          // 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.