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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations