Example usage for org.eclipse.jgit.lib ObjectId equals

List of usage examples for org.eclipse.jgit.lib ObjectId equals

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId equals.

Prototype

@SuppressWarnings({ "NonOverridingEquals", "AmbiguousMethodReference" })
public final boolean equals(AnyObjectId other) 

Source Link

Document

Determine if this ObjectId has exactly the same value as another.

Usage

From source file:org.kuali.student.git.model.tree.TreeResourceContext.java

License:Educational Community License

@Override
public void storeResource(String name, GitTreeNodeData node)
        throws MissingObjectException, IncorrectObjectTypeException, IOException {

    GitTreeNodeData newTree = treeProcessor.extractExistingTreeData(objectId, name);

    GitTreeNodeData existing = node.addDirectTree(name, newTree);

    if (existing != null) {

        ObjectId existingObjectId = existing.getOriginalTreeObjectId();

        if (existingObjectId != null && !existingObjectId.equals(objectId)) {

            /*/*from  w  ww.  j  a  v a2 s .  c o  m*/
             * lets merge the tree.  We take the changes even if there are conflicts on the blob id's.
             */

            existing.merge(treeProcessor.extractExistingTreeData(objectId, existing.getName()));

            log.warn("merging conflicting trees " + getErrorMessage());
        }
    }

}

From source file:org.kuali.student.svn.model.TestExternalsFusion.java

License:Educational Community License

private void checkTrees(ObjectId originalAggregateId, ObjectId aggregateId)
        throws MissingObjectException, IncorrectObjectTypeException, IOException {

    RevWalk rw = new RevWalk(repo);

    RevCommit originalAggregateCommit = rw.parseCommit(originalAggregateId);

    RevCommit aggregateCommit = rw.parseCommit(aggregateId);

    TreeWalk tw = new TreeWalk(repo);

    tw.addTree(originalAggregateCommit.getTree().getId());
    tw.addTree(aggregateCommit.getTree().getId());

    tw.setRecursive(false);/*  ww w .  jav a2s .c  o m*/

    while (tw.next()) {

        FileMode originalMode = tw.getFileMode(0);

        FileMode fileMode = tw.getFileMode(1);

        if (originalMode.equals(FileMode.TYPE_MISSING) || fileMode.equals(FileMode.TYPE_MISSING))
            continue; // skip where one side or the other does not exist.

        String name = tw.getNameString();

        ObjectId originalObjectId = tw.getObjectId(0);
        ObjectId currentObjectId = tw.getObjectId(1);

        Assert.assertTrue(originalObjectId + " is not equals to " + currentObjectId + " for " + name,
                originalObjectId.equals(currentObjectId));

    }

    tw.release();

    rw.release();
}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

@Override
public boolean exists(String arg0) {
    try {//from   w ww  .  j a  v a2  s. c  om
        AnyObjectId id = repository.resolve(Constants.HEAD);
        RevCommit commit = new RevWalk(repository).parseCommit(id);
        LOGGER.debug("Looking up file {} in HEAD revision", arg0);
        TreeWalk treeWalk = TreeWalk.forPath(repository, arg0, new AnyObjectId[] { commit.getTree() });
        if (treeWalk == null) {
            return false;
        }
        ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1);
        LOGGER.debug("File {} received commit id {} at commit", arg0, objectId.name());
        return !objectId.equals(ObjectId.zeroId());
    } catch (Exception e) {
        throw new ScmException(e);
    }
}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

@Override
public boolean exists(String arg0, CommitRef arg1) {
    try {/*from  w w w. ja  v  a 2s .  c om*/
        AnyObjectId id = repository.resolve(arg1.getStringRepresentation());
        RevCommit commit = new RevWalk(repository).parseCommit(id);
        LOGGER.debug("Looking up file {} in revision {}", arg0, arg1.getStringRepresentation());
        TreeWalk treeWalk = TreeWalk.forPath(repository, arg0, new AnyObjectId[] { commit.getTree() });
        if (treeWalk == null) {
            return false;
        }
        ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1);
        LOGGER.debug("File {} received commit id {} at commit", arg0, objectId.name());
        return !objectId.equals(ObjectId.zeroId());
    } catch (Exception e) {
        throw new ScmException(e);
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.DiffBranches.java

License:Apache License

private List<String> getLines(final ObjectId id, final int fromStart, final int fromEnd) throws IOException {
    List<String> lines = new ArrayList<>();
    if (!id.equals(ObjectId.zeroId())) {
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        final ObjectLoader loader = git.getRepository().open(id);
        loader.copyTo(stream);//from   w w  w  . j  ava  2  s.c  o m
        final String content = stream.toString();
        final List<String> filteredLines = Arrays.asList(content.split("\n"));
        lines = filteredLines.subList(fromStart, fromEnd);
    }
    return lines;
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.SubdirectoryClone.java

License:Apache License

private boolean isDifferentFromParent(final RevWalk revWalk, final CommitBuilder commitBuilder)
        throws MissingObjectException, IncorrectObjectTypeException, IOException {
    final ObjectId parentId = commitBuilder.getParentIds()[0];
    final RevCommit parentCommit = revWalk.parseCommit(parentId);
    final ObjectId parentTreeId = parentCommit.getTree().getId();
    final ObjectId commitTreeId = commitBuilder.getTreeId();
    // A commit with the same tree as its parent has no changes.
    return !commitTreeId.equals(parentTreeId);
}

From source file:pl.project13.jgit.DescribeCommand.java

License:Open Source License

/**
 * Calculates the distance (number of commits) between the given parent and child commits.
 *
 * @return distance (number of commits) between the given commits
 * @see <a href="https://github.com/mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java">mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java</a>
 *///from   w w  w.j  a va2 s. c om
private int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child, @NotNull RevCommit parent) {
    RevWalk revWalk = new RevWalk(repo);

    try {
        revWalk.markStart(child);

        Set<ObjectId> seena = newHashSet();
        Set<ObjectId> seenb = newHashSet();
        Queue<RevCommit> q = newLinkedList();

        q.add(revWalk.parseCommit(child));
        int distance = 0;
        ObjectId parentId = parent.getId();

        while (q.size() > 0) {
            RevCommit commit = q.remove();
            ObjectId commitId = commit.getId();

            if (seena.contains(commitId)) {
                continue;
            }
            seena.add(commitId);

            if (parentId.equals(commitId)) {
                // don't consider commits that are included in this commit
                seeAllParents(revWalk, commit, seenb);
                // remove things we shouldn't have included
                for (ObjectId oid : seenb) {
                    if (seena.contains(oid)) {
                        distance--;
                    }
                }
                seena.addAll(seenb);
                continue;
            }

            for (ObjectId oid : commit.getParents()) {
                if (!seena.contains(oid)) {
                    q.add(revWalk.parseCommit(oid));
                }
            }
            distance++;
        }

        return distance;

    } catch (Exception e) {
        throw new RuntimeException(
                String.format("Unable to calculate distance between [%s] and [%s]", child, parent), e);
    } finally {
        revWalk.dispose();
    }
}

From source file:pl.project13.jgit.JGitCommon.java

License:Open Source License

/**
* Calculates the distance (number of commits) between the given parent and child commits.
*
* @return distance (number of commits) between the given commits
* @see <a href="https://github.com/mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java">mdonoughe/jgit-describe/blob/master/src/org/mdonoughe/JGitDescribeTask.java</a>
*/// w  ww .ja va 2s .  co m
protected int distanceBetween(@NotNull Repository repo, @NotNull RevCommit child, @NotNull RevCommit parent) {
    try (RevWalk revWalk = new RevWalk(repo)) {
        revWalk.markStart(child);

        Set<ObjectId> seena = new HashSet<>();
        Set<ObjectId> seenb = new HashSet<>();
        Queue<RevCommit> q = new ArrayDeque<>();

        q.add(revWalk.parseCommit(child));
        int distance = 0;
        ObjectId parentId = parent.getId();

        while (q.size() > 0) {
            RevCommit commit = q.remove();
            ObjectId commitId = commit.getId();

            if (seena.contains(commitId)) {
                continue;
            }
            seena.add(commitId);

            if (parentId.equals(commitId)) {
                // don't consider commits that are included in this commit
                seeAllParents(revWalk, commit, seenb);
                // remove things we shouldn't have included
                for (ObjectId oid : seenb) {
                    if (seena.contains(oid)) {
                        distance--;
                    }
                }
                seena.addAll(seenb);
                continue;
            }

            for (ObjectId oid : commit.getParents()) {
                if (!seena.contains(oid)) {
                    q.add(revWalk.parseCommit(oid));
                }
            }
            distance++;
        }
        return distance;
    } catch (Exception e) {
        throw new RuntimeException(
                String.format("Unable to calculate distance between [%s] and [%s]", child, parent), e);
    }
}

From source file:playRepository.BareRepository.java

License:Apache License

public static EndingType findFileLineEnding(Repository repository, String fileNameWithPath) throws IOException {
    ObjectId oldObjectId = BareRepository.getFileObjectId(repository, fileNameWithPath);
    if (oldObjectId.equals(ObjectId.zeroId())) {
        return EndingType.UNDEFINED;
    } else {//from  www. ja va2s  . c o  m
        String fileContents = new String(repository.open(oldObjectId).getBytes(), utils.Config.getCharset());
        return findLineEnding(fileContents);
    }
}

From source file:svnserver.repository.git.GitRepository.java

License:GNU General Public License

/**
 * Load all cached revisions./*www . j ava 2s  . co  m*/
 *
 * @throws IOException
 * @throws SVNException
 */
public boolean loadRevisions() throws IOException, SVNException {
    // Fast check.
    lock.readLock().lock();
    try {
        final int lastRevision = revisions.size() - 1;
        final ObjectId lastCommitId;
        if (lastRevision >= 0) {
            lastCommitId = revisions.get(lastRevision).getCacheCommit();
            final Ref head = repository.getRef(svnBranch);
            if (head.getObjectId().equals(lastCommitId)) {
                return false;
            }
        }
    } finally {
        lock.readLock().unlock();
    }
    // Real loading.
    lock.writeLock().lock();
    try {
        final int lastRevision = revisions.size() - 1;
        final ObjectId lastCommitId = lastRevision < 0 ? null : revisions.get(lastRevision).getCacheCommit();
        final Ref head = repository.getRef(svnBranch);
        final List<RevCommit> newRevs = new ArrayList<>();
        final RevWalk revWalk = new RevWalk(repository);
        ObjectId objectId = head.getObjectId();
        while (true) {
            if (objectId.equals(lastCommitId)) {
                break;
            }
            final RevCommit commit = revWalk.parseCommit(objectId);
            newRevs.add(commit);
            if (commit.getParentCount() == 0)
                break;
            objectId = commit.getParent(0);
        }
        if (newRevs.isEmpty()) {
            return false;
        }
        final long beginTime = System.currentTimeMillis();
        int processed = 0;
        long reportTime = beginTime;
        log.info("Loading cached revision changes: {} revision", newRevs.size());
        for (int i = newRevs.size() - 1; i >= 0; i--) {
            loadRevisionInfo(newRevs.get(i));
            processed++;
            long currentTime = System.currentTimeMillis();
            if (currentTime - reportTime > REPORT_DELAY) {
                log.info("  processed cached revision: {} ({} rev/sec)", newRevs.size() - i,
                        1000.0f * processed / (currentTime - reportTime));
                reportTime = currentTime;
                processed = 0;
            }
        }
        final long endTime = System.currentTimeMillis();
        log.info("Cached revision loaded: {} ms", endTime - beginTime);
        return true;
    } finally {
        lock.writeLock().unlock();
    }
}