Search in sources :

Example 96 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project orgzly-android by orgzly.

the class GitRepo method retrieveBook.

@Override
public VersionedRook retrieveBook(String fileName, File destination) throws IOException {
    // public VersionedRook retrieveBook(Uri sourceUri, File destinationFile)
    // FIXME: Interface changed, this will not work
    Uri sourceUri = Uri.parse(fileName);
    // FIXME: Removed current_versioned_rooks table, just get the list from remote
    // VersionedRook current = CurrentRooksClient.get(App.getAppContext(), getUri().toString(), sourceUri.toString());
    VersionedRook current = null;
    RevCommit currentCommit = null;
    if (current != null) {
        currentCommit = getCommitFromRevisionString(current.getRevision());
    }
    // synchronizer.checkoutSelected();
    try {
        currentCommit = synchronizer.getLatestCommitOfFile(Uri.parse(fileName));
    } catch (GitAPIException ex) {
        throw new IOException("Error while retrieving latest commit of " + fileName, ex);
    }
    // TODO: What if we  can't merge here? Can that not happen?
    synchronizer.mergeWithRemote();
    synchronizer.tryPushIfUpdated(currentCommit);
    synchronizer.safelyRetrieveLatestVersionOfFile(sourceUri.getPath(), destination, currentCommit);
    return currentVersionedRook(sourceUri);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) Uri(android.net.Uri) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 97 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project orgzly-android by orgzly.

the class GitFileSynchronizer method mergeWithRemote.

public boolean mergeWithRemote() throws IOException {
    ensureRepoIsClean();
    try {
        fetch();
        RevCommit mergeTarget = getCommit(String.format("%s/%s", preferences.remoteName(), git.getRepository().getBranch()));
        return doMerge(mergeTarget);
    } catch (GitAPIException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 98 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project orgzly-android by orgzly.

the class GitFileSynchronizer method safelyRetrieveLatestVersionOfFile.

public void safelyRetrieveLatestVersionOfFile(String repositoryPath, File destination, RevCommit revision) throws IOException {
    RevWalk revWalk = new RevWalk(git.getRepository());
    RevCommit head = currentHead();
    RevCommit rHead = revWalk.parseCommit(head.toObjectId());
    RevCommit rRevision = revWalk.parseCommit(revision.toObjectId());
    if (!revWalk.isMergedInto(rRevision, rHead)) {
        throw new IOException(String.format("The provided revision %s is not merged in to the current HEAD, %s.", revision, head));
    }
    retrieveLatestVersionOfFile(repositoryPath, destination);
}
Also used : IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 99 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project jphp by jphp-compiler.

the class WrapGit method resolveCommit.

@Signature
public Memory resolveCommit(String revstr) throws IOException, GitAPIException {
    ObjectId objectId = getWrappedObject().getRepository().resolve(revstr);
    if (objectId == null) {
        return Memory.NULL;
    }
    LogCommand command = getWrappedObject().log().add(objectId).setMaxCount(1);
    Iterable<RevCommit> call = command.call();
    for (RevCommit revCommit : call) {
        return GitUtils.valueOf(revCommit);
    }
    return Memory.NULL;
}
Also used : RevCommit(org.eclipse.jgit.revwalk.RevCommit) Signature(php.runtime.annotation.Reflection.Signature)

Example 100 with RevCommit

use of org.eclipse.jgit.revwalk.RevCommit in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelLoader method restoreProblemObjects.

/**
 * Find the problem object xml files from the commit history and restore them
 * @param unresolvedObjects
 * @return
 * @throws IOException
 */
private IArchimateModel restoreProblemObjects(List<UnresolvedObject> unresolvedObjects) throws IOException {
    fRestoredObjects = new ArrayList<IIdentifier>();
    List<String> restoredIdentifiers = new ArrayList<String>();
    try (Repository repository = Git.open(fRepository.getLocalRepositoryFolder()).getRepository()) {
        try (RevWalk revWalk = new RevWalk(repository)) {
            for (UnresolvedObject unresolved : unresolvedObjects) {
                String missingFileName = unresolved.missingObjectURI.lastSegment();
                String missingObjectID = unresolved.missingObjectURI.fragment();
                // Already got this one
                if (restoredIdentifiers.contains(missingObjectID)) {
                    continue;
                }
                boolean found = false;
                // Reset RevWalk
                revWalk.reset();
                ObjectId id = repository.resolve(IGraficoConstants.HEAD);
                if (id != null) {
                    revWalk.markStart(revWalk.parseCommit(id));
                }
                // Iterate all commits
                for (RevCommit commit : revWalk) {
                    try (TreeWalk treeWalk = new TreeWalk(repository)) {
                        treeWalk.addTree(commit.getTree());
                        treeWalk.setRecursive(true);
                        // We can't use a PathFilter for the file name as its path is not correct
                        while (!found && treeWalk.next()) {
                            // File is found
                            if (treeWalk.getPathString().endsWith(missingFileName)) {
                                // Save file
                                ObjectId objectId = treeWalk.getObjectId(0);
                                ObjectLoader loader = repository.open(objectId);
                                File file = new File(fRepository.getLocalRepositoryFolder(), treeWalk.getPathString());
                                file.getParentFile().mkdirs();
                                try (FileOutputStream out = new FileOutputStream(file)) {
                                    loader.copyTo(out);
                                }
                                restoredIdentifiers.add(missingObjectID);
                                found = true;
                            }
                        }
                    }
                    if (found) {
                        break;
                    }
                }
            }
            revWalk.dispose();
        }
    }
    // Then re-import
    GraficoModelImporter importer = new GraficoModelImporter(fRepository.getLocalRepositoryFolder());
    IArchimateModel graficoModel = importer.importAsModel();
    // do this again
    graficoModel.setFile(fRepository.getTempModelFile());
    // Collect restored objects
    for (Iterator<EObject> iter = graficoModel.eAllContents(); iter.hasNext(); ) {
        EObject element = iter.next();
        for (String id : restoredIdentifiers) {
            if (element instanceof IIdentifier && id.equals(((IIdentifier) element).getId())) {
                fRestoredObjects.add((IIdentifier) element);
            }
        }
    }
    return graficoModel;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) UnresolvedObject(org.archicontribs.modelrepository.grafico.GraficoModelImporter.UnresolvedObject) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) FileOutputStream(java.io.FileOutputStream) EObject(org.eclipse.emf.ecore.EObject) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RevCommit (org.eclipse.jgit.revwalk.RevCommit)1302 Test (org.junit.Test)650 RevWalk (org.eclipse.jgit.revwalk.RevWalk)333 ObjectId (org.eclipse.jgit.lib.ObjectId)295 Repository (org.eclipse.jgit.lib.Repository)273 IOException (java.io.IOException)222 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)190 Ref (org.eclipse.jgit.lib.Ref)174 File (java.io.File)134 ArrayList (java.util.ArrayList)134 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)133 Git (org.eclipse.jgit.api.Git)133 PersonIdent (org.eclipse.jgit.lib.PersonIdent)105 Change (com.google.gerrit.entities.Change)87 TestRepository (org.eclipse.jgit.junit.TestRepository)72 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)70 ObjectReader (org.eclipse.jgit.lib.ObjectReader)64 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)61 List (java.util.List)61 HashMap (java.util.HashMap)57