Search in sources :

Example 1 with RevPerson

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);
}
Also used : RevPersonImpl(org.locationtech.geogig.api.RevPersonImpl) RevPerson(org.locationtech.geogig.api.RevPerson) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevTagImpl(org.locationtech.geogig.api.RevTagImpl) Test(org.junit.Test)

Example 2 with RevPerson

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;
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RevPerson(org.locationtech.geogig.api.RevPerson) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevTagImpl(org.locationtech.geogig.api.RevTagImpl) RefParse(org.locationtech.geogig.api.plumbing.RefParse) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef)

Example 3 with RevPerson

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();
        }
    });
}
Also used : ParseTimestamp(org.locationtech.geogig.api.plumbing.ParseTimestamp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) NodeRef(org.locationtech.geogig.api.NodeRef) RevPerson(org.locationtech.geogig.api.RevPerson) RevParse(org.locationtech.geogig.api.plumbing.RevParse) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ObjectId(org.locationtech.geogig.api.ObjectId) Date(java.util.Date) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter)

Example 4 with RevPerson

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);
}
Also used : RevPerson(org.locationtech.geogig.api.RevPerson) ObjectId(org.locationtech.geogig.api.ObjectId) RevTagImpl(org.locationtech.geogig.api.RevTagImpl)

Example 5 with RevPerson

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);
}
Also used : RevPerson(org.locationtech.geogig.api.RevPerson) ObjectId(org.locationtech.geogig.api.ObjectId) RevCommitImpl(org.locationtech.geogig.api.RevCommitImpl)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)7 RevPerson (org.locationtech.geogig.api.RevPerson)7 RevTagImpl (org.locationtech.geogig.api.RevTagImpl)4 Integer.toBinaryString (java.lang.Integer.toBinaryString)2 RevCommitImpl (org.locationtech.geogig.api.RevCommitImpl)2 RevTag (org.locationtech.geogig.api.RevTag)2 Date (java.util.Date)1 Test (org.junit.Test)1 Context (org.locationtech.geogig.api.Context)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 Ref (org.locationtech.geogig.api.Ref)1 RevCommit (org.locationtech.geogig.api.RevCommit)1 RevPersonImpl (org.locationtech.geogig.api.RevPersonImpl)1 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)1 ParseTimestamp (org.locationtech.geogig.api.plumbing.ParseTimestamp)1 RefParse (org.locationtech.geogig.api.plumbing.RefParse)1 RevParse (org.locationtech.geogig.api.plumbing.RevParse)1 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 LogOp (org.locationtech.geogig.api.porcelain.LogOp)1