List of usage examples for org.eclipse.jgit.lib Constants OBJ_TREE
int OBJ_TREE
To view the source code for org.eclipse.jgit.lib Constants OBJ_TREE.
Click Source Link
From source file:com.google.gerrit.sshd.commands.CreateProject.java
License:Apache License
private void createEmptyCommit(final Repository repo, final Project.NameKey project, final String ref) throws IOException { ObjectInserter oi = repo.newObjectInserter(); try {/*from www. j av a 2 s . c om*/ CommitBuilder cb = new CommitBuilder(); cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {})); cb.setAuthor(metaDataUpdateFactory.getUserPersonIdent()); cb.setCommitter(serverIdent); cb.setMessage("Initial empty repository\n"); ObjectId id = oi.insert(cb); oi.flush(); RefUpdate ru = repo.updateRef(Constants.HEAD); ru.setNewObjectId(id); final Result result = ru.update(); switch (result) { case NEW: rq.scheduleUpdate(project, ref); break; default: { throw new IOException(result.name()); } } } catch (IOException e) { log.error("Cannot create empty commit for " + projectName, e); throw e; } finally { oi.release(); } }
From source file:com.netbeetle.reboot.git.CachedRepository.java
License:Apache License
public ObjectId lookupTree(ObjectId tree, String path) throws IOException { TreeWalk treeWalk = TreeWalk.forPath(repository, path, tree); if (treeWalk == null) { return null; }//from w w w . j av a 2 s . c o m try { FileMode fileMode = treeWalk.getFileMode(0); if (fileMode.getObjectType() != Constants.OBJ_TREE) { return null; } return treeWalk.getObjectId(0); } finally { treeWalk.release(); } }
From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java
License:Open Source License
private static TreeWalk getTreeOnPath(MutableObjectId id, Repository repo, ObjectId rev, String path) throws MissingObjectException, IOException { RevTree tree = new RevWalk(repo).parseTree(rev); TreeWalk tw = new TreeWalk(repo); tw.reset(tree);/* www .j av a 2 s . com*/ tw.setRecursive(false); if (path == null || path.isEmpty() || "/".equals(path)) { id.fromObjectId(tree.getId()); return tw; } PathFilter f = PathFilter.create(path); tw.setFilter(f); while (tw.next()) { if (f.isDone(tw)) { id.fromObjectId(tw.getObjectId(0)); if (tw.isSubtree()) { tw.enterSubtree(); return tw; } else { throw new MissingObjectException(tw.getObjectId(0), Constants.OBJ_TREE); } } else if (tw.isSubtree()) { tw.enterSubtree(); } } return null; }
From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java
License:Open Source License
private static Item.Type getType(int type) { switch (type) { case Constants.OBJ_BLOB: return Item.Type.BLOB; case Constants.OBJ_TREE: return Item.Type.TREE; case Constants.OBJ_COMMIT: return Item.Type.COMMIT; // XXX add more default:// w w w . j a va 2 s . co m return null; } }
From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java
License:Open Source License
private static String getEmptyPath(Repository r, ObjectId id) throws IOException { TreeWalk treeWalk = new TreeWalk(r); treeWalk.addTree(new RevWalk(r).parseTree(id)); String path = null;/*w ww . j av a 2s. c om*/ // Find tree of interrest it has to be alone there ObjectId iId = null; String iPath = null; while (treeWalk.next()) { if (iId == null) { iId = treeWalk.getObjectId(0); iPath = treeWalk.getPathString(); } else { iId = null; break; } } if (iId != null) { ObjectLoader loader = r.open(iId); if (loader.getType() == Constants.OBJ_TREE) { // It is alone there and it is a folder path = "/" + iPath; String sep = getEmptyPath(r, iId); if (sep != null) { path = path + sep; } } } return path; }
From source file:edu.nju.cs.inform.jgit.unfinished.BrowseTree.java
License:Apache License
public static void main(String[] args) throws IOException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { ObjectId revId = repository.resolve(Constants.HEAD); try (TreeWalk treeWalk = new TreeWalk(repository)) { try (RevWalk revWalk = new RevWalk(repository)) { treeWalk.addTree(revWalk.parseTree(revId)); while (treeWalk.next()) { System.out.println("---------------------------"); System.out.append("name: ").println(treeWalk.getNameString()); System.out.append("path: ").println(treeWalk.getPathString()); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.append("directory: ").println(loader.getType() == Constants.OBJ_TREE); System.out.append("size: ").println(loader.getSize()); }//w w w .j ava2 s .c om } } } }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void process(final ObjectId id) throws TransportException { final RevObject obj; try {//from ww w . j a v a 2s.c om if (id instanceof RevObject) { obj = (RevObject) id; if (obj.has(COMPLETE)) return; revWalk.parseHeaders(obj); } else { obj = revWalk.parseAny(id); if (obj.has(COMPLETE)) return; } } catch (IOException e) { throw new TransportException(MessageFormat.format(JGitText.get().cannotRead, id.name()), e); } switch (obj.getType()) { case Constants.OBJ_BLOB: processBlob(obj); break; case Constants.OBJ_TREE: processTree(obj); break; case Constants.OBJ_COMMIT: processCommit(obj); break; case Constants.OBJ_TAG: processTag(obj); break; default: throw new TransportException(MessageFormat.format(JGitText.get().unknownObjectType, id.name())); } // If we had any prior errors fetching this object they are // now resolved, as the object was parsed successfully. // fetchErrors.remove(id); }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void processTree(final RevObject obj) throws TransportException { try {/*from w w w. jav a2 s. c o m*/ treeWalk.reset(obj); while (treeWalk.next()) { final FileMode mode = treeWalk.getFileMode(0); final int sType = mode.getObjectType(); switch (sType) { case Constants.OBJ_BLOB: case Constants.OBJ_TREE: treeWalk.getObjectId(idBuffer, 0); needs(revWalk.lookupAny(idBuffer, sType)); continue; default: if (FileMode.GITLINK.equals(mode)) continue; treeWalk.getObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.format(JGitText.get().invalidModeFor, mode, idBuffer.name(), treeWalk.getPathString(), obj.getId().name())); } } } catch (IOException ioe) { throw new TransportException(MessageFormat.format(JGitText.get().cannotReadTree, obj.name()), ioe); } obj.add(COMPLETE); }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void markLocalObjComplete(RevObject obj) throws IOException { while (obj.getType() == Constants.OBJ_TAG) { obj.add(COMPLETE);/*from w w w .j a v a 2 s . c o m*/ obj = ((RevTag) obj).getObject(); revWalk.parseHeaders(obj); } switch (obj.getType()) { case Constants.OBJ_BLOB: obj.add(COMPLETE); break; case Constants.OBJ_COMMIT: pushLocalCommit((RevCommit) obj); break; case Constants.OBJ_TREE: markTreeComplete((RevTree) obj); break; } }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void markTreeComplete(final RevTree tree) throws IOException { if (tree.has(COMPLETE)) return;/* w w w . j a va 2 s . c om*/ tree.add(COMPLETE); treeWalk.reset(tree); while (treeWalk.next()) { final FileMode mode = treeWalk.getFileMode(0); final int sType = mode.getObjectType(); switch (sType) { case Constants.OBJ_BLOB: treeWalk.getObjectId(idBuffer, 0); revWalk.lookupAny(idBuffer, sType).add(COMPLETE); continue; case Constants.OBJ_TREE: { treeWalk.getObjectId(idBuffer, 0); final RevObject o = revWalk.lookupAny(idBuffer, sType); if (!o.has(COMPLETE)) { o.add(COMPLETE); treeWalk.enterSubtree(); } continue; } default: if (FileMode.GITLINK.equals(mode)) continue; treeWalk.getObjectId(idBuffer, 0); throw new CorruptObjectException(MessageFormat.format(JGitText.get().corruptObjectInvalidMode3, mode, idBuffer.name(), treeWalk.getPathString(), tree.name())); } } }