use of org.locationtech.geogig.api.RevPerson in project GeoGig by boundlessgeo.
the class HashObjectTest method testHashTags.
@Test
public void testHashTags() throws Exception {
RevPerson tagger = new RevPersonImpl("volaya", "volaya@boundlessgeo.com", -1000, -1);
RevPerson tagger2 = new RevPersonImpl("groldan", "groldan@boundlessgeo.com", 10000, 0);
RevTag tag = new RevTagImpl(null, "tag1", ObjectId.forString("fake commit id"), "message", tagger);
RevTag tag2 = new RevTagImpl(null, "tag2", ObjectId.forString("another fake commit id"), "another message", tagger2);
ObjectId tagId = hashCommand.setObject(tag).call();
ObjectId tagId2 = hashCommand.setObject(tag2).call();
assertNotNull(tagId);
assertNotNull(tagId2);
assertNotSame(tagId, tagId2);
}
use of org.locationtech.geogig.api.RevPerson in project GeoGig by boundlessgeo.
the class TagCreateOp method _call.
/**
* Executes the tag creation operation.
*
* @return the created tag
*
*/
@Override
protected RevTag _call() throws RuntimeException {
checkState(name != null, "tag name was not provided");
final String tagRefPath = Ref.TAGS_PREFIX + name;
checkArgument(!command(RefParse.class).setName(tagRefPath).call().isPresent(), "A tag named '" + name + "' already exists.");
if (commitId == null) {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't create tag");
commitId = currHead.get().getObjectId();
}
RevPerson tagger = resolveTagger();
message = message == null ? "" : message;
RevTag tag = new RevTagImpl(ObjectId.NULL, name, commitId, message, tagger);
ObjectId id = command(HashObject.class).setObject(tag).call();
tag = new RevTagImpl(id, name, commitId, message, tagger);
objectDatabase().put(tag);
Optional<Ref> branchRef = command(UpdateRef.class).setName(tagRefPath).setNewValue(tag.getId()).call();
checkState(branchRef.isPresent());
return tag;
}
use of org.locationtech.geogig.api.RevPerson in project GeoGig by boundlessgeo.
the class StatisticsWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
final Context geogig = this.getCommandLocator(context);
final List<FeatureTypeStats> stats = Lists.newArrayList();
LogOp logOp = geogig.command(LogOp.class).setFirstParentOnly(true);
final Iterator<RevCommit> log;
if (since != null && !since.trim().isEmpty()) {
Date untilTime = new Date();
Date sinceTime = new Date(geogig.command(ParseTimestamp.class).setString(since).call());
logOp.setTimeRange(new Range<Date>(Date.class, sinceTime, untilTime));
}
if (this.until != null) {
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(this.until).call();
Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
logOp.setUntil(until.get());
}
LsTreeOp lsTreeOp = geogig.command(LsTreeOp.class).setStrategy(LsTreeOp.Strategy.TREES_ONLY);
if (path != null && !path.trim().isEmpty()) {
lsTreeOp.setReference(path);
logOp.addPath(path);
}
final Iterator<NodeRef> treeIter = lsTreeOp.call();
while (treeIter.hasNext()) {
NodeRef node = treeIter.next();
stats.add(new FeatureTypeStats(node.path(), context.getGeoGIG().getRepository().getTree(node.objectId()).size()));
}
log = logOp.call();
RevCommit firstCommit = null;
RevCommit lastCommit = null;
int totalCommits = 0;
final List<RevPerson> authors = Lists.newArrayList();
if (log.hasNext()) {
lastCommit = log.next();
authors.add(lastCommit.getAuthor());
totalCommits++;
}
while (log.hasNext()) {
firstCommit = log.next();
RevPerson newAuthor = firstCommit.getAuthor();
// If the author isn't defined, use the committer for the purposes of statistics.
if (!newAuthor.getName().isPresent() && !newAuthor.getEmail().isPresent()) {
newAuthor = firstCommit.getCommitter();
}
if (newAuthor.getName().isPresent() || newAuthor.getEmail().isPresent()) {
boolean authorFound = false;
for (RevPerson author : authors) {
if (newAuthor.getName().equals(author.getName()) && newAuthor.getEmail().equals(author.getEmail())) {
authorFound = true;
break;
}
}
if (!authorFound) {
authors.add(newAuthor);
}
}
totalCommits++;
}
int addedFeatures = 0;
int modifiedFeatures = 0;
int removedFeatures = 0;
if (since != null && !since.trim().isEmpty() && firstCommit != null && lastCommit != null) {
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(firstCommit.getId()).setNewVersion(lastCommit.getId()).setFilter(path).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
addedFeatures++;
} else if (entry.changeType() == DiffEntry.ChangeType.MODIFIED) {
modifiedFeatures++;
} else {
removedFeatures++;
}
}
}
final RevCommit first = firstCommit;
final RevCommit last = lastCommit;
final int total = totalCommits;
final int added = addedFeatures;
final int modified = modifiedFeatures;
final int removed = removedFeatures;
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start(true);
out.writeStatistics(stats, first, last, total, authors, added, modified, removed);
out.finish();
}
});
}
use of org.locationtech.geogig.api.RevPerson in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readTag.
public static RevTag readTag(ObjectId id, DataInput in) throws IOException {
final ObjectId commitId = readObjectId(in);
final String name = in.readUTF();
final String message = in.readUTF();
final RevPerson tagger = readRevPerson(in);
return new RevTagImpl(id, name, commitId, message, tagger);
}
use of org.locationtech.geogig.api.RevPerson in project GeoGig by boundlessgeo.
the class FormatCommonV1 method readCommit.
public static RevCommit readCommit(ObjectId id, DataInput in) throws IOException {
byte tag = in.readByte();
if (tag != COMMIT_TREE_REF) {
throw new IllegalArgumentException("Commit should include a tree ref");
}
final byte[] treeIdBytes = new byte[20];
in.readFully(treeIdBytes);
final ObjectId treeId = ObjectId.createNoClone(treeIdBytes);
final Builder<ObjectId> parentListBuilder = ImmutableList.builder();
while (true) {
tag = in.readByte();
if (tag != COMMIT_PARENT_REF) {
break;
} else {
final byte[] parentIdBytes = new byte[20];
in.readFully(parentIdBytes);
parentListBuilder.add(ObjectId.createNoClone(parentIdBytes));
}
}
if (tag != COMMIT_AUTHOR_PREFIX) {
throw new IllegalArgumentException("Expected AUTHOR element following parent ids in commit");
}
final RevPerson author = readRevPerson(in);
tag = in.readByte();
if (tag != COMMIT_COMMITTER_PREFIX) {
throw new IllegalArgumentException("Expected COMMITTER element following author in commit");
}
final RevPerson committer = readRevPerson(in);
final String message = in.readUTF();
return new RevCommitImpl(id, treeId, parentListBuilder.build(), author, committer, message);
}
Aggregations