//load all commits which are older than the expiry time. mark them as dangling
DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
DBCursor commits = collCommits.find(new BasicDBObject(MongoDBConstants.TIMESTAMP,
new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), //also include commits without a timestamp
new BasicDBObject(MongoDBConstants.ID, 1));
IdSet danglingCommits = new IdHashSet();
for (DBObject o : commits) {
long cid = (Long)o.get(MongoDBConstants.ID);
danglingCommits.add(cid);
}
//walk through all branches and eliminate commits which are not dangling
DBCollection collBranches = _db.getDB().getCollection(MongoDBConstants.COLLECTION_BRANCHES);
DBCursor branches = collBranches.find(new BasicDBObject(), new BasicDBObject(MongoDBConstants.CID, 1));
VHistory history = _db.getHistory();
IdSet alreadyCheckedCommits = new IdHashSet();
for (DBObject o : branches) {
long cid = (Long)o.get(MongoDBConstants.CID);
while (cid != 0) {
if (alreadyCheckedCommits.contains(cid)) {
break;
}
alreadyCheckedCommits.add(cid);
danglingCommits.remove(cid);
cid = history.getParent(cid);
}
}