use of org.eclipse.jgit.dircache.DirCacheEntry in project gitblit by gitblit.
the class BranchTicketService method deleteTicketImpl.
/**
* Deletes a ticket from the repository.
*
* @param ticket
* @return true if successful
*/
@Override
protected synchronized boolean deleteTicketImpl(RepositoryModel repository, TicketModel ticket, String deletedBy) {
if (ticket == null) {
throw new RuntimeException("must specify a ticket!");
}
boolean success = false;
Repository db = repositoryManager.getRepository(ticket.repository);
try {
RefModel ticketsBranch = getTicketsBranch(db);
if (ticketsBranch == null) {
throw new RuntimeException(BRANCH + " does not exist!");
}
String ticketPath = toTicketPath(ticket.number);
TreeWalk treeWalk = null;
try {
ObjectId treeId = db.resolve(BRANCH + "^{tree}");
// Create the in-memory index of the new/updated ticket
DirCache index = DirCache.newInCore();
DirCacheBuilder builder = index.builder();
// Traverse HEAD to add all other paths
treeWalk = new TreeWalk(db);
int hIdx = -1;
if (treeId != null) {
hIdx = treeWalk.addTree(treeId);
}
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String path = treeWalk.getPathString();
CanonicalTreeParser hTree = null;
if (hIdx != -1) {
hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);
}
if (!path.startsWith(ticketPath)) {
// add entries from HEAD for all other paths
if (hTree != null) {
final DirCacheEntry entry = new DirCacheEntry(path);
entry.setObjectId(hTree.getEntryObjectId());
entry.setFileMode(hTree.getEntryFileMode());
// add to temporary in-core index
builder.add(entry);
}
}
}
// finish temporary in-core index used for this commit
builder.finish();
success = commitIndex(db, index, deletedBy, "- " + ticket.number);
} catch (Throwable t) {
log.error(MessageFormat.format("Failed to delete ticket {0,number,0} from {1}", ticket.number, db.getDirectory()), t);
} finally {
// release the treewalk
if (treeWalk != null) {
treeWalk.close();
}
}
} finally {
db.close();
}
return success;
}
use of org.eclipse.jgit.dircache.DirCacheEntry 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");
}
use of org.eclipse.jgit.dircache.DirCacheEntry in project gerrit by GerritCodeReview.
the class CommitMsgHookTest method file.
private DirCacheEntry file(final String name) throws IOException {
try (ObjectInserter oi = repository.newObjectInserter()) {
final DirCacheEntry e = new DirCacheEntry(name);
e.setFileMode(FileMode.REGULAR_FILE);
e.setObjectId(oi.insert(Constants.OBJ_BLOB, Constants.encode(name)));
oi.flush();
return e;
}
}
Aggregations