@Override
protected void run() throws Exception {
if (CookieHandler.getDefault() == null)
CookieHandler.setDefault(new SimpleCookieManager());
final IpLogGenerator log = new IpLogGenerator();
if (commitId == null) {
System.err.println(MessageFormat.format(
CLIText.get().warningNoCommitGivenOnCommandLine, Constants.HEAD));
commitId = db.resolve(Constants.HEAD);
}
final RevWalk rw = new RevWalk(db);
final RevObject start = rw.parseAny(commitId);
if (version == null && start instanceof RevTag)
version = ((RevTag) start).getTagName();
else if (version == null)
throw die(MessageFormat.format(CLIText.get().notATagVersionIsRequired, start.name()));
log.scan(db, rw.parseCommit(start), version);
if (output != null) {
if (!output.getParentFile().exists())
output.getParentFile().mkdirs();
LockFile lf = new LockFile(output, db.getFS());
if (!lf.lock())
throw die(MessageFormat.format(CLIText.get().cannotLock, output));
try {
OutputStream os = lf.getOutputStream();
try {
log.writeTo(os);
} finally {
os.close();
}
if (!lf.commit())
throw die(MessageFormat.format(CLIText.get().cannotWrite, output));
} finally {
lf.unlock();
}
} else {
log.writeTo(System.out);
System.out.flush();
}
}