throws SubmoduleException {
PersonIdent author = null;
final StringBuilder msgbuf = new StringBuilder();
msgbuf.append("Updated " + subscriber.getParentKey().get());
Repository pdb = null;
try {
boolean sameAuthorForAll = true;
for (final Map.Entry<Branch.NameKey, ObjectId> me : modules.entrySet()) {
RevCommit c = rw.parseCommit(me.getValue());
msgbuf.append("\nProject: ");
msgbuf.append(me.getKey().getParentKey().get());
msgbuf.append(" " + me.getValue().getName());
msgbuf.append("\n");
if (modules.size() == 1 && msg != null) {
msgbuf.append(msg);
} else {
msgbuf.append(c.getShortMessage());
}
msgbuf.append("\n");
if (author == null) {
author = c.getAuthorIdent();
} else if (!author.equals(c.getAuthorIdent())) {
sameAuthorForAll = false;
}
}
if (!sameAuthorForAll || author == null) {
author = myIdent;
}
pdb = repoManager.openRepository(subscriber.getParentKey());
if (pdb.getRef(subscriber.get()) == null) {
throw new SubmoduleException(
"The branch was probably deleted from the subscriber repository");
}
final ObjectId currentCommitId =
pdb.getRef(subscriber.get()).getObjectId();
DirCache dc = readTree(pdb, pdb.getRef(subscriber.get()));
DirCacheEditor ed = dc.editor();
for (final Map.Entry<Branch.NameKey, ObjectId> me : modules.entrySet()) {
ed.add(new PathEdit(paths.get(me.getKey())) {
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.GITLINK);
ent.setObjectId(me.getValue().copy());
}
});
}
ed.finish();
ObjectInserter oi = pdb.newObjectInserter();
ObjectId tree = dc.writeTree(oi);
final CommitBuilder commit = new CommitBuilder();
commit.setTreeId(tree);
commit.setParentIds(new ObjectId[] {currentCommitId});
commit.setAuthor(author);
commit.setCommitter(myIdent);
commit.setMessage(msgbuf.toString());
oi.insert(commit);
ObjectId commitId = oi.idFor(Constants.OBJ_COMMIT, commit.build());
final RefUpdate rfu = pdb.updateRef(subscriber.get());
rfu.setForceUpdate(false);
rfu.setNewObjectId(commitId);
rfu.setExpectedOldObjectId(currentCommitId);
rfu
.setRefLogMessage("Submit to " + subscriber.getParentKey().get(),
true);
switch (rfu.update()) {
case NEW:
case FAST_FORWARD:
replication.fire(subscriber.getParentKey(), rfu.getName());
// TODO since this is performed "in the background" no mail will be
// sent to inform users about the updated branch
break;
default:
throw new IOException(rfu.getResult().name());
}
// Recursive call: update subscribers of the subscriber
updateSuperProjects(subscriber, commitId, msgbuf.toString());
} catch (IOException e) {
logAndThrowSubmoduleException("Cannot update gitlinks for "
+ subscriber.get(), e);
} finally {
if (pdb != null) {
pdb.close();
}
}
}