List of usage examples for org.eclipse.jgit.lib FileMode getObjectType
public int getObjectType()
From source file:com.buildautomation.jgit.api.GetFileAttributes.java
License:Apache License
private static void printFile(Repository repository, RevTree tree) throws IOException { // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree);//from w ww .ja va 2 s. c o m treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("README.md")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit // set FileMode fileMode = treeWalk.getFileMode(0); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode + " size: " + loader.getSize()); } }
From source file:com.buildautomation.jgit.api.GetFileAttributes.java
License:Apache License
private static void printDirectory(Repository repository, RevTree tree) throws IOException { // look at directory, this has FileMode.TREE try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree);// w w w . j av a 2 s . c o m treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("src")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } // FileMode now indicates that this is a directory, i.e. FileMode.TREE.equals(fileMode) holds true FileMode fileMode = treeWalk.getFileMode(0); System.out.println("src: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode); } }
From source file:com.google.gitiles.TreeJsonData.java
License:Open Source License
static Tree toJsonData(ObjectId id, TreeWalk tw) throws IOException { Tree tree = new Tree(); tree.id = id.name();//from ww w . jav a 2s .c om tree.entries = Lists.newArrayList(); while (tw.next()) { Entry e = new Entry(); FileMode mode = tw.getFileMode(0); e.mode = mode.getBits(); e.type = Constants.typeString(mode.getObjectType()); e.id = tw.getObjectId(0).name(); e.name = tw.getNameString(); tree.entries.add(e); } return tree; }
From source file:com.madgag.agit.diff.LineContextDiffer.java
License:Open Source License
private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException { if (mode == FileMode.MISSING) return new byte[] {}; if (mode.getObjectType() != Constants.OBJ_BLOB) return new byte[] {}; if (!id.isComplete()) { Collection<ObjectId> ids = reader.resolve(id); if (ids.size() == 1) id = AbbreviatedObjectId.fromObjectId(ids.iterator().next()); else if (ids.size() == 0) throw new MissingObjectException(id, Constants.OBJ_BLOB); else//from w w w. j av a2 s . c o m throw new AmbiguousObjectException(id, ids); } ObjectLoader ldr = reader.open(id.toObjectId()); return ldr.getCachedBytes(bigFileThreshold); }
From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareRmCommand.java
/** * Executes the {@code Rm} command. Each instance of this class should only * be used for one invocation of the command. Don't call this method twice * on an instance.//from w w w . j av a2 s.c o m * * @return the DirCache after Rm */ public DirCache call() throws GitAPIException, NoFilepatternException { if (filepatterns.isEmpty()) { throw new NoFilepatternException(JGitText.get().atLeastOnePatternIsRequired); } checkCallable(); try (final TreeWalk tw = new TreeWalk(repo)) { index.lock(); DirCacheBuilder builder = index.builder(); tw.reset(); // drop the first empty tree, which we do not need here tw.setRecursive(true); tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); tw.addTree(new DirCacheBuildIterator(builder)); while (tw.next()) { if (!cached) { final FileMode mode = tw.getFileMode(0); if (mode.getObjectType() == Constants.OBJ_BLOB) { final File path = new File(repo.getWorkTree(), tw.getPathString()); // Deleting a blob is simply a matter of removing // the file or symlink named by the tree entry. delete(path); } } } builder.commit(); setCallable(false); } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfRmCommand, e); } finally { if (index != null) { index.unlock(); } } return index; }
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; }/* www.ja v 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.netbeetle.reboot.git.CachedRepository.java
License:Apache License
public ObjectId lookupBlob(ObjectId tree, String path) throws IOException { TreeWalk treeWalk = TreeWalk.forPath(repository, path, tree); if (treeWalk == null) { return null; }/*from ww w.j av a2s . com*/ try { FileMode fileMode = treeWalk.getFileMode(0); if (fileMode.getObjectType() != Constants.OBJ_BLOB || (fileMode != FileMode.REGULAR_FILE && fileMode != FileMode.EXECUTABLE_FILE)) { return null; } return treeWalk.getObjectId(0); } finally { treeWalk.release(); } }
From source file:com.nexus.git.GetFileAttributes.java
License:Apache License
private static void printFile(Repository repository, RevTree tree) throws IOException { // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree);//from ww w .jav a 2 s . co m treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("README.md")); // if (!treeWalk.next()) { // throw new IllegalStateException("Did not find expected file // 'README.md'"); // } // FileMode specifies the type of file, FileMode.REGULAR_FILE for // normal file, FileMode.EXECUTABLE_FILE for executable bit // set FileMode fileMode = treeWalk.getFileMode(0); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode + " size: " + loader.getSize()); } }
From source file:com.nexus.git.GetFileAttributes.java
License:Apache License
private static void printDirectory(Repository repository, RevTree tree) throws IOException { // look at directory, this has FileMode.TREE try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree);// w w w. ja v a 2 s . c o m treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("src")); // if (!treeWalk.next()) { // throw new IllegalStateException("Did not find expected file // 'README.md'"); // } // FileMode now indicates that this is a directory, i.e. // FileMode.TREE.equals(fileMode) holds true FileMode fileMode = treeWalk.getFileMode(0); System.out.println("src: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode); } }
From source file:edu.nju.cs.inform.jgit.api.GetFileAttributes.java
License:Apache License
private static void printFile(Repository repository, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { // now try to find a specific file try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.addTree(tree);// w w w . j a va 2 s. c o m treeWalk.setRecursive(false); treeWalk.setFilter(PathFilter.create("README.md")); if (!treeWalk.next()) { throw new IllegalStateException("Did not find expected file 'README.md'"); } // FileMode specifies the type of file, FileMode.REGULAR_FILE for normal file, FileMode.EXECUTABLE_FILE for executable bit // set FileMode fileMode = treeWalk.getFileMode(0); ObjectLoader loader = repository.open(treeWalk.getObjectId(0)); System.out.println("README.md: " + getFileMode(fileMode) + ", type: " + fileMode.getObjectType() + ", mode: " + fileMode + " size: " + loader.getSize()); } }