/** * Gets all of the changes from the target commit that should be applied to the sparse clone. * * @param commit the commit to get changes from * @return an iterator for changes that match the repository filter */ @Override protected FilteredDiffIterator getFilteredChanges(RevCommit commit) { ObjectId parent = ObjectId.NULL; if (commit.getParentIds().size() > 0) { parent = commit.getParentIds().get(0); } Iterator<DiffEntry> changes = remoteGeoGit .command(DiffOp.class) .setNewVersion(commit.getId()) .setOldVersion(parent) .setReportTrees(true) .call(); return new LocalFilteredDiffIterator( changes, remoteGeoGit.getRepository(), localRepository, filter); }
@Override protected void print(RevCommit commit, Writer w) throws IOException { println(w, "tree\t", commit.getTreeId().toString()); print(w, "parents\t"); for (Iterator<ObjectId> it = commit.getParentIds().iterator(); it.hasNext(); ) { print(w, it.next().toString()); if (it.hasNext()) { print(w, " "); } } println(w); printPerson(w, "author", commit.getAuthor()); printPerson(w, "committer", commit.getCommitter()); println(w, "message\t", Optional.fromNullable(commit.getMessage()).or("")); w.flush(); }
private void writeCSV(GeoGIT geogit, Writer out, Iterator<RevCommit> log) throws Exception { String response = "ChangeType,FeatureId,CommitId,Parent CommitIds,Author Name,Author Email,Author Commit Time,Committer Name,Committer Email,Committer Commit Time,Commit Message"; out.write(response); response = ""; String path = paths.get(0); // This is the feature type object Optional<NodeRef> ref = geogit .command(FindTreeChild.class) .setChildPath(path) .setParent(geogit.getRepository().workingTree().getTree()) .call(); Optional<RevObject> type = Optional.absent(); if (ref.isPresent()) { type = geogit .command(RevObjectParse.class) .setRefSpec(ref.get().getMetadataId().toString()) .call(); } else { throw new CommandSpecException("Couldn't resolve the given path."); } if (type.isPresent() && type.get() instanceof RevFeatureType) { RevFeatureType featureType = (RevFeatureType) type.get(); Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors(); int attributeLength = attribs.size(); for (PropertyDescriptor attrib : attribs) { response += "," + escapeCsv(attrib.getName().toString()); } response += '\n'; out.write(response); response = ""; RevCommit commit = null; while (log.hasNext()) { commit = log.next(); String parentId = commit.getParentIds().size() >= 1 ? commit.getParentIds().get(0).toString() : ObjectId.NULL.toString(); Iterator<DiffEntry> diff = geogit .command(DiffOp.class) .setOldVersion(parentId) .setNewVersion(commit.getId().toString()) .setFilter(path) .call(); while (diff.hasNext()) { DiffEntry entry = diff.next(); response += entry.changeType().toString() + ","; String fid = ""; if (entry.newPath() != null) { if (entry.oldPath() != null) { fid = entry.oldPath() + " -> " + entry.newPath(); } else { fid = entry.newPath(); } } else if (entry.oldPath() != null) { fid = entry.oldPath(); } response += fid + ","; response += commit.getId().toString() + ","; response += parentId; if (commit.getParentIds().size() > 1) { for (int index = 1; index < commit.getParentIds().size(); index++) { response += " " + commit.getParentIds().get(index).toString(); } } response += ","; if (commit.getAuthor().getName().isPresent()) { response += escapeCsv(commit.getAuthor().getName().get()); } response += ","; if (commit.getAuthor().getEmail().isPresent()) { response += escapeCsv(commit.getAuthor().getEmail().get()); } response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z") .format(new Date(commit.getAuthor().getTimestamp())) + ","; if (commit.getCommitter().getName().isPresent()) { response += escapeCsv(commit.getCommitter().getName().get()); } response += ","; if (commit.getCommitter().getEmail().isPresent()) { response += escapeCsv(commit.getCommitter().getEmail().get()); } response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z") .format(new Date(commit.getCommitter().getTimestamp())) + ","; String message = escapeCsv(commit.getMessage()); response += message; if (entry.newObjectId() == ObjectId.NULL) { // Feature was removed so we need to fill out blank attribute values for (int index = 0; index < attributeLength; index++) { response += ","; } } else { // Feature was added or modified so we need to write out the // attribute // values from the feature Optional<RevObject> feature = geogit.command(RevObjectParse.class).setObjectId(entry.newObjectId()).call(); RevFeature revFeature = (RevFeature) feature.get(); List<Optional<Object>> values = revFeature.getValues(); for (int index = 0; index < values.size(); index++) { Optional<Object> value = values.get(index); PropertyDescriptor attrib = (PropertyDescriptor) attribs.toArray()[index]; String stringValue = ""; if (value.isPresent()) { FieldType attributeType = FieldType.forBinding(attrib.getType().getBinding()); switch (attributeType) { case DATE: stringValue = new SimpleDateFormat("MM/dd/yyyy z").format((java.sql.Date) value.get()); break; case DATETIME: stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Date) value.get()); break; case TIME: stringValue = new SimpleDateFormat("HH:mm:ss z").format((Time) value.get()); break; case TIMESTAMP: stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z") .format((Timestamp) value.get()); break; default: stringValue = escapeCsv(value.get().toString()); } response += "," + stringValue; } else { response += ","; } } } response += '\n'; out.write(response); response = ""; } } } else { // Couldn't resolve FeatureType throw new CommandSpecException("Couldn't resolve the given path to a feature type."); } }
/** * This function takes all of the changes introduced by a commit on the sparse repository and * creates a new commit on the full repository with those changes. * * @param commitId the commit id of commit from the sparse repository * @param from the sparse repository * @param to the full repository */ protected void pushSparseCommit(ObjectId commitId) { Repository from = localRepository; Repository to = remoteGeoGit.getRepository(); Optional<RevObject> object = from.command(RevObjectParse.class).setObjectId(commitId).call(); if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) { RevCommit commit = (RevCommit) object.get(); ObjectId parent = ObjectId.NULL; List<ObjectId> newParents = new LinkedList<ObjectId>(); for (int i = 0; i < commit.getParentIds().size(); i++) { ObjectId parentId = commit.getParentIds().get(i); if (i != 0) { Optional<ObjectId> commonAncestor = from.getGraphDatabase() .findLowestCommonAncestor(commit.getParentIds().get(0), parentId); if (commonAncestor.isPresent()) { if (from.getGraphDatabase().isSparsePath(parentId, commonAncestor.get())) { // This should be the base commit to preserve the sparse changes that // were filtered // out. newParents.add(0, from.getGraphDatabase().getMapping(parentId)); continue; } } } newParents.add(from.getGraphDatabase().getMapping(parentId)); } if (newParents.size() > 0) { parent = from.getGraphDatabase().getMapping(newParents.get(0)); } Iterator<DiffEntry> diffIter = from.command(DiffOp.class) .setNewVersion(commitId) .setOldVersion(parent) .setReportTrees(true) .call(); LocalCopyingDiffIterator changes = new LocalCopyingDiffIterator(diffIter, from, to); RevTree rootTree = RevTree.EMPTY; if (newParents.size() > 0) { ObjectId mappedCommit = newParents.get(0); Optional<ObjectId> treeId = to.command(ResolveTreeish.class).setTreeish(mappedCommit).call(); if (treeId.isPresent()) { rootTree = to.getTree(treeId.get()); } } // Create new commit ObjectId newTreeId = to.command(WriteTree.class) .setOldRoot(Suppliers.ofInstance(rootTree)) .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) changes)) .call(); CommitBuilder builder = new CommitBuilder(commit); builder.setParentIds(newParents); builder.setTreeId(newTreeId); RevCommit mapped = builder.build(); to.getObjectDatabase().put(mapped); from.getGraphDatabase().map(commit.getId(), mapped.getId()); from.getGraphDatabase().map(mapped.getId(), commit.getId()); } }
@Override public void print(RevCommit commit) throws IOException { Ansi ansi = AnsiDecorator.newAnsi(useColor); ansi.a("Commit: ").fg(Color.YELLOW).a(getIdAsString(commit.getId())).reset().newline(); if (commit.getParentIds().size() > 1) { ansi.a("Merge: "); for (ObjectId parent : commit.getParentIds()) { ansi.a(parent.toString().substring(0, 7)).a(" "); } ansi.newline(); } ansi.a("Author: ").fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline(); final long timestamp = commit.getAuthor().getTimestamp(); final int timeZoneOffset = commit.getAuthor().getTimeZoneOffset(); String friendlyString = estimateSince(now, timestamp); DATE_FORMAT.getCalendar().getTimeZone().setRawOffset(timeZoneOffset); String formattedDate = DATE_FORMAT.format(timestamp); ansi.a("Date: (") .fg(Color.RED) .a(friendlyString) .reset() .a(") ") .a(formattedDate) .newline(); ansi.a("Subject: ").a(commit.getMessage()).newline(); if ((detail.equals(LOG_DETAIL.NAMES_ONLY)) && commit.getParentIds().size() == 1) { ansi.a("Affected paths:").newline(); Iterator<DiffEntry> diff = geogit .command(DiffOp.class) .setOldVersion(commit.parentN(0).get()) .setNewVersion(commit.getId()) .call(); DiffEntry diffEntry; while (diff.hasNext()) { diffEntry = diff.next(); ansi.a("\t" + diffEntry.newPath()).newline(); } } if (detail.equals(LOG_DETAIL.STATS) && commit.getParentIds().size() == 1) { Iterator<DiffEntry> diff = geogit .command(DiffOp.class) .setOldVersion(commit.parentN(0).get()) .setNewVersion(commit.getId()) .call(); int adds = 0, deletes = 0, changes = 0; DiffEntry diffEntry; while (diff.hasNext()) { diffEntry = diff.next(); switch (diffEntry.changeType()) { case ADDED: ++adds; break; case REMOVED: ++deletes; break; case MODIFIED: ++changes; break; } } ansi.a("Changes:"); ansi.fg(Color.GREEN) .a(adds) .reset() .a(" features added, ") .fg(Color.YELLOW) .a(changes) .reset() .a(" changed, ") .fg(Color.RED) .a(deletes) .reset() .a(" deleted.") .reset() .newline(); } console.println(ansi.toString()); if (detail.equals(LOG_DETAIL.SUMMARY) && commit.getParentIds().size() == 1) { ansi.a("Changes:").newline(); Iterator<DiffEntry> diff = geogit .command(DiffOp.class) .setOldVersion(commit.parentN(0).get()) .setNewVersion(commit.getId()) .call(); DiffEntry diffEntry; while (diff.hasNext()) { diffEntry = diff.next(); if (detail.equals(LOG_DETAIL.SUMMARY)) { new FullDiffPrinter(true, false).print(geogit, console, diffEntry); } } } }