Examples of RevObject


Examples of org.eclipse.jgit.revwalk.RevObject

   * @throws IOException
   */
  private void removeReferenced(Map<ObjectId, File> id2File,
      ObjectWalk w) throws MissingObjectException,
      IncorrectObjectTypeException, IOException {
    RevObject ro = w.next();
    while (ro != null) {
      if (id2File.remove(ro.getId()) != null)
        if (id2File.isEmpty())
          return;
      ro = w.next();
    }
    ro = w.nextObject();
    while (ro != null) {
      if (id2File.remove(ro.getId()) != null)
        if (id2File.isEmpty())
          return;
      ro = w.nextObject();
    }
  }
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

    final RawTextComparator cmp = comparatorFor(key.getWhitespace());
    final ObjectReader reader = repo.newObjectReader();
    try {
      final RevWalk rw = new RevWalk(reader);
      final RevCommit b = rw.parseCommit(key.getNewId());
      final RevObject a = aFor(key, repo, rw, b);

      if (a == null) {
        // TODO(sop) Remove this case.
        // This is a merge commit, compared to its ancestor.
        //
        final PatchListEntry[] entries = new PatchListEntry[1];
        entries[0] = newCommitMessage(cmp, repo, reader, null, b);
        return new PatchList(a, b, true, entries);
      }

      final boolean againstParent =
          b.getParentCount() > 0 && b.getParent(0) == a;

      RevCommit aCommit;
      RevTree aTree;
      if (a instanceof RevCommit) {
        aCommit = (RevCommit) a;
        aTree = aCommit.getTree();
      } else if (a instanceof RevTree) {
        aCommit = null;
        aTree = (RevTree) a;
      } else {
        throw new IOException("Unexpected type: " + a.getClass());
      }

      RevTree bTree = b.getTree();

      final TreeWalk walk = new TreeWalk(reader);
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

    final RefControl refControl = projectControl.controlForRef(name);
    final Repository repo = repoManager.openRepository(projectName);
    try {
      final ObjectId revid = parseStartingRevision(repo);
      final RevWalk rw = verifyConnected(repo, revid);
      RevObject object = rw.parseAny(revid);

      if (refname.startsWith(Constants.R_HEADS)) {
        // Ensure that what we start the branch from is a commit. If we
        // were given a tag, deference to the commit instead.
        //
        try {
          object = rw.parseCommit(object);
        } catch (IncorrectObjectTypeException notCommit) {
          throw new IllegalStateException(startingRevision + " not a commit");
        }
      }

      if (!refControl.canCreate(rw, object)) {
        throw new IllegalStateException("Cannot create " + refname);
      }

      try {
        final RefUpdate u = repo.updateRef(refname);
        u.setExpectedOldObjectId(ObjectId.zeroId());
        u.setNewObjectId(object.copy());
        u.setRefLogIdent(identifiedUser.newRefLogIdent());
        u.setRefLogMessage("created via web from " + startingRevision, false);
        final RefUpdate.Result result = u.update(rw);
        switch (result) {
          case FAST_FORWARD:
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

      }
    }
  }

  private void parseCreate(final ReceiveCommand cmd) {
    RevObject obj;
    try {
      obj = rp.getRevWalk().parseAny(cmd.getNewId());
    } catch (IOException err) {
      log.error("Invalid object " + cmd.getNewId().name() + " for "
          + cmd.getRefName() + " creation", err);
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

      reject(cmd, "can not update the reference as a fast forward");
    }
  }

  private boolean isCommit(final ReceiveCommand cmd) {
    RevObject obj;
    try {
      obj = rp.getRevWalk().parseAny(cmd.getNewId());
    } catch (IOException err) {
      log.error("Invalid object " + cmd.getNewId().name() + " for "
          + cmd.getRefName(), err);
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

      show(c);
    }
    if (walk instanceof ObjectWalk) {
      final ObjectWalk ow = (ObjectWalk) walk;
      for (;;) {
        final RevObject obj = ow.nextObject();
        if (obj == null)
          break;
        show(ow, obj);
      }
    }
View Full Code Here

Examples of org.eclipse.jgit.revwalk.RevObject

  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

Examples of org.eclipse.jgit.revwalk.RevObject

    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

Examples of org.eclipse.jgit.revwalk.RevObject

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

Examples of org.eclipse.jgit.revwalk.RevObject

  }

  private Object resolve(final RevWalk rw, final String revstr)
      throws IOException {
    char[] revChars = revstr.toCharArray();
    RevObject rev = null;
    String name = null;
    int done = 0;
    for (int i = 0; i < revChars.length; ++i) {
      switch (revChars[i]) {
      case '^':
        if (rev == null) {
          if (name == null)
            if (done == 0)
              name = new String(revChars, done, i);
            else {
              done = i + 1;
              break;
            }
          rev = parseSimple(rw, name);
          name = null;
          if (rev == null)
            return null;
        }
        if (i + 1 < revChars.length) {
          switch (revChars[i + 1]) {
          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            int j;
            rev = rw.parseCommit(rev);
            for (j = i + 1; j < revChars.length; ++j) {
              if (!Character.isDigit(revChars[j]))
                break;
            }
            String parentnum = new String(revChars, 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) rev;
              if (pnum > commit.getParentCount())
                rev = null;
              else
                rev = commit.getParent(pnum - 1);
            }
            i = j - 1;
            done = j;
            break;
          case '{':
            int k;
            String item = null;
            for (k = i + 2; k < revChars.length; ++k) {
              if (revChars[k] == '}') {
                item = new String(revChars, i + 2, k - i - 2);
                break;
              }
            }
            i = k;
            if (item != null)
              if (item.equals("tree")) {
                rev = rw.parseTree(rev);
              } else if (item.equals("commit")) {
                rev = rw.parseCommit(rev);
              } else if (item.equals("blob")) {
                rev = rw.peel(rev);
                if (!(rev instanceof RevBlob))
                  throw new IncorrectObjectTypeException(rev,
                      Constants.TYPE_BLOB);
              } else if (item.equals("")) {
                rev = rw.peel(rev);
              } else
                throw new RevisionSyntaxException(revstr);
            else
              throw new RevisionSyntaxException(revstr);
            done = k;
            break;
          default:
            rev = rw.parseAny(rev);
            if (rev instanceof RevCommit) {
              RevCommit commit = ((RevCommit) rev);
              if (commit.getParentCount() == 0)
                rev = null;
              else
                rev = commit.getParent(0);
            } else
              throw new IncorrectObjectTypeException(rev,
                  Constants.TYPE_COMMIT);
          }
        } else {
          rev = rw.peel(rev);
          if (rev instanceof RevCommit) {
            RevCommit commit = ((RevCommit) rev);
            if (commit.getParentCount() == 0)
              rev = null;
            else
              rev = commit.getParent(0);
          } else
            throw new IncorrectObjectTypeException(rev,
                Constants.TYPE_COMMIT);
        }
        done = i + 1;
        break;
      case '~':
        if (rev == null) {
          if (name == null)
            if (done == 0)
              name = new String(revChars, done, i);
            else {
              done = i + 1;
              break;
            }
          rev = parseSimple(rw, name);
          name = null;
          if (rev == null)
            return null;
        }
        rev = rw.peel(rev);
        if (!(rev instanceof RevCommit))
          throw new IncorrectObjectTypeException(rev,
              Constants.TYPE_COMMIT);
        int l;
        for (l = i + 1; l < revChars.length; ++l) {
          if (!Character.isDigit(revChars[l]))
            break;
        }
        int dist;
        if (l - i > 1) {
          String distnum = new String(revChars, i + 1, l - i - 1);
          try {
            dist = Integer.parseInt(distnum);
          } catch (NumberFormatException e) {
            throw new RevisionSyntaxException(
                JGitText.get().invalidAncestryLength, revstr);
          }
        } else
          dist = 1;
        while (dist > 0) {
          RevCommit commit = (RevCommit) rev;
          if (commit.getParentCount() == 0) {
            rev = null;
            break;
          }
          commit = commit.getParent(0);
          rw.parseHeaders(commit);
          rev = commit;
          --dist;
        }
        i = l - 1;
        done = l;
        break;
      case '@':
        if (rev != null)
          throw new RevisionSyntaxException(revstr);
        if (i + 1 < revChars.length && revChars[i + 1] != '{')
          continue;
        int m;
        String time = null;
        for (m = i + 2; m < revChars.length; ++m) {
          if (revChars[m] == '}') {
            time = new String(revChars, i + 2, m - i - 2);
            break;
          }
        }
        if (time != null) {
          if (time.equals("upstream")) {
            if (name == null)
              name = new String(revChars, done, i);
            if (name.equals(""))
              // Currently checked out branch, HEAD if
              // detached
              name = Constants.HEAD;
            if (!Repository.isValidRefName("x/" + name))
              throw new RevisionSyntaxException(revstr);
            Ref ref = getRef(name);
            name = null;
            if (ref == null)
              return null;
            if (ref.isSymbolic())
              ref = ref.getLeaf();
            name = ref.getName();

            RemoteConfig remoteConfig;
            try {
              remoteConfig = new RemoteConfig(getConfig(),
                  "origin");
            } catch (URISyntaxException e) {
              throw new RevisionSyntaxException(revstr);
            }
            String remoteBranchName = getConfig()
                .getString(
                    ConfigConstants.CONFIG_BRANCH_SECTION,
                Repository.shortenRefName(ref.getName()),
                    ConfigConstants.CONFIG_KEY_MERGE);
            List<RefSpec> fetchRefSpecs = remoteConfig
                .getFetchRefSpecs();
            for (RefSpec refSpec : fetchRefSpecs) {
              if (refSpec.matchSource(remoteBranchName)) {
                RefSpec expandFromSource = refSpec
                    .expandFromSource(remoteBranchName);
                name = expandFromSource.getDestination();
                break;
              }
            }
            if (name == null)
              throw new RevisionSyntaxException(revstr);
          } else if (time.matches("^-\\d+$")) {
            if (name != null)
              throw new RevisionSyntaxException(revstr);
            else {
              String previousCheckout = resolveReflogCheckout(-Integer
                  .parseInt(time));
              if (ObjectId.isId(previousCheckout))
                rev = parseSimple(rw, previousCheckout);
              else
                name = previousCheckout;
            }
          } else {
            if (name == null)
              name = new String(revChars, done, i);
            if (name.equals(""))
              name = Constants.HEAD;
            if (!Repository.isValidRefName("x/" + name))
              throw new RevisionSyntaxException(revstr);
            Ref ref = getRef(name);
            name = null;
            if (ref == null)
              return null;
            // @{n} means current branch, not HEAD@{1} unless
            // detached
            if (ref.isSymbolic())
              ref = ref.getLeaf();
            rev = resolveReflog(rw, ref, time);
          }
          i = m;
        } else
          throw new RevisionSyntaxException(revstr);
        break;
      case ':': {
        RevTree tree;
        if (rev == null) {
          if (name == null)
            name = new String(revChars, done, i);
          if (name.equals(""))
            name = Constants.HEAD;
          rev = parseSimple(rw, name);
          name = null;
        }
        if (rev == null)
          return null;
        tree = rw.parseTree(rev);
        if (i == revChars.length - 1)
          return tree.copy();

        TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(),
            new String(revChars, i + 1, revChars.length - i - 1),
            tree);
        return tw != null ? tw.getObjectId(0) : null;
      }
      default:
        if (rev != null)
          throw new RevisionSyntaxException(revstr);
      }
    }
    if (rev != null)
      return rev.copy();
    if (name != null)
      return name;
    if (done == revstr.length())
      return null;
    name = revstr.substring(done);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.