@Override public void putEntry(ZipOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) throws IOException { // loader is null for directories... if (loader != null) { ZipEntry entry = new ZipEntry(path); if (tree instanceof RevCommit) { long t = ((RevCommit) tree).getCommitTime() * 1000L; entry.setTime(t); } out.putNextEntry(entry); out.write(loader.getBytes()); out.closeEntry(); } }
/** * Returns a path model of the current file in the treewalk. * * @param tw * @param basePath * @param commit * @return a path model of the current file in the treewalk */ private static PathModel getPathModel(TreeWalk tw, String basePath, RevCommit commit) { String name; long size = 0; if (StringUtils.isEmpty(basePath)) { name = tw.getPathString(); } else { name = tw.getPathString().substring(basePath.length() + 1); } ObjectId objectId = tw.getObjectId(0); try { if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) { size = tw.getObjectReader().getObjectSize(objectId, Constants.OBJ_BLOB); } } catch (Throwable t) { error(t, null, "failed to retrieve blob size for " + tw.getPathString()); } return new PathModel(name, tw.getPathString(), size, tw.getFileMode(0).getBits(), objectId.getName(), commit.getName()); }
/** * Returns a path model by path string * * @param repo * @param path * @param filter * @param commit * @return a path model of the specified object */ private static PathModel getPathModel(Repository repo, String path, String filter, RevCommit commit) throws IOException { long size = 0; try (TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree())) { String pathString = path; if (!tw.isSubtree() && (tw.getFileMode(0) != FileMode.GITLINK)) { size = tw.getObjectReader().getObjectSize(tw.getObjectId(0), Constants.OBJ_BLOB); pathString = PathUtils.getLastPathComponent(pathString); } else if (tw.isSubtree()) { // do not display dirs that are behind in the path if (!Strings.isNullOrEmpty(filter)) { pathString = path.replaceFirst(filter + "/", ""); } // remove the last slash from path in displayed link if (pathString != null && pathString.charAt(pathString.length() - 1) == '/') { pathString = pathString.substring(0, pathString.length() - 1); } } return new PathModel(pathString, tw.getPathString(), size, tw.getFileMode(0).getBits(), tw.getObjectId(0).getName(), commit.getName()); } }
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) { String commitId = null; try (TreeWalk tw = new TreeWalk(repository)) { tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path))); tw.reset(commit.getTree()); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } if (FileMode.GITLINK == tw.getFileMode(0)) { commitId = tw.getObjectId(0).getName(); break; } } } catch (Throwable t) { error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name()); } return commitId; }
@NotNull @Override 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; }
@Nullable @Override public GitProperty createForChild(@NotNull String name, @NotNull FileMode fileMode) { if (matchers.isEmpty() || (fileMode.getObjectType() == Constants.OBJ_BLOB)) { return null; } final List<String> localList = new ArrayList<>(); final List<String> globalList = new ArrayList<>(); final List<PathMatcher> childMatchers = new ArrayList<>(); for (PathMatcher matcher : matchers) { processMatcher(localList, globalList, childMatchers, matcher.createChild(name, true)); } if (localList.isEmpty() && globalList.isEmpty() && childMatchers.isEmpty()) { return null; } return new GitIgnore(localList, globalList, childMatchers); }
private void checkProps(@NotNull GitProperty[] gitProperties, @Nullable String local, @Nullable String global, @Nullable String mine, @NotNull FileMode fileMode, @NotNull String... path) { GitProperty[] props = gitProperties; for (int i = 0; i < path.length; ++i) { final String name = path[i]; final FileMode mode = i == path.length - 1 ? fileMode : FileMode.TREE; props = createForChild(props, name, mode); } final Map<String, String> text = new HashMap<>(); for (GitProperty prop : props) { prop.apply(text); } Assert.assertEquals(text.remove("svn:eol-style"), local); Assert.assertEquals(text.remove("svn:auto-props"), global); Assert.assertEquals(text.remove("svn:mime-type"), mine); Assert.assertTrue(text.isEmpty(), text.toString()); }
public static String getSubmoduleCommitId(Repository repository, String path, RevCommit commit) { String commitId = null; RevWalk rw = new RevWalk(repository); TreeWalk tw = new TreeWalk(repository); tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path))); try { tw.reset(commit.getTree()); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } if (FileMode.GITLINK == tw.getFileMode(0)) { commitId = tw.getObjectId(0).getName(); break; } } } catch (Throwable t) { error(t, repository, "{0} can't find {1} in commit {2}", path, commit.name()); } finally { rw.dispose(); tw.release(); } return commitId; }
public void checkoutEntry (Repository repository, File file, DirCacheEntry e, ObjectReader od) throws IOException, GitException { // ... create/overwrite this file ... if (!ensureParentFolderExists(file.getParentFile())) { return; } boolean exists = file.exists(); if (exists && e.getFileMode() == FileMode.SYMLINK) { monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_SymLink"), file.getAbsolutePath())); //NOI18N return; } if (Utils.isFromNested(e.getFileMode().getBits())) { if (!exists) { file.mkdirs(); } } else { if (exists && file.isDirectory()) { monitor.notifyWarning(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_ReplacingDirectory"), file.getAbsolutePath())); //NOI18N Utils.deleteRecursively(file); } file.createNewFile(); if (file.isFile()) { DirCacheCheckout.checkoutEntry(repository, file, e, od); } else { monitor.notifyError(MessageFormat.format(Utils.getBundle(CheckoutIndex.class).getString("MSG_Warning_CannotCreateFile"), file.getAbsolutePath())); //NOI18N } } }
public void testAddMissingSymlink () throws Exception { if (isWindows()) { return; } String path = "folder/file"; File f = new File(workDir, path); // try with commandline client File link = new File(workDir, "link"); Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(path)); getClient(workDir).add(new File[] { link }, NULL_PROGRESS_MONITOR); DirCacheEntry e = repository.readDirCache().getEntry(link.getName()); assertEquals(FileMode.SYMLINK, e.getFileMode()); assertEquals(0, e.getLength()); ObjectReader reader = repository.getObjectDatabase().newReader(); assertTrue(reader.has(e.getObjectId())); byte[] bytes = reader.open(e.getObjectId()).getBytes(); assertEquals(path, RawParseUtils.decode(bytes)); reader.release(); }
public QuickSearchPanel(String id, IModel<Project> projectModel, IModel<String> revisionModel) { super(id); this.projectModel = projectModel; this.revisionModel = revisionModel; Project project = projectModel.getObject(); for (String blobPath: getRecentOpened()) { try { RevTree revTree = project.getRevCommit(revisionModel.getObject()).getTree(); TreeWalk treeWalk = TreeWalk.forPath(project.getRepository(), blobPath, revTree); if (treeWalk != null && treeWalk.getRawMode(0) != FileMode.TREE.getBits()) { symbolHits.add(new FileHit(blobPath, null)); } } catch (IOException e) { throw new RuntimeException(e); } } }
public Map<String, String> getSubmodules(String revision) { Map<String, String> submodules = new HashMap<>(); Blob blob = getBlob(new BlobIdent(revision, ".gitmodules", FileMode.REGULAR_FILE.getBits())); String content = new String(blob.getBytes()); String path = null; String url = null; for (String line: LoaderUtils.splitAndTrim(content, "\r\n")) { if (line.startsWith("[") && line.endsWith("]")) { if (path != null && url != null) submodules.put(path, url); path = url = null; } else if (line.startsWith("path")) { path = StringUtils.substringAfter(line, "=").trim(); } else if (line.startsWith("url")) { url = StringUtils.substringAfter(line, "=").trim(); } } if (path != null && url != null) submodules.put(path, url); return submodules; }
public int getMode(String revision, @Nullable String path) { if (path != null) { RevCommit commit = getRevCommit(revision); try { TreeWalk treeWalk = TreeWalk.forPath(getRepository(), path, commit.getTree()); if (treeWalk != null) { return treeWalk.getRawMode(0); } else { throw new ObjectNotFoundException("Unable to find blob path '" + path + "' in revision '" + revision + "'"); } } catch (IOException e) { throw new RuntimeException(e); } } else { return FileMode.TREE.getBits(); } }
@Test public void shouldFailIfOldPathIsTreeWhenRename() throws IOException { createDir("client"); addFileAndCommit("client/a.java", "a", "add a"); addFileAndCommit("client/b.java", "b", "add b"); createDir("server/src/com/example/a"); createDir("server/src/com/example/b"); addFileAndCommit("server/src/com/example/a/a.java", "a", "add a"); addFileAndCommit("server/src/com/example/b/b.java", "b", "add b"); String refName = "refs/heads/master"; ObjectId oldCommitId = git.getRepository().resolve(refName); Map<String, BlobContent> newBlobs = new HashMap<>(); newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE)); BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a"), newBlobs); ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename"); try (RevWalk revWalk = new RevWalk(git.getRepository())) { RevTree revTree = revWalk.parseCommit(newCommitId).getTree(); assertNotNull(TreeWalk.forPath(git.getRepository(), "client/c.java", revTree)); assertNull(TreeWalk.forPath(git.getRepository(), "server/src/com/example/a", revTree)); } }
@Test public void shouldFailIfNewPathIsNotUnderTreeWhenRename() throws IOException { createDir("client"); addFileAndCommit("client/a.java", "a", "add a"); addFileAndCommit("client/b.java", "b", "add b"); createDir("server/src/com/example/a"); createDir("server/src/com/example/b"); addFileAndCommit("server/src/com/example/a/a.java", "a", "add a"); addFileAndCommit("server/src/com/example/b/b.java", "b", "add b"); String refName = "refs/heads/master"; ObjectId oldCommitId = git.getRepository().resolve(refName); Map<String, BlobContent> newBlobs = new HashMap<>(); newBlobs.put("client/a.java/a.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE)); BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a/a.java"), newBlobs); try { edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree"); assertTrue("A NotTreeException should be thrown", false); } catch (NotTreeException e) { } }
@Test public void testAddExistFile() throws IOException { createDir("client"); addFileAndCommit("client/a.java", "a", "add a"); addFileAndCommit("client/b.java", "b", "add b"); createDir("server/src/com/example/a"); createDir("server/src/com/example/b"); addFileAndCommit("server/src/com/example/a/a.java", "a", "add a"); addFileAndCommit("server/src/com/example/b/b.java", "b", "add b"); String refName = "refs/heads/master"; ObjectId oldCommitId = git.getRepository().resolve(refName); Map<String, BlobContent> newBlobs = new HashMap<>(); newBlobs.put("client/a.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE)); BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs); try { edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test rename tree"); assertTrue("An ObjectAlreadyExistException should be thrown", false); } catch (ObjectAlreadyExistsException e) { } }
@Test public void testObsoleteOldCommit() throws IOException { addFileAndCommit("a.java", "a", "add a"); String refName = "refs/heads/master"; ObjectId oldCommitId = git.getRepository().resolve(refName); addFileAndCommit("b.java", "b", "add b"); ObjectId newCommitId = git.getRepository().resolve(refName); Map<String, BlobContent> newBlobs = new HashMap<>(); newBlobs.put("/server/src/com/example/c/c.java", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE)); BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs); try { edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test add"); assertTrue("An ObsoleteCommitException should be thrown", false); } catch (ObsoleteCommitException e) { assertTrue(newCommitId.equals(e.getOldCommitId())); } }
/** * * @param dbmdJson * @param repo * @param tree * @param conn * @param clmnTree * @return * @throws IOException * @throws SQLException */ public static ObjectId metaTreeCommit(ObjectJson dbmdJson, Repository repo, TreeFormatter tree, Connection conn, Boolean clmnTree) throws IOException, SQLException { DatabaseMetaData dbmd = conn.getMetaData(); // ObjectJson dbmdJson = new ObjectJson(); String mapString = metaDbInfo(dbmd); ObjectInserter objectInserter = repo.newObjectInserter(); ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, mapString.getBytes()); objectInserter.flush(); tree.append(Consts.DATABASE, FileMode.REGULAR_FILE, blobId); Utils.putTableMeta(repo, conn, dbmd, objectInserter, tree, clmnTree); ObjectId treeId = objectInserter.insert(tree); objectInserter.flush(); System.out.println("Tree ID: " + treeId.getName()); return treeId; }
/** * * @param datarepo * @param tree * @param conn * @param clmnTree * @return * @throws SQLException * @throws IOException */ public static ObjectId dataTreeCommit(Repository datarepo, TreeFormatter tree, Connection conn, Boolean clmnTree) throws SQLException, IOException { DatabaseMetaData dbmd = conn.getMetaData(); // ObjectJson dbmdJson = new ObjectJson(); String mapString = metaDbInfo(dbmd); // Build Db_Info object, general info about Database ObjectInserter objectInserter = datarepo.newObjectInserter(); ObjectId blobId = objectInserter.insert(Constants.OBJ_BLOB, mapString.getBytes()); objectInserter.flush(); tree.append("DATABASE", FileMode.REGULAR_FILE, blobId); // Continue building Database Tree Utils.putTableMeta(datarepo, conn, dbmd, objectInserter, tree, clmnTree); ObjectId treeId = objectInserter.insert(tree); objectInserter.flush(); System.out.println("Tree ID: " + treeId.getName()); return treeId; }
/** * * @param columns * @param objectInserter * @param tblTree * @param walkTbl * @return * @throws SQLException * @throws IOException */ public static ObjectId putColumnMetaAsObject(ResultSet columns, ObjectInserter objectInserter, TreeFormatter tblTree, RevWalk walkTbl) throws SQLException, IOException { // Build object for column attributs ObjectId objectId = buildMetaObject(columns, Consts.COLUMN_META_ATTRIBUTES, objectInserter); tblTree.append(Consts.COLUMN_META, FileMode.REGULAR_FILE, (AnyObjectId) objectId); // Add empty tree for the column content TreeFormatter clmnDataTree = new TreeFormatter(); ObjectId clmnDataTreeId = objectInserter.insert(clmnDataTree); objectInserter.flush(); tblTree.append(Consts.COLUMN_DATA, walkTbl.parseTree(clmnDataTreeId)); return objectId; }
private static ObjectId buildMetaTree(ResultSet set, String[] attrs, ObjectInserter inserter, TreeFormatter tree) throws IOException, SQLException { for (String attr : attrs) { ObjectJson objectJson = new ObjectJson(); objectJson.addDoc(attr, set.getString(attr)); String attrJson = new Map2JsonString().convert(objectJson.getObjectAsMap()); ObjectId objectId = inserter.insert(Constants.OBJ_BLOB, attrJson.getBytes()); inserter.flush(); System.out.println("MetaObject: " + attrJson); // commitJson.addDoc(Consts.OBJECT_ID, objectId); tree.append(attr, FileMode.REGULAR_FILE, objectId); } return tree.computeId(inserter); }
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 { // there are a few others, see FileMode javadoc for details throw new IllegalArgumentException("Unknown type of file encountered: " + fileMode); } }
/** * TODO: see if performance can be improved */ private ObjectId getObjectId(File file) throws IOException { try (TreeWalk treeWalk = new TreeWalk(localRepo)) { treeWalk.addTree(new FileTreeIterator(localRepo)); String path = getRepoPath(file); treeWalk.setFilter(PathFilter.create(path)); while (treeWalk.next()) { WorkingTreeIterator workingTreeIterator = treeWalk.getTree(0, WorkingTreeIterator.class); if (treeWalk.getPathString().equals(path)) return workingTreeIterator.getEntryObjectId(); if (workingTreeIterator.getEntryFileMode().equals(FileMode.TREE)) treeWalk.enterSubtree(); } return ObjectId.zeroId(); // not found } }
private void processTreeParser(CanonicalTreeParser treeParser) throws IOException { TreeParserTreeEntry treeParserEntry = new TreeParserTreeEntry( treeParser, objectReader); List<CanonicalTreeParser> subTrees = new ArrayList<CanonicalTreeParser>(); while (!treeParser.eof()) { FileMode entryFileMode = treeParser.getEntryFileMode(); if (FileMode.TREE.equals(entryFileMode)) { CanonicalTreeParser canonicalTreeParser = new CanonicalTreeParser(); canonicalTreeParser.reset(objectReader, treeParser.getEntryObjectId()); subTrees.add(canonicalTreeParser); } else { if (!filterPredicate.evaluate(treeParserEntry)) { treeEntryWalk.walk(treeParserEntry); } } treeParser.next(); } for (CanonicalTreeParser subTreeParser : subTrees) { processTreeParser(subTreeParser); } }
private List<DashboardInfo> scanDashboards( Project definingProject, Repository git, RevWalk rw, Ref ref, String project, boolean setDefault) throws IOException { List<DashboardInfo> list = new ArrayList<>(); try (TreeWalk tw = new TreeWalk(rw.getObjectReader())) { tw.addTree(rw.parseTree(ref.getObjectId())); tw.setRecursive(true); while (tw.next()) { if (tw.getFileMode(0) == FileMode.REGULAR_FILE) { try { list.add( DashboardsCollection.parse( definingProject, ref.getName().substring(REFS_DASHBOARDS.length()), tw.getPathString(), new BlobBasedConfig(null, git, tw.getObjectId(0)), project, setDefault)); } catch (ConfigInvalidException e) { log.warn( String.format( "Cannot parse dashboard %s:%s:%s: %s", definingProject.getName(), ref.getName(), tw.getPathString(), e.getMessage())); } } } } return list; }
protected void saveFile(String fileName, byte[] raw) throws IOException { DirCacheEditor editor = newTree.editor(); if (raw != null && 0 < raw.length) { final ObjectId blobId = inserter.insert(Constants.OBJ_BLOB, raw); editor.add( new PathEdit(fileName) { @Override public void apply(DirCacheEntry ent) { ent.setFileMode(FileMode.REGULAR_FILE); ent.setObjectId(blobId); } }); } else { editor.add(new DeletePath(fileName)); } editor.finish(); }
@Override protected void onLoad() throws IOException, ConfigInvalidException { String prefix = DestinationList.DIR_NAME + "/"; for (PathInfo p : getPathInfos(true)) { if (p.fileMode == FileMode.REGULAR_FILE) { String path = p.path; if (path.startsWith(prefix)) { String label = path.substring(prefix.length()); ValidationError.Sink errors = TabFile.createLoggerSink(path, log); destinations.parseLabel(label, readUTF8(path), errors); } } } }
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; } return null; }
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 throw new AmbiguousObjectException(id, ids); } ObjectLoader ldr = reader.open(id.toObjectId()); return ldr.getCachedBytes(bigFileThreshold); }
/** * Retrieves the raw byte content of a file in the specified tree. * * @param repository * @param tree * if null, the RevTree from HEAD is assumed. * @param path * @return content as a byte [] */ public static byte[] getByteContent(Repository repository, RevTree tree, final String path, boolean throwError) { RevWalk rw = new RevWalk(repository); byte[] content = null; try (TreeWalk tw = new TreeWalk(repository)) { tw.setFilter(PathFilterGroup.createFromStrings(Collections.singleton(path))); if (tree == null) { ObjectId object = getDefaultBranch(repository); if (object == null) { return null; } RevCommit commit = rw.parseCommit(object); tree = commit.getTree(); } tw.reset(tree); while (tw.next()) { if (tw.isSubtree() && !path.equals(tw.getPathString())) { tw.enterSubtree(); continue; } ObjectId entid = tw.getObjectId(0); FileMode entmode = tw.getFileMode(0); if (entmode != FileMode.GITLINK) { ObjectLoader ldr = repository.open(entid, Constants.OBJ_BLOB); content = ldr.getCachedBytes(); } } } catch (Throwable t) { if (throwError) { error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name()); } } finally { rw.close(); rw.dispose(); } return content; }
@NotNull static GitProperty[] joinProperties(@NotNull GitProperty[] parentProps, @NotNull String entryName, @NotNull FileMode fileMode, @NotNull GitProperty[] entryProps) { if (parentProps.length == 0) { return entryProps; } final GitProperty[] joined = new GitProperty[parentProps.length + entryProps.length]; int index = 0; for (GitProperty parentProp : parentProps) { final GitProperty prop = parentProp.createForChild(entryName, fileMode); if (prop != null) { joined[index] = prop; index++; } } System.arraycopy(entryProps, 0, joined, index, entryProps.length); return index == parentProps.length ? joined : Arrays.copyOf(joined, index + entryProps.length); }
private boolean isExistingSymlink (int fileMode1, int fileModeWorking) { return (fileModeWorking & FileMode.TYPE_FILE) == FileMode.TYPE_FILE && (fileMode1 & FileMode.TYPE_SYMLINK) == FileMode.TYPE_SYMLINK; }
private boolean isSymlinkFolder (int mHead, boolean isSymlink) { // it seems symlink to a folder comes as two separate tree entries, // first has always mWorking set to 0 and is a symlink in index and HEAD // the other is identified as a new tree return isSymlink || (mHead & FileMode.TYPE_SYMLINK) == FileMode.TYPE_SYMLINK; }
private GitStatus.Status getGitlinkStatus (int mode1, ObjectId id1, int mode2, ObjectId id2) { if (mode1 == FileMode.TYPE_GITLINK || mode2 == FileMode.TYPE_GITLINK) { if (mode1 == FileMode.TYPE_MISSING) { return GitStatus.Status.STATUS_REMOVED; } else if (mode2 == FileMode.TYPE_MISSING) { return GitStatus.Status.STATUS_ADDED; } else if (!id1.equals(id2)) { return GitStatus.Status.STATUS_MODIFIED; } } return GitStatus.Status.STATUS_NORMAL; }
public void testAddNested () throws Exception { File f = new File(workDir, "f"); write(f, "file"); GitClient client = getClient(workDir); client.add(new File[] { f }, NULL_PROGRESS_MONITOR); client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); Thread.sleep(1100); File nested = new File(workDir, "nested"); nested.mkdirs(); File f2 = new File(nested, "f"); write(f2, "file"); GitClient clientNested = getClient(nested); clientNested.init(NULL_PROGRESS_MONITOR); clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); clientNested.commit(new File[] { f2 }, "aaa", null, null, NULL_PROGRESS_MONITOR); write(f2, "change"); Thread.sleep(1000); client.add(new File[] { workDir }, NULL_PROGRESS_MONITOR); Map<File, GitStatus> statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); // nested should be added as gitlink assertStatus(statuses, workDir, nested, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); DirCacheEntry e = repository.readDirCache().getEntry("nested"); assertEquals(FileMode.GITLINK, e.getFileMode()); assertEquals(nested.length(), e.getLength()); assertNotSame(ObjectId.zeroId().name(), e.getObjectId().getName()); statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); }
public static PageParameters paramsOf(CodeComment comment) { BlobIdent blobIdent = new BlobIdent(comment.getCommentPos().getCommit(), comment.getCommentPos().getPath(), FileMode.REGULAR_FILE.getBits()); ProjectBlobPage.State state = new ProjectBlobPage.State(blobIdent); state.requestId = comment.getRequest().getId(); state.commentId = comment.getId(); state.mark = comment.getCommentPos().getRange(); return paramsOf(comment.getRequest().getTargetProject(), state); }