private JsonObject createFetchMessage(List<ObjectId> want, Set<ObjectId> have) { JsonObject message = new JsonObject(); JsonArray wantArray = new JsonArray(); for (ObjectId id : want) { wantArray.add(new JsonPrimitive(id.toString())); } JsonArray haveArray = new JsonArray(); for (ObjectId id : have) { haveArray.add(new JsonPrimitive(id.toString())); } message.add("want", wantArray); message.add("have", haveArray); return message; }
/** * Push all new objects from the specified {@link Ref} to the remote. * * @param ref the local ref that points to new commit data * @param refspec the remote branch to push to */ @Override public void pushNewData(Ref ref, String refspec, ProgressListener progress) throws SynchronizationException { Optional<Ref> remoteRef = HttpUtils.getRemoteRef(repositoryURL, refspec); checkPush(ref, remoteRef); beginPush(); progress.setDescription("Uploading objects to " + refspec); progress.setProgress(0); CommitTraverser traverser = getPushTraverser(remoteRef); traverser.traverse(ref.getObjectId()); List<ObjectId> toSend = new LinkedList<ObjectId>(traverser.commits); Collections.reverse(toSend); Set<ObjectId> have = new HashSet<ObjectId>(traverser.have); Deduplicator deduplicator = deduplicationService.createDeduplicator(); try { sendPackedObjects(toSend, have, deduplicator, progress); } finally { deduplicator.release(); } ObjectId originalRemoteRefValue = ObjectId.NULL; if (remoteRef.isPresent()) { originalRemoteRefValue = remoteRef.get().getObjectId(); } String nameToSet = remoteRef.isPresent() ? remoteRef.get().getName() : Ref.HEADS_PREFIX + refspec; endPush(nameToSet, ref.getObjectId(), originalRemoteRefValue.toString()); }
private Optional<NodeRef> parseID(ObjectId commitId, String path, GeoGIG geogig) { Optional<RevObject> object = geogig.command(RevObjectParse.class).setObjectId(commitId).call(); RevCommit commit = null; if (object.isPresent() && object.get() instanceof RevCommit) { commit = (RevCommit) object.get(); } else { throw new CommandSpecException( "Couldn't resolve id: " + commitId.toString() + " to a commit"); } object = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(); if (object.isPresent()) { RevTree tree = (RevTree) object.get(); return geogig.command(FindTreeChild.class).setParent(tree).setChildPath(path).call(); } else { throw new CommandSpecException("Couldn't resolve commit's treeId"); } }
public void print(RevCommit commit) throws IOException { StringBuilder sb = new StringBuilder(); sb.append("commit ").append(commit.getId().toString()).append('\n'); sb.append("tree ").append(commit.getTreeId().toString()).append('\n'); sb.append("parent"); for (ObjectId parentId : commit.getParentIds()) { sb.append(' ').append(parentId.toString()); } sb.append('\n'); sb.append("author ").append(format(commit.getAuthor())).append('\n'); sb.append("committer ").append(format(commit.getCommitter())).append('\n'); if (commit.getMessage() != null) { sb.append("message\n"); sb.append("\t" + commit.getMessage().replace("\n", "\n\t")); sb.append('\n'); } if (showChanges) { Iterator<DiffEntry> diff = geogig .command(DiffOp.class) .setOldVersion(commit.parentN(0).or(ObjectId.NULL)) .setNewVersion(commit.getId()) .call(); DiffEntry diffEntry; sb.append("changes\n"); while (diff.hasNext()) { diffEntry = diff.next(); String path = diffEntry.newPath() != null ? diffEntry.newPath() : diffEntry.oldPath(); sb.append('\t') .append(path) .append(' ') .append(diffEntry.oldObjectId().toString()) .append(' ') .append(diffEntry.newObjectId().toString()) .append('\n'); } } console.println(sb.toString()); }