Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectInserter$Filter


      return rw.parseTree(ref.getObjectId());
    }

    ObjectId treeId;
    ResolveMerger m = (ResolveMerger) MergeStrategy.RESOLVE.newMerger(repo, true);
    final ObjectInserter ins = repo.newObjectInserter();
    try {
      DirCache dc = DirCache.newInCore();
      m.setDirCache(dc);
      m.setObjectInserter(new ObjectInserter.Filter() {
        @Override
        protected ObjectInserter delegate() {
          return ins;
        }

        @Override
        public void flush() {
        }

        @Override
        public void release() {
        }
      });

      boolean couldMerge = false;
      try {
        couldMerge = m.merge(b.getParents());
      } catch (IOException e) {
        //
      }

      if (couldMerge) {
        treeId = m.getResultTreeId();

      } else {
        RevCommit ours = b.getParent(0);
        RevCommit theirs = b.getParent(1);
        rw.parseBody(ours);
        rw.parseBody(theirs);
        String oursMsg = ours.getShortMessage();
        String theirsMsg = theirs.getShortMessage();

        String oursName = String.format("HEAD   (%s %s)",
            ours.abbreviate(6).name(),
            oursMsg.substring(0, Math.min(oursMsg.length(), 60)));
        String theirsName = String.format("BRANCH (%s %s)",
            theirs.abbreviate(6).name(),
            theirsMsg.substring(0, Math.min(theirsMsg.length(), 60)));

        MergeFormatter fmt = new MergeFormatter();
        Map<String, MergeResult<? extends Sequence>> r = m.getMergeResults();
        Map<String, ObjectId> resolved = new HashMap<String, ObjectId>();
        for (String path : r.keySet()) {
          MergeResult<? extends Sequence> p = r.get(path);
          TemporaryBuffer buf = new TemporaryBuffer.LocalFile(10 * 1024 * 1024);
          try {
            fmt.formatMerge(buf, p, "BASE", oursName, theirsName, "UTF-8");
            buf.close();

            InputStream in = buf.openInputStream();
            try {
              resolved.put(path, ins.insert(Constants.OBJ_BLOB, buf.length(), in));
            } finally {
              in.close();
            }
          } finally {
            buf.destroy();
          }
        }

        DirCacheBuilder builder = dc.builder();
        int cnt = dc.getEntryCount();
        for (int i = 0; i < cnt;) {
          DirCacheEntry entry = dc.getEntry(i);
          if (entry.getStage() == 0) {
            builder.add(entry);
            i++;
            continue;
          }

          int next = dc.nextEntry(i);
          String path = entry.getPathString();
          DirCacheEntry res = new DirCacheEntry(path);
          if (resolved.containsKey(path)) {
            // For a file with content merge conflict that we produced a result
            // above on, collapse the file down to a single stage 0 with just
            // the blob content, and a randomly selected mode (the lowest stage,
            // which should be the merge base, or ours).
            res.setFileMode(entry.getFileMode());
            res.setObjectId(resolved.get(path));

          } else if (next == i + 1) {
            // If there is exactly one stage present, shouldn't be a conflict...
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());

          } else if (next == i + 2) {
            // Two stages suggests a delete/modify conflict. Pick the higher
            // stage as the automatic result.
            entry = dc.getEntry(i + 1);
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());

          } else { // 3 stage conflict, no resolve above
            // Punt on the 3-stage conflict and show the base, for now.
            res.setFileMode(entry.getFileMode());
            res.setObjectId(entry.getObjectId());
          }
          builder.add(res);
          i = next;
        }
        builder.finish();
        treeId = dc.writeTree(ins);
      }
      ins.flush();
    } finally {
      ins.release();
    }

    RefUpdate update = repo.updateRef(refName);
    update.setNewObjectId(treeId);
    update.disableRefLog();
View Full Code Here


    update.forceUpdate();
    return rw.parseTree(treeId);
  }

  private static ObjectId emptyTree(final Repository repo) throws IOException {
    ObjectInserter oi = repo.newObjectInserter();
    try {
      ObjectId id = oi.insert(Constants.OBJ_TREE, new byte[] {});
      oi.flush();
      return id;
    } finally {
      oi.release();
    }
  }
View Full Code Here

  }

  private void createEmptyCommits(final Repository repo,
      final Project.NameKey project, final List<String> refs)
      throws IOException {
    ObjectInserter oi = repo.newObjectInserter();
    try {
      CommitBuilder cb = new CommitBuilder();
      cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {}));
      cb.setAuthor(metaDataUpdateFactory.getUserPersonIdent());
      cb.setCommitter(serverIdent);
      cb.setMessage("Initial empty repository\n");

      ObjectId id = oi.insert(cb);
      oi.flush();

      for (String ref : refs) {
        RefUpdate ru = repo.updateRef(ref);
        ru.setNewObjectId(id);
        final Result result = ru.update();
        switch (result) {
          case NEW:
            referenceUpdated.fire(project, ref);
            break;
          default: {
            throw new IOException(String.format(
              "Failed to create ref \"%s\": %s", ref, result.name()));
          }
        }
      }
    } catch (IOException e) {
      log.error(
          "Cannot create empty commit for "
              + createProjectArgs.getProjectName(), e);
      throw e;
    } finally {
      oi.release();
    }
  }
View Full Code Here

                .getRevision().get()));

        CommitBuilder rebasedCommitBuilder =
            rebaseCommit(git, originalCommit, branchTipCommit, myIdent);

        final ObjectInserter oi = git.newObjectInserter();
        final ObjectId rebasedCommitId;
        try {
          rebasedCommitId = oi.insert(rebasedCommitBuilder);
          oi.flush();
        } finally {
          oi.release();
        }

        Change updatedChange =
            db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() {
              @Override
View Full Code Here

      revertCommit.setTreeId(parentToCommitToRevert.getTree());
      revertCommit.setAuthor(authorIdent);
      revertCommit.setCommitter(myIdent);
      revertCommit.setMessage(message);

      final ObjectInserter oi = git.newObjectInserter();;
      ObjectId id;
      try {
        id = oi.insert(revertCommit);
        oi.flush();
      } finally {
        oi.release();
      }

      Change.Key changeKey = new Change.Key("I" + id.name());
      final Change change =
          new Change(changeKey, new Change.Id(db.nextChangeId()),
View Full Code Here

  private int indexVersion = -1;

  @Override
  protected void run() throws Exception {
    BufferedInputStream in = new BufferedInputStream(System.in);
    ObjectInserter inserter = db.newObjectInserter();
    try {
      PackParser p = inserter.newPackParser(in);
      p.setAllowThin(fixThin);
      if (indexVersion != -1 && p instanceof ObjectDirectoryPackParser) {
        ObjectDirectoryPackParser imp = (ObjectDirectoryPackParser) p;
        imp.setIndexVersion(indexVersion);
      }
      p.parse(new TextProgressMonitor());
      inserter.flush();
    } finally {
      inserter.release();
    }
  }
View Full Code Here

    ProgressMonitor receiving = NullProgressMonitor.INSTANCE;
    ProgressMonitor resolving = NullProgressMonitor.INSTANCE;
    if (sideBand)
      resolving = new SideBandProgressMonitor(msgOut);

    ObjectInserter ins = db.newObjectInserter();
    try {
      String lockMsg = "jgit receive-pack";
      if (getRefLogIdent() != null)
        lockMsg += " from " + getRefLogIdent().toExternalString();

      parser = ins.newPackParser(rawIn);
      parser.setAllowThin(true);
      parser.setNeedNewObjectIds(checkReferencedIsReachable);
      parser.setNeedBaseObjectIds(checkReferencedIsReachable);
      parser.setCheckEofAfterPackFooter(!biDirectionalPipe
          && !isExpectDataAfterPackFooter());
      parser.setExpectDataAfterPackFooter(isExpectDataAfterPackFooter());
      parser.setObjectChecking(isCheckReceivedObjects());
      parser.setLockMessage(lockMsg);
      parser.setMaxObjectSizeLimit(maxObjectSizeLimit);
      packLock = parser.parse(receiving, resolving);
      ins.flush();
    } finally {
      ins.release();
    }

    if (timeoutIn != null)
      timeoutIn.setTimeout(timeout * 1000);
  }
 
View Full Code Here

    } finally {
      br.close();
    }

    pm.beginTask("Rewriting commits", queue.size());
    final ObjectInserter oi = db.newObjectInserter();
    final ObjectId emptyTree = oi.insert(Constants.OBJ_TREE, new byte[] {});
    final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph", //$NON-NLS-1$
        "rebuild-commitgraph@localhost"); //$NON-NLS-1$
    while (!queue.isEmpty()) {
      final ListIterator<ToRewrite> itr = queue
          .listIterator(queue.size());
      queue = new ArrayList<ToRewrite>();
      REWRITE: while (itr.hasPrevious()) {
        final ToRewrite t = itr.previous();
        final ObjectId[] newParents = new ObjectId[t.oldParents.length];
        for (int k = 0; k < t.oldParents.length; k++) {
          final ToRewrite p = toRewrite.get(t.oldParents[k]);
          if (p != null) {
            if (p.newId == null) {
              // Must defer until after the parent is rewritten.
              queue.add(t);
              continue REWRITE;
            } else {
              newParents[k] = p.newId;
            }
          } else {
            // We have the old parent object. Use it.
            //
            newParents[k] = t.oldParents[k];
          }
        }

        final CommitBuilder newc = new CommitBuilder();
        newc.setTreeId(emptyTree);
        newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
        newc.setCommitter(newc.getAuthor());
        newc.setParentIds(newParents);
        newc.setMessage("ORIGINAL " + t.oldId.name() + "\n"); //$NON-NLS-2$
        t.newId = oi.insert(newc);
        rewrites.put(t.oldId, t.newId);
        pm.update(1);
      }
    }
    oi.flush();
    oi.release();
    pm.endTask();
  }
View Full Code Here

      builder = null;

      if (hasConflict)
        return false;
      try {
        ObjectInserter odi = getObjectInserter();
        resultTree = cache.writeTree(odi);
        odi.flush();
        return true;
      } catch (UnmergedPathException upe) {
        resultTree = null;
        return false;
      }
View Full Code Here

        parents.add(0, headId);

      // lock the index
      DirCache index = repo.lockDirCache();
      try {
        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);

          // 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);
            ru.setRefLogMessage("commit : "
                + revCommit.getShortMessage(), false);

            ru.setExpectedOldObjectId(headId);
            Result rc = ru.update();
            switch (rc) {
            case NEW:
            case FAST_FORWARD: {
              setCallable(false);
              if (state == RepositoryState.MERGING_RESOLVED) {
                // Commit was successful. Now delete the files
                // used for merge commits
                repo.writeMergeCommitMsg(null);
                repo.writeMergeHeads(null);
              }
              return revCommit;
            }
            case REJECTED:
            case LOCK_FAILURE:
              throw new ConcurrentRefUpdateException(JGitText
                  .get().couldNotLockHEAD, ru.getRef(), rc);
            default:
              throw new JGitInternalException(MessageFormat
                  .format(JGitText.get().updatingRefFailed,
                      Constants.HEAD,
                      commitId.toString(), rc));
            }
          } finally {
            revWalk.release();
          }
        } finally {
          odi.release();
        }
      } finally {
        index.unlock();
      }
    } catch (UnmergedPathException e) {
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.ObjectInserter$Filter

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.