List of usage examples for org.eclipse.jgit.lib FileMode equals
@SuppressWarnings("NonOverridingEquals") public abstract boolean equals(int modebits);
From source file:MyDiffFormatter.java
License:Eclipse Distribution License
private void formatHeader(ByteArrayOutputStream o, DiffEntry ent) throws IOException { final ChangeType type = ent.getChangeType(); final String oldp = ent.getOldPath(); final String newp = ent.getNewPath(); final FileMode oldMode = ent.getOldMode(); final FileMode newMode = ent.getNewMode(); formatGitDiffFirstHeaderLine(o, type, oldp, newp); if ((type == MODIFY || type == COPY || type == RENAME) && !oldMode.equals(newMode)) { o.write(encodeASCII("old mode ")); //$NON-NLS-1$ oldMode.copyTo(o);// ww w.jav a 2s. c om o.write('\n'); o.write(encodeASCII("new mode ")); //$NON-NLS-1$ newMode.copyTo(o); o.write('\n'); } switch (type) { case ADD: o.write(encodeASCII("new file mode ")); //$NON-NLS-1$ newMode.copyTo(o); o.write('\n'); break; case DELETE: o.write(encodeASCII("deleted file mode ")); //$NON-NLS-1$ oldMode.copyTo(o); o.write('\n'); break; case RENAME: o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$ o.write('\n'); o.write(encode("rename from " + quotePath(oldp))); //$NON-NLS-1$ o.write('\n'); o.write(encode("rename to " + quotePath(newp))); //$NON-NLS-1$ o.write('\n'); break; case COPY: o.write(encodeASCII("similarity index " + ent.getScore() + "%")); //$NON-NLS-1$ //$NON-NLS-2$ o.write('\n'); o.write(encode("copy from " + quotePath(oldp))); //$NON-NLS-1$ o.write('\n'); o.write(encode("copy to " + quotePath(newp))); //$NON-NLS-1$ o.write('\n'); break; case MODIFY: if (0 < ent.getScore()) { o.write(encodeASCII("dissimilarity index " //$NON-NLS-1$ + (100 - ent.getScore()) + "%")); //$NON-NLS-1$ o.write('\n'); } break; } if (ent.getOldId() != null && !ent.getOldId().equals(ent.getNewId())) { formatIndexLine(o, ent); } }
From source file:com.buildautomation.jgit.api.GetFileAttributes.java
License:Apache License
private static String getFileMode(FileMode fileMode) { if (fileMode.equals(FileMode.EXECUTABLE_FILE)) { return "Executable File"; } else if (fileMode.equals(FileMode.REGULAR_FILE)) { return "Normal File"; } else if (fileMode.equals(FileMode.TREE)) { return "Directory"; } else if (fileMode.equals(FileMode.SYMLINK)) { return "Symlink"; } else {//w w w . jav a 2 s . co m // there are a few others, see FileMode javadoc for details throw new IllegalArgumentException("Unknown type of file encountered: " + fileMode); } }
From source file:eu.trentorise.opendata.josman.Josmans.java
License:Open Source License
/** * Returns a string representation of the provided git file mode *//* www .j a v a2s . c om*/ static String gitFileModeToString(FileMode fileMode) { if (fileMode.equals(FileMode.EXECUTABLE_FILE)) { return "Executable File"; } else if (fileMode.equals(FileMode.REGULAR_FILE)) { return "Normal File"; } else if (fileMode.equals(FileMode.TREE)) { return "Directory"; } else if (fileMode.equals(FileMode.SYMLINK)) { return "Symlink"; } else if (fileMode.equals(FileMode.GITLINK)) { return "submodule link"; } else { return fileMode.toString(); } }
From source file:org.eclipse.egit.ui.internal.history.FileDiff.java
License:Open Source License
private void outputEclipseDiff(final StringBuilder d, final Repository db, final ObjectReader reader, final DiffFormatter diffFmt) throws IOException { if (!(getBlobs().length == 2)) throw new UnsupportedOperationException( "Not supported yet if the number of parents is different from one"); //$NON-NLS-1$ String projectRelativePath = getProjectRelativePath(db, getPath()); d.append("diff --git ").append(projectRelativePath).append(" ") //$NON-NLS-1$ //$NON-NLS-2$ .append(projectRelativePath).append("\n"); //$NON-NLS-1$ final ObjectId id1 = getBlobs()[0]; final ObjectId id2 = getBlobs()[1]; final FileMode mode1 = getModes()[0]; final FileMode mode2 = getModes()[1]; if (id1.equals(ObjectId.zeroId())) { d.append("new file mode " + mode2).append("\n"); //$NON-NLS-1$//$NON-NLS-2$ } else if (id2.equals(ObjectId.zeroId())) { d.append("deleted file mode " + mode1).append("\n"); //$NON-NLS-1$//$NON-NLS-2$ } else if (!mode1.equals(mode2)) { d.append("old mode " + mode1); //$NON-NLS-1$ d.append("new mode " + mode2).append("\n"); //$NON-NLS-1$//$NON-NLS-2$ }//from w w w . ja va2 s.com d.append("index ").append(reader.abbreviate(id1).name()). //$NON-NLS-1$ append("..").append(reader.abbreviate(id2).name()). //$NON-NLS-1$ append(mode1.equals(mode2) ? " " + mode1 : "").append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (id1.equals(ObjectId.zeroId())) d.append("--- /dev/null\n"); //$NON-NLS-1$ else { d.append("--- "); //$NON-NLS-1$ d.append(getProjectRelativePath(db, getPath())); d.append("\n"); //$NON-NLS-1$ } if (id2.equals(ObjectId.zeroId())) d.append("+++ /dev/null\n"); //$NON-NLS-1$ else { d.append("+++ "); //$NON-NLS-1$ d.append(getProjectRelativePath(db, getPath())); d.append("\n"); //$NON-NLS-1$ } final RawText a = getRawText(id1, reader); final RawText b = getRawText(id2, reader); EditList editList = MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b); diffFmt.format(editList, a, b); }
From source file:org.eclipse.orion.server.gerritfs.GerritListFile.java
License:Open Source License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { handleAuth(req);//from w w w .j a va2s . co m resp.setCharacterEncoding("UTF-8"); final PrintWriter out = resp.getWriter(); try { String pathInfo = req.getPathInfo(); Pattern pattern = Pattern.compile("/([^/]*)(?:/([^/]*)(?:/(.*))?)?"); Matcher matcher = pattern.matcher(pathInfo); matcher.matches(); String projectName = null; String refName = null; String filePath = null; if (matcher.groupCount() > 0) { projectName = matcher.group(1); refName = matcher.group(2); filePath = matcher.group(3); if (projectName == null || projectName.equals("")) { projectName = null; } else { projectName = java.net.URLDecoder.decode(projectName, "UTF-8"); } if (refName == null || refName.equals("")) { refName = null; } else { refName = java.net.URLDecoder.decode(refName, "UTF-8"); } if (filePath == null || filePath.equals("")) { filePath = null; } else { filePath = java.net.URLDecoder.decode(filePath, "UTF-8"); } } if (projectName != null) { if (filePath == null) filePath = ""; NameKey projName = NameKey.parse(projectName); ProjectControl control; try { control = projControlFactory.controlFor(projName); if (!control.isVisible()) { log.debug("Project not visible!"); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "You need to be logged in to see private projects"); return; } } catch (NoSuchProjectException e1) { } Repository repo = repoManager.openRepository(projName); if (refName == null) { ArrayList<HashMap<String, Object>> contents = new ArrayList<HashMap<String, Object>>(); List<Ref> call; try { call = new Git(repo).branchList().call(); Git git = new Git(repo); for (Ref ref : call) { HashMap<String, Object> jsonObject = new HashMap<String, Object>(); jsonObject.put("name", ref.getName()); jsonObject.put("type", "ref"); jsonObject.put("size", "0"); jsonObject.put("path", ""); jsonObject.put("project", projectName); jsonObject.put("ref", ref.getName()); lastCommit(git, null, ref.getObjectId(), jsonObject); contents.add(jsonObject); } String response = JSONUtil.write(contents); resp.setContentType("application/json"); resp.setHeader("Cache-Control", "no-cache"); resp.setHeader("ETag", "W/\"" + response.length() + "-" + response.hashCode() + "\""); log.debug(response); out.write(response); } catch (GitAPIException e) { } } else { Ref head = repo.getRef(refName); if (head == null) { ArrayList<HashMap<String, String>> contents = new ArrayList<HashMap<String, String>>(); String response = JSONUtil.write(contents); resp.setContentType("application/json"); resp.setHeader("Cache-Control", "no-cache"); resp.setHeader("ETag", "W/\"" + response.length() + "-" + response.hashCode() + "\""); log.debug(response); out.write(response); return; } RevWalk walk = new RevWalk(repo); // add try catch to catch failures Git git = new Git(repo); RevCommit commit = walk.parseCommit(head.getObjectId()); RevTree tree = commit.getTree(); TreeWalk treeWalk = new TreeWalk(repo); treeWalk.addTree(tree); treeWalk.setRecursive(false); if (!filePath.equals("")) { PathFilter pathFilter = PathFilter.create(filePath); treeWalk.setFilter(pathFilter); } if (!treeWalk.next()) { CanonicalTreeParser canonicalTreeParser = treeWalk.getTree(0, CanonicalTreeParser.class); ArrayList<HashMap<String, Object>> contents = new ArrayList<HashMap<String, Object>>(); if (canonicalTreeParser != null) { while (!canonicalTreeParser.eof()) { String path = canonicalTreeParser.getEntryPathString(); FileMode mode = canonicalTreeParser.getEntryFileMode(); listEntry(path, mode.equals(FileMode.TREE) ? "dir" : "file", "0", path, projectName, head.getName(), git, contents); canonicalTreeParser.next(); } } String response = JSONUtil.write(contents); resp.setContentType("application/json"); resp.setHeader("Cache-Control", "no-cache"); resp.setHeader("ETag", "\"" + tree.getId().getName() + "\""); log.debug(response); out.write(response); } else { // if (treeWalk.isSubtree()) { // treeWalk.enterSubtree(); // } ArrayList<HashMap<String, Object>> contents = new ArrayList<HashMap<String, Object>>(); do { if (treeWalk.isSubtree()) { String test = new String(treeWalk.getRawPath()); if (test.length() /*treeWalk.getPathLength()*/ > filePath.length()) { listEntry(treeWalk.getNameString(), "dir", "0", treeWalk.getPathString(), projectName, head.getName(), git, contents); } if (test.length() /*treeWalk.getPathLength()*/ <= filePath.length()) { treeWalk.enterSubtree(); } } else { ObjectId objId = treeWalk.getObjectId(0); ObjectLoader loader = repo.open(objId); long size = loader.getSize(); listEntry(treeWalk.getNameString(), "file", Long.toString(size), treeWalk.getPathString(), projectName, head.getName(), git, contents); } } while (treeWalk.next()); String response = JSONUtil.write(contents); resp.setContentType("application/json"); resp.setHeader("Cache-Control", "no-cache"); resp.setHeader("ETag", "\"" + tree.getId().getName() + "\""); log.debug(response); out.write(response); } walk.release(); treeWalk.release(); } } } finally { out.close(); } }
From source file:org.kuali.student.git.model.tree.utils.GitTreeProcessor.java
License:Educational Community License
public GitTreeNodeData extractExistingTreeData(ObjectId treeId, String name) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { GitTreeNodeData treeData = new GitTreeNodeData(nodeInitializer, name); treeData.setGitTreeObjectId(treeId); TreeWalk tw = new TreeWalk(repo); tw.setRecursive(false);// ww w . jav a 2s. c o m tw.addTree(treeId); while (tw.next()) { FileMode fileMode = tw.getFileMode(0); String entryName = tw.getNameString(); ObjectId objectId = tw.getObjectId(0); if (fileMode.equals(FileMode.TREE)) { GitTreeNodeData subTree = new GitTreeNodeData(nodeInitializer, entryName); subTree.setGitTreeObjectId(objectId); treeData.addDirectTree(entryName, subTree); } else if (fileMode.equals(FileMode.REGULAR_FILE)) { treeData.addDirectBlob(entryName, objectId); } } /* * This tree is initialized the subtree's are not. */ treeData.setInitialized(true); treeData.setDirty(false); tw.release(); return treeData; }
From source file:org.kuali.student.svn.model.TestExternalsFusion.java
License:Educational Community License
private void checkTrees(ObjectId originalAggregateId, ObjectId aggregateId) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevWalk rw = new RevWalk(repo); RevCommit originalAggregateCommit = rw.parseCommit(originalAggregateId); RevCommit aggregateCommit = rw.parseCommit(aggregateId); TreeWalk tw = new TreeWalk(repo); tw.addTree(originalAggregateCommit.getTree().getId()); tw.addTree(aggregateCommit.getTree().getId()); tw.setRecursive(false);/*from w w w. j a v a 2 s.co m*/ while (tw.next()) { FileMode originalMode = tw.getFileMode(0); FileMode fileMode = tw.getFileMode(1); if (originalMode.equals(FileMode.TYPE_MISSING) || fileMode.equals(FileMode.TYPE_MISSING)) continue; // skip where one side or the other does not exist. String name = tw.getNameString(); ObjectId originalObjectId = tw.getObjectId(0); ObjectId currentObjectId = tw.getObjectId(1); Assert.assertTrue(originalObjectId + " is not equals to " + currentObjectId + " for " + name, originalObjectId.equals(currentObjectId)); } tw.release(); rw.release(); }
From source file:org.uberfire.java.nio.fs.jgit.util.model.PathInfo.java
License:Apache License
private static PathType convert(final FileMode fileMode) { if (fileMode.equals(FileMode.TYPE_TREE)) { return PathType.DIRECTORY; } else if (fileMode.equals(TYPE_FILE)) { return PathType.FILE; }/* www . jav a 2 s . com*/ return null; }
From source file:svnserver.repository.git.GitFileTreeEntry.java
License:GNU General Public License
@NotNull @Override//from w ww .j a va 2s .com public Map<String, String> getProperties() throws IOException, SVNException { final Map<String, String> props = getUpstreamProperties(); final FileMode fileMode = getFileMode(); if (fileMode.equals(FileMode.SYMLINK)) { props.remove(SVNProperty.EOL_STYLE); props.remove(SVNProperty.MIME_TYPE); props.put(SVNProperty.SPECIAL, "*"); } else { if (fileMode.equals(FileMode.EXECUTABLE_FILE)) { props.put(SVNProperty.EXECUTABLE, "*"); } if (fileMode.getObjectType() == Constants.OBJ_BLOB && repo.isObjectBinary(filter, getObjectId())) { props.remove(SVNProperty.EOL_STYLE); props.put(SVNProperty.MIME_TYPE, SVNFileUtil.BINARY_MIME_TYPE); } } return props; }