Package org.eclipse.jgit.revwalk

Examples of org.eclipse.jgit.revwalk.RevCommit


    walk.resetRetain(SAVE);
    walk.markStart((RevCommit) want);
    if (oldestTime != 0)
      walk.setRevFilter(CommitTimeRevFilter.after(oldestTime * 1000L));
    for (;;) {
      final RevCommit c = walk.next();
      if (c == null)
        break;
      if (c.has(PEER_HAS)) {
        addCommonBase(c);
        want.add(SATISFIED);
        return true;
      }
    }
View Full Code Here


      remaining = c.sourceText.size();
      push(c);
      return this;
    }

    RevCommit commit = revPool.parseCommit(id);
    if (!find(commit, resultPath))
      return this;

    Candidate c = new Candidate(commit, resultPath);
    c.sourceBlob = idBuf.toObjectId();
View Full Code Here

      }
    }
  }

  private boolean processOne(Candidate n) throws IOException {
    RevCommit parent = n.getParent(0);
    if (parent == null)
      return split(n.getNextCandidate(0), n);
    if (parent.has(SEEN))
      return false;
    revPool.parseHeaders(parent);

    if (find(parent, n.sourcePath)) {
      if (idBuf.equals(n.sourceBlob)) {
View Full Code Here

  private boolean processMerge(Candidate n) throws IOException {
    int pCnt = n.getParentCount();

    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;
      revPool.parseHeaders(parent);
    }

    // If any single parent exactly matches the merge, follow only
    // that one parent through history.
    ObjectId[] ids = null;
    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;
      if (!find(parent, n.sourcePath))
        continue;
      if (!(n instanceof ReverseCandidate) && idBuf.equals(n.sourceBlob)) {
        n.sourceCommit = parent;
        push(n);
        return false;
      }
      if (ids == null)
        ids = new ObjectId[pCnt];
      ids[pIdx] = idBuf.toObjectId();
    }

    // If rename detection is enabled, search for any relevant names.
    DiffEntry[] renames = null;
    if (renameDetector != null) {
      renames = new DiffEntry[pCnt];
      for (int pIdx = 0; pIdx < pCnt; pIdx++) {
        RevCommit parent = n.getParent(pIdx);
        if (parent.has(SEEN))
          continue;
        if (ids != null && ids[pIdx] != null)
          continue;

        DiffEntry r = findRename(parent, n.sourceCommit, n.sourcePath);
        if (r == null)
          continue;

        if (n instanceof ReverseCandidate) {
          if (ids == null)
            ids = new ObjectId[pCnt];
          ids[pCnt] = r.getOldId().toObjectId();
        } else if (0 == r.getOldId().prefixCompare(n.sourceBlob)) {
          // A 100% rename without any content change can also
          // skip directly to the parent. Note this bypasses an
          // earlier parent that had the path (above) but did not
          // have an exact content match. For performance reasons
          // we choose to follow the one parent over trying to do
          // possibly both parents.
          n.sourceCommit = parent;
          n.sourcePath = PathFilter.create(r.getOldPath());
          push(n);
          return false;
        }

        renames[pIdx] = r;
      }
    }

    // Construct the candidate for each parent.
    Candidate[] parents = new Candidate[pCnt];
    for (int pIdx = 0; pIdx < pCnt; pIdx++) {
      RevCommit parent = n.getParent(pIdx);
      if (parent.has(SEEN))
        continue;

      Candidate p;
      if (renames != null && renames[pIdx] != null) {
        p = n.create(parent,
View Full Code Here

    return currentSource.getAuthor();
  }

  /** @return current committer being blamed. */
  public PersonIdent getSourceCommitter() {
    RevCommit c = getSourceCommit();
    return c != null ? c.getCommitterIdent() : null;
  }
View Full Code Here

    r.append(getResultPath());
    return r.toString();
  }

  private void loadFrom(BlameGenerator gen) {
    RevCommit srcCommit = gen.getSourceCommit();
    PersonIdent srcAuthor = gen.getSourceAuthor();
    PersonIdent srcCommitter = gen.getSourceCommitter();
    String srcPath = gen.getSourcePath();
    int srcLine = gen.getSourceStart();
    int resLine = gen.getResultStart();
View Full Code Here

   {
      // Does the same as the original git-cherryPick
      // except commiting after running merger
      Repository repo = git.getRepository();

      RevCommit newHead = null;
      List<Ref> cherryPickedRefs = new LinkedList<Ref>();

      RevWalk revWalk = new RevWalk(repo);
      try
      {
         // get the head commit
         Ref headRef = repo.getRef(Constants.HEAD);
         if (headRef == null)
            throw new NoHeadException(
                     JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
         RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());

         newHead = headCommit;

         // get the commit to be cherry-picked
         // handle annotated tags
         ObjectId srcObjectId = src.getPeeledObjectId();
         if (srcObjectId == null)
            srcObjectId = src.getObjectId();
         RevCommit srcCommit = revWalk.parseCommit(srcObjectId);

         // get the parent of the commit to cherry-pick
         if (srcCommit.getParentCount() == 0)
            throw new CantMergeCommitException("Commit with zero parents cannot be merged");

         if (srcCommit.getParentCount() > 1)
            throw new MultipleParentsNotAllowedException(
                     MessageFormat.format(
                              JGitText.get().canOnlyCherryPickCommitsWithOneParent,
                              srcCommit.name(),
                              Integer.valueOf(srcCommit.getParentCount())));

         RevCommit srcParent = srcCommit.getParent(0);
         revWalk.parseHeaders(srcParent);

         ResolveMerger merger = (ResolveMerger) MergeStrategy.RESOLVE
                  .newMerger(repo);
         merger.setWorkingTreeIterator(new FileTreeIterator(repo));
         merger.setBase(srcParent.getTree());
         if (merger.merge(headCommit, srcCommit))
         {
            DirCacheCheckout dco = new DirCacheCheckout(repo,
                     headCommit.getTree(), repo.lockDirCache(),
                     merger.getResultTreeId());
View Full Code Here

            }

            List<ScmFile> checkedInFiles = Collections.emptyList();
            if ( doCommit )
            {
                RevCommit commitRev = git.commit().setMessage( message ).call();
                getLogger().info( "commit done: " + commitRev.getShortMessage() );
                checkedInFiles = JGitUtils.getFilesInCommit( git.getRepository(), commitRev );
                if ( getLogger().isDebugEnabled() )
                {
                    for ( ScmFile scmFile : checkedInFiles )
                    {
View Full Code Here

        throw new WrongRepositoryStateException(
            JGitText.get().commitAmendOnInitialNotPossible);

      if (headId != null)
        if (amend) {
          RevCommit previousCommit = new RevWalk(repo)
              .parseCommit(headId);
          RevCommit[] p = previousCommit.getParents();
          for (int i = 0; i < p.length; i++)
            parents.add(0, p[i].getId());
          if (author == null)
            author = previousCommit.getAuthorIdent();
        } else {
          parents.add(0, headId);
        }

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        if (!only.isEmpty())
          index = createTemporaryIndex(headId, index);

        ObjectInserter odi = repo.newObjectInserter();
        try {
          // Write the index as tree to the object database. This may
          // fail for example when the index contains unmerged paths
          // (unresolved conflicts)
          ObjectId indexTreeId = index.writeTree(odi);

          if (insertChangeId)
            insertChangeId(indexTreeId);

          // Create a Commit object, populate it and write it
          CommitBuilder commit = new CommitBuilder();
          commit.setCommitter(committer);
          commit.setAuthor(author);
          commit.setMessage(message);

          commit.setParentIds(parents);
          commit.setTreeId(indexTreeId);
          ObjectId commitId = odi.insert(commit);
          odi.flush();

          RevWalk revWalk = new RevWalk(repo);
          try {
            RevCommit revCommit = revWalk.parseCommit(commitId);
            RefUpdate ru = repo.updateRef(Constants.HEAD);
            ru.setNewObjectId(commitId);
            if (reflogComment != null) {
              ru.setRefLogMessage(reflogComment, false);
            } else {
              String prefix = amend ? "commit (amend): "
                  : "commit: ";
              ru.setRefLogMessage(
                  prefix + revCommit.getShortMessage(), false);
            }
            if (headId != null)
              ru.setExpectedOldObjectId(headId);
            else
              ru.setExpectedOldObjectId(ObjectId.zeroId());
View Full Code Here

   * @throws NoHeadException
   * @throws RefNotFoundException
   */
  public RebaseResult call() throws GitAPIException, NoHeadException,
      RefNotFoundException, WrongRepositoryStateException {
    RevCommit newHead = null;
    boolean lastStepWasForward = false;
    checkCallable();
    checkParameters();
    try {
      switch (operation) {
      case ABORT:
        try {
          return abort(RebaseResult.ABORTED_RESULT);
        } catch (IOException ioe) {
          throw new JGitInternalException(ioe.getMessage(), ioe);
        }
      case SKIP:
        // fall through
      case CONTINUE:
        String upstreamCommitId = readFile(rebaseDir, ONTO);
        try {
          upstreamCommitName = readFile(rebaseDir, ONTO_NAME);
        } catch (FileNotFoundException e) {
          // Fall back to commit ID if file doesn't exist (e.g. rebase
          // was started by C Git)
          upstreamCommitName = upstreamCommitId;
        }
        this.upstreamCommit = walk.parseCommit(repo
            .resolve(upstreamCommitId));
        break;
      case BEGIN:
        RebaseResult res = initFilesAndRewind();
        if (res != null)
          return res;
      }

      if (monitor.isCancelled())
        return abort(RebaseResult.ABORTED_RESULT);

      if (operation == Operation.CONTINUE) {
        newHead = continueRebase();

        File amendFile = new File(rebaseDir, AMEND);
        boolean amendExists = amendFile.exists();
        if (amendExists) {
          FileUtils.delete(amendFile);
        }
        if (newHead == null && !amendExists) {
          // continueRebase() returns null only if no commit was
          // neccessary. This means that no changes where left over
          // after resolving all conflicts. In this case, cgit stops
          // and displays a nice message to the user, telling him to
          // either do changes or skip the commit instead of continue.
          return RebaseResult.NOTHING_TO_COMMIT_RESULT;
        }
      }

      if (operation == Operation.SKIP)
        newHead = checkoutCurrentHead();

      ObjectReader or = repo.newObjectReader();

      List<Step> steps = loadSteps();
      if (isInteractive()) {
        interactiveHandler.prepareSteps(steps);
        BufferedWriter fw = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(new File(
                rebaseDir, GIT_REBASE_TODO)),
                Constants.CHARACTER_ENCODING));
        fw.newLine();
        try {
          StringBuilder sb = new StringBuilder();
          for (Step step : steps) {
            sb.setLength(0);
            sb.append(step.action.token);
            sb.append(" ");
            sb.append(step.commit.name());
            sb.append(" ");
            sb.append(RawParseUtils.decode(step.shortMessage)
                .trim());
            fw.write(sb.toString());
            fw.newLine();
          }
        } finally {
          fw.close();
        }
      }
      for (Step step : steps) {
        popSteps(1);
        Collection<ObjectId> ids = or.resolve(step.commit);
        if (ids.size() != 1)
          throw new JGitInternalException(
              "Could not resolve uniquely the abbreviated object ID");
        RevCommit commitToPick = walk
            .parseCommit(ids.iterator().next());
        if (monitor.isCancelled())
          return new RebaseResult(commitToPick);
        try {
          monitor.beginTask(MessageFormat.format(
              JGitText.get().applyingCommit,
              commitToPick.getShortMessage()),
              ProgressMonitor.UNKNOWN);
          // if the first parent of commitToPick is the current HEAD,
          // we do a fast-forward instead of cherry-pick to avoid
          // unnecessary object rewriting
          newHead = tryFastForward(commitToPick);
          lastStepWasForward = newHead != null;
          if (!lastStepWasForward) {
            // TODO if the content of this commit is already merged
            // here we should skip this step in order to avoid
            // confusing pseudo-changed
            String ourCommitName = getOurCommitName();
            CherryPickResult cherryPickResult = new Git(repo)
                .cherryPick().include(commitToPick)
                .setOurCommitName(ourCommitName).call();
            switch (cherryPickResult.getStatus()) {
            case FAILED:
              if (operation == Operation.BEGIN)
                return abort(new RebaseResult(
                    cherryPickResult.getFailingPaths()));
              else
                return stop(commitToPick);
            case CONFLICTING:
              return stop(commitToPick);
            case OK:
              newHead = cherryPickResult.getNewHead();
            }
          }
          switch (step.action) {
          case PICK:
            continue; // continue rebase process on pick command
          case REWORD:
            String oldMessage = commitToPick.getFullMessage();
            String newMessage = interactiveHandler
                .modifyCommitMessage(oldMessage);
            newHead = new Git(repo).commit().setMessage(newMessage)
                .setAmend(true).call();
            continue;
          case EDIT:
            createFile(rebaseDir, AMEND, commitToPick.name());
            return stop(commitToPick);
          }
        } finally {
          monitor.endTask();
        }
View Full Code Here

TOP

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

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.