File repoDir = new File("test-git/.git"); // open the repository Repository repo = new Repository(repoDir); // find the HEAD Commit head = repo.mapCommit(Constants.HEAD); // retrieve the tree in HEAD Tree tree = head.getTree(); // 1.2.0 api version here // find a file (as a TreeEntry, which contains the blob object id) TreeWalk treewalk = TreeWalk.forPath(repo, "b/test.txt", tree); // use the blob id to read the file's data byte[] data = repo.open(treewalk.getObjectId(0)).getBytes();
File repoDir = new File("test-git/.git"); // open the repository Repository repo = new Repository(repoDir); // find the HEAD Commit head = repo.mapCommit(Constants.HEAD); // retrieve the tree in HEAD Tree tree = head.getTree(); // find a file (as a TreeEntry, which contains the blob object id) TreeEntry entry = tree.findBlobMember("b/test.txt"); // use the blob id to read the file's data byte[] data = repo.openBlob(entry.getId()).getBytes();
params.put("parents", parentIds); //$NON-NLS-1$ Tree tree = commit.getTree(); if (tree != null) params.put("tree", tree.getSha()); //$NON-NLS-1$
if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) baseTree = currentTree.getSha();
if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) baseTree = currentTree.getSha();
Tree currentTree = ref != null ? service.getCommit(repository, ref.getObject().getSha()).getTree() : null; String baseTree = null; if (currentTree != null)
/** * Saves a commit object into the data * * there are some critical elements of information that are no longer * saved in the v3 api vs v2. Namely the date of the commit and the * parents of the commit. * * @param commit * @return */ public Vertex saveCommit(final Commit commit) { log.trace("saveCommit: enter"); Vertex node = getOrCreateCommit(commit.getSha()); if (commit.getAuthor() != null) { Vertex author = saveUser(commit.getAuthor()); createEdgeIfNotExist(node, author, EdgeType.COMMITAUTHOR); setProperty(node, PropertyName.AUTHORED_DATE, commit.getAuthor().getDate()); } if (commit.getCommitter() != null) { Vertex committer = saveUser(commit.getCommitter()); createEdgeIfNotExist(node, committer, EdgeType.COMMITTER); setProperty(node, PropertyName.COMMITTED_DATE, commit.getCommitter().getDate()); } setProperty(node, PropertyName.COMMIT_ID, commit.getSha()); setProperty(node, PropertyName.MESSAGE, commit.getMessage()); setProperty(node, PropertyName.TREE, commit.getTree()); setProperty(node, PropertyName.URL, commit.getUrl()); log.trace("saveCommit: exit"); return node; }