private DhtRef doPeel(final Ref leaf) throws MissingObjectException, IOException {
    RevWalk rw = new RevWalk(getRepository());
    try {
      DhtReader ctx = (DhtReader) rw.getObjectReader();
      RevObject obj = rw.parseAny(leaf.getObjectId());
      RefData.Builder d = RefData.newBuilder(((DhtRef) leaf).getRefData());

      ChunkKey oKey = ctx.findChunk(leaf.getObjectId());
      if (oKey != null) d.getTargetBuilder().setChunkKey(oKey.asString());
      else d.getTargetBuilder().clearChunkKey();

      if (obj instanceof RevTag) {
        ObjectId pId = rw.peel(obj);
        d.getPeeledBuilder().setObjectName(pId.name());

        ChunkKey pKey = ctx.findChunk(pId);
        if (pKey != null) d.getPeeledBuilder().setChunkKey(pKey.asString());
        else d.getPeeledBuilder().clearChunkKey();
      } else {
        d.clearPeeled();
      }

      d.setIsPeeled(true);
      d.setSequence(d.getSequence() + 1);
      return new DhtObjectIdRef(leaf.getName(), d.build());
    } finally {
      rw.release();
    }
  }
Example #2
0
 private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException, IOException {
   try (RevWalk rw = new RevWalk(getRepository())) {
     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.getName(), leaf.getObjectId());
     }
   }
 }
Example #3
0
  /**
   * Sets default values for not explicitly specified options. Then validates that all required data
   * has been provided.
   *
   * @param state the state of the repository we are working on
   * @param rw the RevWalk to use
   * @throws NoMessageException if the commit message has not been specified
   */
  private void processOptions(RepositoryState state, RevWalk rw) throws NoMessageException {
    if (committer == null) committer = new PersonIdent(repo);
    if (author == null && !amend) author = committer;
    if (allowEmpty == null)
      // JGit allows empty commits by default. Only when pathes are
      // specified the commit should not be empty. This behaviour differs
      // from native git but can only be adapted in the next release.
      // TODO(ch) align the defaults with native git
      allowEmpty = (only.isEmpty()) ? Boolean.TRUE : Boolean.FALSE;

    // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
    if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) {
      try {
        parents = repo.readMergeHeads();
        if (parents != null)
          for (int i = 0; i < parents.size(); i++) {
            RevObject ro = rw.parseAny(parents.get(i));
            if (ro instanceof RevTag) parents.set(i, rw.peel(ro));
          }
      } catch (IOException e) {
        throw new JGitInternalException(
            MessageFormat.format(
                JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e),
            e);
      }
      if (message == null) {
        try {
          message = repo.readMergeCommitMsg();
        } catch (IOException e) {
          throw new JGitInternalException(
              MessageFormat.format(
                  JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e),
              e);
        }
      }
    } else if (state == RepositoryState.SAFE && message == null) {
      try {
        message = repo.readSquashCommitMsg();
        if (message != null) repo.writeSquashCommitMsg(null /* delete */);
      } catch (IOException e) {
        throw new JGitInternalException(
            MessageFormat.format(
                JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e),
            e);
      }
    }
    if (message == null)
      // as long as we don't support -C option we have to have
      // an explicit message
      throw new NoMessageException(JGitText.get().commitMessageNotSpecified);
  }
Example #4
0
  /**
   * Sets default values for not explicitly specified options. Then validates that all required data
   * has been provided.
   *
   * @param state the state of the repository we are working on
   * @param rw the RevWalk to use
   * @throws NoMessageException if the commit message has not been specified
   */
  private void processOptions(RepositoryState state, RevWalk rw) throws NoMessageException {
    if (committer == null) committer = new PersonIdent(repo);
    if (author == null && !amend) author = committer;

    // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
    if (state == RepositoryState.MERGING_RESOLVED || isMergeDuringRebase(state)) {
      try {
        parents = repo.readMergeHeads();
        if (parents != null)
          for (int i = 0; i < parents.size(); i++) {
            RevObject ro = rw.parseAny(parents.get(i));
            if (ro instanceof RevTag) parents.set(i, rw.peel(ro));
          }
      } catch (IOException e) {
        throw new JGitInternalException(
            MessageFormat.format(
                JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_HEAD, e),
            e);
      }
      if (message == null) {
        try {
          message = repo.readMergeCommitMsg();
        } catch (IOException e) {
          throw new JGitInternalException(
              MessageFormat.format(
                  JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e),
              e);
        }
      }
    } else if (state == RepositoryState.SAFE && message == null) {
      try {
        message = repo.readSquashCommitMsg();
        if (message != null) repo.writeSquashCommitMsg(null /* delete */);
      } catch (IOException e) {
        throw new JGitInternalException(
            MessageFormat.format(
                JGitText.get().exceptionOccurredDuringReadingOfGIT_DIR, Constants.MERGE_MSG, e),
            e);
      }
    }
    if (message == null)
      // as long as we don't support -C option we have to have
      // an explicit message
      throw new NoMessageException(JGitText.get().commitMessageNotSpecified);
  }
Example #5
0
  @Override
  protected Result doUpdate(Result desiredResult) throws IOException {
    ObjectIdRef newRef;
    RevObject obj = rw.parseAny(getNewObjectId());
    if (obj instanceof RevTag) {
      newRef =
          new ObjectIdRef.PeeledTag(
              Storage.PACKED, dstRef.getName(), getNewObjectId(), rw.peel(obj).copy());
    } else {
      newRef = new ObjectIdRef.PeeledNonTag(Storage.PACKED, dstRef.getName(), getNewObjectId());
    }

    if (getRefDatabase().compareAndPut(dstRef, newRef)) {
      getRefDatabase().stored(newRef);
      return desiredResult;
    }
    return Result.LOCK_FAILURE;
  }