Delete commented code

Leave working examples of using Git
This commit is contained in:
Paul Campbell 2018-05-31 23:38:54 +01:00
parent 5ffdb0f895
commit 1098cd2e21
2 changed files with 108 additions and 201 deletions

View file

@ -27,9 +27,7 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import java.nio.file.Path; import java.nio.file.Path;
public interface GitDB public interface GitDB {
// extends Closeable
{
/** /**
* Initialise a new local gitdb. * Initialise a new local gitdb.
@ -43,42 +41,4 @@ public interface GitDB
return new GitDBLocal(git); return new GitDBLocal(git);
} }
// /**
// * Open an existing local gitdb.
// *
// * @param dbDir the path to the local repo
// * @return a GitDB instance for the local gitdb
// */
// static GitDB local(final Path dbDir) throws IOException {
// return new GitDBLocal(Git.open(dbDir.toFile()));
// }
// /**
// * Select a branch.
// *
// * @param branch the branch to select
// * @return a branch within the gitdb
// */
// GitDbBranch branch(Branch branch);
// interface GitDbBranch {
// String get(Key key);
//
// <T> T get(Key key, Class<T> type);
//
// Key put(Message message, Document<String> document, Author author);
//
// GitDbBranch delete(Branch branch, Key key, Message message, Author author);
//
// GitDbBranch tag(Reference reference);
//
// Transaction startTransaction(Branch branch);
//
// GitDbBranch fork(Branch branch);
// }
// Stream<Branch> allBranches();
} }

View file

@ -29,166 +29,113 @@ class GitDBLocal implements GitDB {
private final Git git; private final Git git;
// @Override // @Override
// public void close() { // @SneakyThrows
// git.close(); // public <T> T get(Branch branch, Key key, Class<T> type) {
// } // //branch
// final RefDatabase refDatabase = repository.getRefDatabase();
// final String branchValue = branch.getValue();
// final Ref refDatabaseRef = refDatabase.getRef(branchValue);
// final ObjectId commitId = refDatabaseRef.getObjectId();
//
// final RevCommit revCommit = repository.parseCommit(commitId);
// final RevTree tree = revCommit.getTree();
// tree.copyTo(System.out);
//
// final ObjectLoader open = repository.getObjectDatabase().open(objectId, Constants.OBJ_TREE);
// final byte[] bytes = open.getBytes();
// final String s = new String(bytes);
// System.out.println("s = " + s);
// //key
// return null;
// }
// @Override // @Override
// public GitDbBranch branch(Branch branch) { // @SneakyThrows
// return null; // public String put(Branch branch, Message message, Document<String> document, Author author) {
// } //// return document.getValue();
// //
// @Override // final ObjectInserter objectInserter = repository.newObjectInserter();
// public Stream<Branch> allBranches() { // final ObjectReader objectReader = repository.newObjectReader();
// return null; // final RevWalk revWalk = new RevWalk(repository);
// } //
// //blob
// @Override // System.out.println("document = " + document.getKey());
// public String get(Branch branch, Key key) { // final ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, document.getValue().getBytes(UTF_8));
// return get(branch, key, String.class); // //tree
// } // final TreeFormatter treeFormatter = new TreeFormatter();
// // treeFormatter.append(document.getKey().getValue(), FileMode.REGULAR_FILE, blobId);
// @Override // final ObjectId treeId = objectInserter.insert(treeFormatter);
// @SneakyThrows // //commit
// public <T> T get(Branch branch, Key key, Class<T> type) { // final CommitBuilder commitBuilder = new CommitBuilder();
//branch // final PersonIdent ident = new PersonIdent(author.getName(), author.getEmail());
// final RefDatabase refDatabase = repository.getRefDatabase(); // commitBuilder.setCommitter(ident);
// final String branchValue = branch.getValue(); // commitBuilder.setAuthor(ident);
// final Ref refDatabaseRef = refDatabase.getRef(branchValue); // commitBuilder.setTreeId(treeId);
// final ObjectId commitId = refDatabaseRef.getObjectId(); // commitBuilder.setMessage(message.getValue());
// // //TODO: setParentId()
// final RevCommit revCommit = repository.parseCommit(commitId); // final ObjectId commitId = objectInserter.insert(commitBuilder);
// final RevTree tree = revCommit.getTree(); // //branch
// tree.copyTo(System.out); // final RevCommit revCommit = revWalk.parseCommit(commitId);
// // revCommit.getShortMessage();
// final ObjectLoader open = repository.getObjectDatabase().open(objectId, Constants.OBJ_TREE); // git.branchCreate()
// final byte[] bytes = open.getBytes(); // .setStartPoint(revCommit)
// final String s = new String(bytes); // .setName(branch.getValue())
// System.out.println("s = " + s); // .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK)
// //key // .call();
// return null; //
// } // //READ
//
// @Override // //block
// @SneakyThrows // final String readBlob = new String(objectReader.open(blobId).getBytes());
// public String put(Branch branch, Message message, Document<String> document, Author author) { // System.out.println("readBlob = " + readBlob);
//// return document.getValue(); // final RevBlob revBlob = revWalk.lookupBlob(blobId);
// // System.out.println("revBlob = " + revBlob);
// final ObjectInserter objectInserter = repository.newObjectInserter(); // final String blobName = revBlob.name();
// final ObjectReader objectReader = repository.newObjectReader(); // System.out.println("blobName = " + blobName);
// final RevWalk revWalk = new RevWalk(repository); // //tree
// // final RevTree revTree = revWalk.lookupTree(treeId);
// //blob // System.out.println("revTree = " + revTree);
// System.out.println("document = " + document.getKey()); // final String treeName = revTree.name();
// final ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, document.getValue().getBytes(UTF_8)); // System.out.println("treeName = " + treeName);
// //tree // //commit
// final TreeFormatter treeFormatter = new TreeFormatter(); // System.out.println("revCommit= " + revCommit);
// treeFormatter.append(document.getKey().getValue(), FileMode.REGULAR_FILE, blobId); // final String commitName = revCommit.getName();
// final ObjectId treeId = objectInserter.insert(treeFormatter); // System.out.println("commitName= " + commitName);
// //commit // //branch
// final CommitBuilder commitBuilder = new CommitBuilder(); // final Ref branchRef = repository.getRefDatabase().getRef(branch.getValue());
// final PersonIdent ident = new PersonIdent(author.getName(), author.getEmail()); // System.out.println("branchRef = " + branchRef.getName());
// commitBuilder.setCommitter(ident); //
// commitBuilder.setAuthor(ident); //// final TreeWalk treeWalk = new TreeWalk(repository);
// commitBuilder.setTreeId(treeId); //// treeWalk.addTree(treeId);
// commitBuilder.setMessage(message.getValue()); //// treeWalk.next();
// //TODO: setParentId() //// final String nameString = treeWalk.getNameString();
// final ObjectId commitId = objectInserter.insert(commitBuilder); //// System.out.println("name = " + nameString);
// //branch //// final ObjectId objectId = treeWalk.getObjectId(0);
// final RevCommit revCommit = revWalk.parseCommit(commitId); //// System.out.println("objectId = " + objectId);
// revCommit.getShortMessage(); //
// git.branchCreate() //// final ObjectLoader openTree = repository.newObjectReader().open(treeId);
// .setStartPoint(revCommit) //// final int type = openTree.openStream().getType();
// .setName(branch.getValue()) //// final long size = openTree.openStream().getSize();
// .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.NOTRACK) //// final String readTree = new String(openTree.getBytes());
// .call(); //
// ////
// //READ //// //commit
// //// final CommitBuilder commitBuilder = new CommitBuilder();
// //block //// commitBuilder.setAuthor(new PersonIdent(author.getName(), author.getEmail()));
// final String readBlob = new String(objectReader.open(blobId).getBytes()); //// commitBuilder.setCommitter(new PersonIdent(author.getName(), author.getEmail()));
// System.out.println("readBlob = " + readBlob); //// commitBuilder.setMessage(message.getValue());
// final RevBlob revBlob = revWalk.lookupBlob(blobId); //// findParentCommit(branch)
// System.out.println("revBlob = " + revBlob); //// .ifPresent(commitBuilder::setParentId);
// final String blobName = revBlob.name(); //// commitBuilder.setTreeId(treeId);
// System.out.println("blobName = " + blobName); //// final ObjectId commitId = repository.newObjectInserter().insert(commitBuilder);
// //tree ////
// final RevTree revTree = revWalk.lookupTree(treeId); //// //branch
// System.out.println("revTree = " + revTree); //// repository.updateRef(branch.getValue()).setNewObjectId(commitId);
// final String treeName = revTree.name(); ////
// System.out.println("treeName = " + treeName); //// //get
// //commit //// return get(branch, document.getKey());
// System.out.println("revCommit= " + revCommit); // return document.getValue();
// final String commitName = revCommit.getName(); // }
// System.out.println("commitName= " + commitName);
// //branch
// final Ref branchRef = repository.getRefDatabase().getRef(branch.getValue());
// System.out.println("branchRef = " + branchRef.getName());
//
//// final TreeWalk treeWalk = new TreeWalk(repository);
//// treeWalk.addTree(treeId);
//// treeWalk.next();
//// final String nameString = treeWalk.getNameString();
//// System.out.println("name = " + nameString);
//// final ObjectId objectId = treeWalk.getObjectId(0);
//// System.out.println("objectId = " + objectId);
//
//// final ObjectLoader openTree = repository.newObjectReader().open(treeId);
//// final int type = openTree.openStream().getType();
//// final long size = openTree.openStream().getSize();
//// final String readTree = new String(openTree.getBytes());
//
////
//// //commit
//// final CommitBuilder commitBuilder = new CommitBuilder();
//// commitBuilder.setAuthor(new PersonIdent(author.getName(), author.getEmail()));
//// commitBuilder.setCommitter(new PersonIdent(author.getName(), author.getEmail()));
//// commitBuilder.setMessage(message.getValue());
//// findParentCommit(branch)
//// .ifPresent(commitBuilder::setParentId);
//// commitBuilder.setTreeId(treeId);
//// final ObjectId commitId = repository.newObjectInserter().insert(commitBuilder);
////
//// //branch
//// repository.updateRef(branch.getValue()).setNewObjectId(commitId);
////
//// //get
//// return get(branch, document.getKey());
// return document.getValue();
// }
// @SneakyThrows
// private Optional<ObjectId> findParentCommit(final Branch branch) {
// return Optional.ofNullable(
// repository.getRefDatabase()
// .getRef(branch.getValue()))
// .map(Ref::getObjectId);
// }
// @Override
// public String delete(Branch branch, Key key, Message message, Author author) {
// return null;
// }
//
// @Override
// public void tag(Reference reference) {
//
// }
//
// @Override
// public void createBranch(Reference reference) {
//
// }
//
// @Override
// public Stream<String> getAllBranches() {
// return null;
// }
//
// @Override
// public Transaction createTransaction(Branch branch) {
// return null;
// }
} }