Search in sources :

Example 1 with PathEdit

use of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit in project gerrit by GerritCodeReview.

the class SubmoduleOp method updateSubmodule.

private RevCommit updateSubmodule(DirCache dc, DirCacheEditor ed, StringBuilder msgbuf, final SubmoduleSubscription s) throws SubmoduleException, IOException {
    OpenRepo subOr;
    try {
        subOr = orm.getRepo(s.getSubmodule().getParentKey());
    } catch (NoSuchProjectException | IOException e) {
        throw new SubmoduleException("Cannot access submodule", e);
    }
    DirCacheEntry dce = dc.getEntry(s.getPath());
    RevCommit oldCommit = null;
    if (dce != null) {
        if (!dce.getFileMode().equals(FileMode.GITLINK)) {
            String errMsg = "Requested to update gitlink " + s.getPath() + " in " + s.getSubmodule().getParentKey().get() + " but entry " + "doesn't have gitlink file mode.";
            throw new SubmoduleException(errMsg);
        }
        oldCommit = subOr.rw.parseCommit(dce.getObjectId());
    }
    final CodeReviewCommit newCommit;
    if (branchTips.containsKey(s.getSubmodule())) {
        newCommit = branchTips.get(s.getSubmodule());
    } else {
        Ref ref = subOr.repo.getRefDatabase().exactRef(s.getSubmodule().get());
        if (ref == null) {
            ed.add(new DeletePath(s.getPath()));
            return null;
        }
        newCommit = subOr.rw.parseCommit(ref.getObjectId());
        addBranchTip(s.getSubmodule(), newCommit);
    }
    if (Objects.equals(newCommit, oldCommit)) {
        // gitlink have already been updated for this submodule
        return null;
    }
    ed.add(new PathEdit(s.getPath()) {

        @Override
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.GITLINK);
            ent.setObjectId(newCommit.getId());
        }
    });
    if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
        createSubmoduleCommitMsg(msgbuf, s, subOr, newCommit, oldCommit);
    }
    subOr.rw.parseBody(newCommit);
    return newCommit;
}
Also used : DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) PathEdit(org.eclipse.jgit.dircache.DirCacheEditor.PathEdit) IOException(java.io.IOException) DeletePath(org.eclipse.jgit.dircache.DirCacheEditor.DeletePath) Ref(org.eclipse.jgit.lib.Ref) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with PathEdit

use of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit in project gerrit by GerritCodeReview.

the class VersionedMetaData method saveFile.

protected void saveFile(String fileName, byte[] raw) throws IOException {
    DirCacheEditor editor = newTree.editor();
    if (raw != null && 0 < raw.length) {
        final ObjectId blobId = inserter.insert(Constants.OBJ_BLOB, raw);
        editor.add(new PathEdit(fileName) {

            @Override
            public void apply(DirCacheEntry ent) {
                ent.setFileMode(FileMode.REGULAR_FILE);
                ent.setObjectId(blobId);
            }
        });
    } else {
        editor.add(new DeletePath(fileName));
    }
    editor.finish();
}
Also used : DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) PathEdit(org.eclipse.jgit.dircache.DirCacheEditor.PathEdit) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor) DeletePath(org.eclipse.jgit.dircache.DirCacheEditor.DeletePath)

Example 3 with PathEdit

use of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit in project gitiles by GerritCodeReview.

the class PathServletTest method symlinkText.

@Test
public void symlinkText() throws Exception {
    final RevBlob link = repo.blob("foo");
    repo.branch("master").commit().edit(new PathEdit("baz") {

        @Override
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.SYMLINK);
            ent.setObjectId(link);
        }
    }).create();
    String text = buildBlob("/repo/+/master/baz", "120000");
    assertThat(text).isEqualTo("foo");
}
Also used : DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) RevBlob(org.eclipse.jgit.revwalk.RevBlob) PathEdit(org.eclipse.jgit.dircache.DirCacheEditor.PathEdit) Test(org.junit.Test)

Example 4 with PathEdit

use of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit in project gitiles by GerritCodeReview.

the class PathServletTest method symlinkHtml.

@Test
public void symlinkHtml() throws Exception {
    final RevBlob link = repo.blob("foo");
    repo.branch("master").commit().add("foo", "contents").edit(new PathEdit("bar") {

        @Override
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.SYMLINK);
            ent.setObjectId(link);
        }
    }).create();
    Map<String, ?> data = buildData("/repo/+/master/bar");
    assertThat(data).containsEntry("type", "SYMLINK");
    assertThat(getBlobData(data)).containsEntry("target", "foo");
}
Also used : DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) RevBlob(org.eclipse.jgit.revwalk.RevBlob) PathEdit(org.eclipse.jgit.dircache.DirCacheEditor.PathEdit) Test(org.junit.Test)

Example 5 with PathEdit

use of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit in project gitiles by GerritCodeReview.

the class PathServletTest method treeJsonLinkTarget.

@Test
public void treeJsonLinkTarget() throws Exception {
    final ObjectId targetID = repo.blob("target");
    RevCommit c = repo.parseBody(repo.branch("master").commit().edit(new PathEdit("link") {

        @Override
        public void apply(DirCacheEntry ent) {
            ent.setFileMode(FileMode.SYMLINK);
            ent.setObjectId(targetID);
        }
    }).create());
    Tree tree = buildJson(Tree.class, "/repo/+/master/", "long=1");
    assertThat(tree.id).isEqualTo(c.getTree().name());
    assertThat(tree.entries).hasSize(1);
    TreeJsonData.Entry e = tree.entries.get(0);
    assertThat(e.mode).isEqualTo(0120000);
    assertThat(e.type).isEqualTo("blob");
    assertThat(e.name).isEqualTo("link");
    assertThat(e.id).isEqualTo(targetID.name());
    assertThat(e.target).isEqualTo("target");
}
Also used : DirCacheEntry(org.eclipse.jgit.dircache.DirCacheEntry) ObjectId(org.eclipse.jgit.lib.ObjectId) PathEdit(org.eclipse.jgit.dircache.DirCacheEditor.PathEdit) Tree(com.google.gitiles.TreeJsonData.Tree) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

PathEdit (org.eclipse.jgit.dircache.DirCacheEditor.PathEdit)5 DirCacheEntry (org.eclipse.jgit.dircache.DirCacheEntry)5 Test (org.junit.Test)3 DeletePath (org.eclipse.jgit.dircache.DirCacheEditor.DeletePath)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevBlob (org.eclipse.jgit.revwalk.RevBlob)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 OpenRepo (com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo)1 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)1 Tree (com.google.gitiles.TreeJsonData.Tree)1 IOException (java.io.IOException)1 DirCacheEditor (org.eclipse.jgit.dircache.DirCacheEditor)1 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)1 Ref (org.eclipse.jgit.lib.Ref)1 RevTree (org.eclipse.jgit.revwalk.RevTree)1