checkParameter(!(args.stats && args.oneline),
"--name-only and --oneline cannot be used together");
geogig = cli.getGeogig();
LogOp op = geogig.command(LogOp.class).setTopoOrder(args.topo)
.setFirstParentOnly(args.firstParent);
refs = Maps.newHashMap();
if (args.decoration) {
Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
refs.put(head.get().getObjectId(), Ref.HEAD);
ImmutableSet<Ref> set = geogig.command(ForEachRef.class)
.setPrefixFilter(Ref.REFS_PREFIX).call();
for (Ref ref : set) {
ObjectId id = ref.getObjectId();
if (refs.containsKey(id)) {
refs.put(id, refs.get(id) + ", " + ref.getName());
} else {
refs.put(id, ref.getName());
}
}
}
if (args.all) {
ImmutableSet<Ref> refs = geogig.command(ForEachRef.class)
.setPrefixFilter(Ref.REFS_PREFIX).call();
List<ObjectId> list = Lists.newArrayList();
for (Ref ref : refs) {
list.add(ref.getObjectId());
}
Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
if (head.isPresent()) {
Ref ref = head.get();
if (ref instanceof SymRef) {
ObjectId id = ref.getObjectId();
list.remove(id);
list.add(id);// put the HEAD ref in the last position, to give it preference
}
}
for (ObjectId id : list) {
op.addCommit(id);
}
} else if (args.branch != null) {
Optional<Ref> obj = geogig.command(RefParse.class).setName(args.branch).call();
checkParameter(obj.isPresent(), "Wrong branch name: " + args.branch);
op.addCommit(obj.get().getObjectId());
}
if (args.author != null && !args.author.isEmpty()) {
op.setAuthor(args.author);
}
if (args.committer != null && !args.committer.isEmpty()) {
op.setCommiter(args.committer);
}
if (args.skip != null) {
op.setSkip(args.skip.intValue());
}
if (args.limit != null) {
op.setLimit(args.limit.intValue());
}
if (args.since != null || args.until != null) {
Date since = new Date(0);
Date until = new Date();
if (args.since != null) {
since = new Date(geogig.command(ParseTimestamp.class).setString(args.since).call());
}
if (args.until != null) {
until = new Date(geogig.command(ParseTimestamp.class).setString(args.until).call());
if (args.all) {
throw new InvalidParameterException(
"Cannot specify 'until' commit when listing all branches");
}
}
op.setTimeRange(new Range<Date>(Date.class, since, until));
}
if (!args.sinceUntilPaths.isEmpty()) {
List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..")
.split(args.sinceUntilPaths.get(0))));
checkParameter(sinceUntil.size() == 1 || sinceUntil.size() == 2,
"Invalid refSpec format, expected [<until>]|[<since>..<until>]: %s",
args.sinceUntilPaths.get(0));
String sinceRefSpec;
String untilRefSpec;
if (sinceUntil.size() == 1) {
// just until was given
sinceRefSpec = null;
untilRefSpec = sinceUntil.get(0);
} else {
sinceRefSpec = sinceUntil.get(0);
untilRefSpec = sinceUntil.get(1);
}
if (sinceRefSpec != null) {
Optional<ObjectId> since;
since = geogig.command(RevParse.class).setRefSpec(sinceRefSpec).call();
checkParameter(since.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setSince(since.get());
}
if (untilRefSpec != null) {
if (args.all) {
throw new InvalidParameterException(
"Cannot specify 'until' commit when listing all branches");
}
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(untilRefSpec).call();
checkParameter(until.isPresent(), "Object not found '%s'", sinceRefSpec);
op.setUntil(until.get());
}
}
if (!args.pathNames.isEmpty()) {
for (String s : args.pathNames) {
op.addPath(s);
}
}
Iterator<RevCommit> log = op.call();
this.console = cli.getConsole();
if (!log.hasNext()) {
console.println("No commits to show");
console.flush();
return;