@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(commits.size() == 2, "Two commit references must be provided"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object."); checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit"); Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object."); checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit"); Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class) .setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call(); checkParameter(ancestor.isPresent(), "No common ancestor was found."); console.print(ancestor.get().toString()); }
private @Nullable ObjectId findShallowestCommonAncestor(ObjectId tip, Set<ObjectId> otherTips) { ObjectDatabase localdb = objectDatabase(); Set<ObjectId> commonAncestors = new HashSet<>(); for (ObjectId remoteTip : otherTips) { if (!commonAncestors.contains(remoteTip) && localdb.exists(remoteTip)) { Optional<ObjectId> commonAncestor = command(FindCommonAncestor.class).setLeftId(tip) .setRightId(remoteTip).call(); if (commonAncestor.isPresent()) { commonAncestors.add(commonAncestor.get()); } } } int depth = Integer.MAX_VALUE; ObjectId shallowestCommonAncestor = null; for (ObjectId ca : commonAncestors) { int depthTo = depthTo(tip, ca); if (depthTo < depth) { shallowestCommonAncestor = ca; depth = depthTo; } } return shallowestCommonAncestor; }
private ObjectId findCommonAncestor(PR pr, Ref targetBranch) { Ref issuerBranch; ObjectId commonAncestor; final Repository issuerRepo = pr.openRemote(); try { issuerBranch = pr.resolveRemoteBranch(issuerRepo); commonAncestor = command(FindCommonAncestor.class)// .setLeftId(targetBranch.getObjectId())// .setLeftSource(graphDatabase())// .setRightId(issuerBranch.getObjectId())// .setRightSource(issuerRepo.graphDatabase())// .call().orNull(); } finally { issuerRepo.close(); } checkArgument(commonAncestor != null, "Local branch %s and remote %s do not have a common ancestor", pr.getTargetBranch(), issuerBranch.getName()); return commonAncestor; }
return Boolean.FALSE; Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(commits.get(0)) .setRight(commits.get(1)).call(); Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found."); for (int i = 2; i < commits.size(); i++) { ancestor = command(FindCommonAncestor.class).setLeft(commits.get(i)) .setRightId(ancestor.get()).call(); Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found.");
.setLeft(headCommit).setRight(targetCommit) .setProgressListener(subProgress(10.f)).call();
return Boolean.FALSE; Optional<ObjectId> ancestor = command(FindCommonAncestor.class).setLeft(commits.get(0)) .setRight(commits.get(1)).call(); Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found."); for (int i = 2; i < commits.size(); i++) { ancestor = command(FindCommonAncestor.class).setLeft(commits.get(i)) .setRightId(ancestor.get()).call(); Preconditions.checkState(ancestor.isPresent(), "No ancestor commit could be found.");
.setLeft(headCommit).setRight(targetCommit) .setProgressListener(subProgress(10.f)).call();
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(commits.size() == 2, "Two commit references must be provided"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object."); checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit"); Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object."); checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit"); Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class) .setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call(); checkParameter(ancestor.isPresent(), "No common ancestor was found."); console.print(ancestor.get().toString()); }
private @Nullable ObjectId findShallowestCommonAncestor(ObjectId tip, Set<ObjectId> otherTips) { ObjectDatabase localdb = objectDatabase(); Set<ObjectId> commonAncestors = new HashSet<>(); for (ObjectId remoteTip : otherTips) { if (!commonAncestors.contains(remoteTip) && localdb.exists(remoteTip)) { Optional<ObjectId> commonAncestor = command(FindCommonAncestor.class).setLeftId(tip) .setRightId(remoteTip).call(); if (commonAncestor.isPresent()) { commonAncestors.add(commonAncestor.get()); } } } int depth = Integer.MAX_VALUE; ObjectId shallowestCommonAncestor = null; for (ObjectId ca : commonAncestors) { int depthTo = depthTo(tip, ca); if (depthTo < depth) { shallowestCommonAncestor = ca; depth = depthTo; } } return shallowestCommonAncestor; }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(commits.size() == 2, "Two commit references must be provided"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object."); checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit"); Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object."); checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit"); Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class) .setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call(); checkParameter(ancestor.isPresent(), "No common ancestor was found."); console.print(ancestor.get().toString()); }
.setLeftId(lastCommit.getId()).setRightId(oldestCommitId).call(); if (ancestor.isPresent()) { stopPoints.add(ancestor.get());
private void printRefspecs(Conflict conflict, Console console, GeoGIG geogig) throws IOException { ObjectId theirsHeadId = getTheirsHeadId(); Optional<RevCommit> theirsHead = geogig.command(RevObjectParse.class) .setObjectId(theirsHeadId).call(RevCommit.class); ObjectId oursHeadId = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get() .getObjectId(); Optional<RevCommit> oursHead = geogig.command(RevObjectParse.class).setObjectId(oursHeadId) .call(RevCommit.class); Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class) .setLeft(theirsHead.get()).setRight(oursHead.get()).call(); String ancestorPath = commonAncestor.get().toString() + ":" + conflict.getPath(); StringBuilder sb = new StringBuilder(); sb.append(conflict.getPath()); sb.append(" "); sb.append(ancestorPath); sb.append(" "); sb.append(oursHeadId.toString() + ":" + conflict.getPath()); sb.append(" "); sb.append(theirsHeadId.toString() + ":" + conflict.getPath()); console.println(sb.toString()); }
.setLeftId(lastCommit.getId()).setRightId(oldestCommitId).call(); if (ancestor.isPresent()) { stopPoints.add(ancestor.get());
private void printRefspecs(Conflict conflict, Console console, GeoGIG geogig) throws IOException { ObjectId theirsHeadId = getTheirsHeadId(); Optional<RevCommit> theirsHead = geogig.command(RevObjectParse.class) .setObjectId(theirsHeadId).call(RevCommit.class); ObjectId oursHeadId = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get() .getObjectId(); Optional<RevCommit> oursHead = geogig.command(RevObjectParse.class).setObjectId(oursHeadId) .call(RevCommit.class); Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class) .setLeft(theirsHead.get()).setRight(oursHead.get()).call(); String ancestorPath = commonAncestor.get().toString() + ":" + conflict.getPath(); StringBuilder sb = new StringBuilder(); sb.append(conflict.getPath()); sb.append(" "); sb.append(ancestorPath); sb.append(" "); sb.append(oursHeadId.toString() + ":" + conflict.getPath()); sb.append(" "); sb.append(theirsHeadId.toString() + ":" + conflict.getPath()); console.println(sb.toString()); }
} else if (local.blobExists(remoteObjectId)) { Optional<ObjectId> ancestor = local.command(FindCommonAncestor.class) .setLeftId(remoteObjectId).setRightId(localObjectId).call(); if (!ancestor.isPresent()) {
private void printRefspecs(Conflict conflict, Console console, GeoGIG geogig) throws IOException { ObjectId theirsHeadId = getTheirsHeadId(); Optional<RevCommit> theirsHead = geogig.command(RevObjectParse.class) .setObjectId(theirsHeadId).call(RevCommit.class); ObjectId oursHeadId = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call().get() .getObjectId(); Optional<RevCommit> oursHead = geogig.command(RevObjectParse.class).setObjectId(oursHeadId) .call(RevCommit.class); Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class) .setLeft(theirsHead.get()).setRight(oursHead.get()).call(); String ancestorPath = commonAncestor.get().toString() + ":" + conflict.getPath(); StringBuilder sb = new StringBuilder(); sb.append(conflict.getPath()); sb.append(" "); sb.append(ancestorPath); sb.append(" "); sb.append(oursHeadId.toString() + ":" + conflict.getPath()); sb.append(" "); sb.append(theirsHeadId.toString() + ":" + conflict.getPath()); console.println(sb.toString()); }
} else if (local.blobExists(remoteObjectId)) { Optional<ObjectId> ancestor = local.command(FindCommonAncestor.class) .setLeftId(remoteObjectId).setRightId(localObjectId).call(); if (!ancestor.isPresent()) {
@Override protected MergeScenarioReport _call() { if (consumer == null) { consumer = new MergeScenarioConsumer(); } final Optional<ObjectId> ancestorOpt = command(FindCommonAncestor.class).setLeft(toMerge) .setRight(mergeInto).call(); Preconditions.checkState(ancestorOpt.isPresent(), "No ancestor commit could be found."); final ObjectId ancestor = ancestorOpt.get(); MergeScenarioReport report = null; try (AutoCloseableIterator<DiffEntry> mergeIntoDiffs = command(DiffTree.class) .setOldTree(ancestor).setReportTrees(true).setNewTree(mergeInto.getId()) .setPreserveIterationOrder(true).call(); AutoCloseableIterator<DiffEntry> toMergeDiffs = command(DiffTree.class) .setOldTree(ancestor).setReportTrees(true).setNewTree(toMerge.getId()) .setPreserveIterationOrder(true).call();) { Iterator<MergeDiffRef> tupleIterator = new MergeDiffIterator(mergeIntoDiffs, toMergeDiffs); final RevCommit ancestorCommit = objectDatabase().getCommit(ancestor); final RevTree ancestorTree = objectDatabase().getTree(ancestorCommit.getTreeId()); report = process(tupleIterator, ancestorTree); } return report; }
} else if (local.blobExists(mappedId)) { Optional<ObjectId> ancestor = local.command(FindCommonAncestor.class) .setLeftId(mappedId).setRightId(ref.getObjectId()).call(); if (!ancestor.isPresent()) {
@Override protected MergeScenarioReport _call() { if (consumer == null) { consumer = new MergeScenarioConsumer(); } final Optional<ObjectId> ancestorOpt = command(FindCommonAncestor.class).setLeft(toMerge) .setRight(mergeInto).call(); Preconditions.checkState(ancestorOpt.isPresent(), "No ancestor commit could be found."); final ObjectId ancestor = ancestorOpt.get(); MergeScenarioReport report = null; try (AutoCloseableIterator<DiffEntry> mergeIntoDiffs = command(DiffTree.class) .setOldTree(ancestor).setReportTrees(true).setNewTree(mergeInto.getId()) .setPreserveIterationOrder(true).call(); AutoCloseableIterator<DiffEntry> toMergeDiffs = command(DiffTree.class) .setOldTree(ancestor).setReportTrees(true).setNewTree(toMerge.getId()) .setPreserveIterationOrder(true).call();) { Iterator<MergeDiffRef> tupleIterator = new MergeDiffIterator(mergeIntoDiffs, toMergeDiffs); final RevCommit ancestorCommit = objectDatabase().getCommit(ancestor); final RevTree ancestorTree = objectDatabase().getTree(ancestorCommit.getTreeId()); report = process(tupleIterator, ancestorTree); } return report; }