Search in sources :

Example 16 with ObjectInserter

use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.

the class MergeUtil method canCherryPick.

public boolean canCherryPick(MergeSorter mergeSorter, Repository repo, CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) throws IntegrationException {
    if (mergeTip == null) {
        //
        return true;
    }
    if (toMerge.getParentCount() == 0) {
        //
        return false;
    }
    if (toMerge.getParentCount() == 1) {
        //
        try (ObjectInserter ins = new InMemoryInserter(repo)) {
            ThreeWayMerger m = newThreeWayMerger(ins, repo.getConfig());
            m.setBase(toMerge.getParent(0));
            return m.merge(mergeTip, toMerge);
        } catch (IOException e) {
            throw new IntegrationException(String.format("Cannot merge commit %s with mergetip %s", toMerge.name(), mergeTip.name()), e);
        }
    }
    //
    return canFastForward(mergeSorter, mergeTip, rw, toMerge) || canMerge(mergeSorter, repo, mergeTip, toMerge);
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ThreeWayMerger(org.eclipse.jgit.merge.ThreeWayMerger) IOException(java.io.IOException)

Example 17 with ObjectInserter

use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.

the class NoteDbUpdateManager method openRepo.

private OpenRepo openRepo(Project.NameKey p) throws IOException {
    // Closed by OpenRepo#close.
    Repository repo = repoManager.openRepository(p);
    // Closed by OpenRepo#close.
    ObjectInserter ins = repo.newObjectInserter();
    // Not closed by OpenRepo#close.
    ObjectReader reader = ins.newReader();
    try (RevWalk rw = new RevWalk(reader)) {
        // Doesn't escape OpenRepo constructor.
        return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {

            @Override
            public void close() {
                reader.close();
                super.close();
            }
        };
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ChainedReceiveCommands(com.google.gerrit.server.update.ChainedReceiveCommands) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 18 with ObjectInserter

use of org.eclipse.jgit.lib.ObjectInserter in project gerrit by GerritCodeReview.

the class RepoSequence method store.

private RefUpdate.Result store(Repository repo, RevWalk rw, @Nullable ObjectId oldId, int val) throws IOException {
    ObjectId newId;
    try (ObjectInserter ins = repo.newObjectInserter()) {
        newId = ins.insert(OBJ_BLOB, Integer.toString(val).getBytes(UTF_8));
        ins.flush();
    }
    RefUpdate ru = repo.updateRef(refName);
    if (oldId != null) {
        ru.setExpectedOldObjectId(oldId);
    }
    ru.setNewObjectId(newId);
    // Required for non-commitish updates.
    ru.setForceUpdate(true);
    return ru.update(rw);
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 19 with ObjectInserter

use of org.eclipse.jgit.lib.ObjectInserter in project gitiles by GerritCodeReview.

the class TimeCacheTest method tagMissingTime.

@Test
public void tagMissingTime() throws Exception {
    RevCommit commit = repo.commit().create();
    TagBuilder builder = new TagBuilder();
    builder.setObjectId(commit);
    builder.setTag("tag");
    builder.setMessage("");
    ObjectId id;
    try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
        id = ins.insert(builder);
        ins.flush();
    }
    assertThat(getTime(commit)).isEqualTo(start + 1);
    assertThat(getTime(id)).isEqualTo(start + 1);
}
Also used : ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) TagBuilder(org.eclipse.jgit.lib.TagBuilder) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 20 with ObjectInserter

use of org.eclipse.jgit.lib.ObjectInserter in project gitiles by GerritCodeReview.

the class TimeCacheTest method firstTagMissingTime.

@Test
public void firstTagMissingTime() throws Exception {
    RevCommit commit = repo.commit().create();
    repo.tick(1);
    RevTag tag = repo.tag("tag", commit);
    repo.tick(1);
    TagBuilder builder = new TagBuilder();
    builder.setObjectId(tag);
    builder.setTag("tagtag");
    builder.setMessage("");
    ObjectId tagTagId;
    try (ObjectInserter ins = repo.getRepository().newObjectInserter()) {
        tagTagId = ins.insert(builder);
        ins.flush();
    }
    assertThat(getTime(commit)).isEqualTo(start + 1);
    assertThat(getTime(tag)).isEqualTo(start + 2);
    assertThat(getTime(tagTagId)).isEqualTo(start + 2);
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ObjectId(org.eclipse.jgit.lib.ObjectId) TagBuilder(org.eclipse.jgit.lib.TagBuilder) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)56 ObjectId (org.eclipse.jgit.lib.ObjectId)39 RevWalk (org.eclipse.jgit.revwalk.RevWalk)30 Repository (org.eclipse.jgit.lib.Repository)26 IOException (java.io.IOException)17 ObjectReader (org.eclipse.jgit.lib.ObjectReader)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 Change (com.google.gerrit.reviewdb.client.Change)13 PersonIdent (org.eclipse.jgit.lib.PersonIdent)12 NoteMap (org.eclipse.jgit.notes.NoteMap)12 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)11 RefUpdate (org.eclipse.jgit.lib.RefUpdate)11 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)10 OrmException (com.google.gwtorm.server.OrmException)8 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 Project (com.google.gerrit.reviewdb.client.Project)6 ChangeControl (com.google.gerrit.server.project.ChangeControl)6 DirCache (org.eclipse.jgit.dircache.DirCache)6 Ref (org.eclipse.jgit.lib.Ref)6