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;
}
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();
}
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");
}
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");
}
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");
}
Aggregations