private byte[] contentFromTree(RevTree tree) { try { final ObjectReader reader = gitRepo.newObjectReader(); CanonicalTreeParser parser = new CanonicalTreeParser(); parser.reset(reader, tree); String lastPath = null; while (true) { final String path = parser.getEntryPathString(); parser = parser.next(); if (path.equals(lastPath)) { break; } lastPath = path; if (path.equals(CRUISE_CONFIG_XML)) { final ObjectId id = parser.getEntryObjectId(); final ObjectLoader loader = reader.open(id); return loader.getBytes(); } } return null; } catch (IOException e) { LOGGER.error("Could not fetch content from the config repository found at path '{}'", workingDir.getAbsolutePath(), e); throw new RuntimeException("Error while fetching content from the config repository.", e); } }
r.append(p.getEntryObjectId().name()); r.append(' '); r.append(p.getEntryPathString()); r.append('\n'); p.next();
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException { try { int ptr = t.getNameOffset(); int end = ptr + t.getNameLength(); chk.checkPathSegment(t.getEntryPathBuffer(), ptr, end); } catch (CorruptObjectException err) { String path = t.getEntryPathString(); InvalidPathException i = new InvalidPathException(path); i.initCause(err); throw i; } } }
update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (f == null || !m.idEqual(i)) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (i.getDirCacheEntry() != null) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); else {
@NotNull private List<GitTreeEntry> getEntries() throws IOException { final List<GitTreeEntry> entries = new ArrayList<>(); final CanonicalTreeParser treeParser = new CanonicalTreeParser(null, reader, id); boolean needAttributes = path.isEmpty(); while (!treeParser.eof()) { final FileMode fileMode = treeParser.getEntryFileMode(); final TaskType blobTask; final String pathTask; if (needAttributes && treeParser.getEntryPathString().equals(GIT_ATTRIBUTES)) { blobTask = TaskType.Attribute; pathTask = null; needAttributes = false; } else if (isFile(fileMode) && matchFilename(path + "/" + treeParser.getEntryPathString())) { blobTask = TaskType.UploadLfs; pathTask = null; } else { blobTask = TaskType.Simple; pathTask = path + "/" + treeParser.getEntryPathString(); } entries.add(new GitTreeEntry(fileMode, new TaskKey(blobTask, pathTask, treeParser.getEntryObjectId()), treeParser.getEntryPathString())); treeParser.next(); } if (needAttributes && globs.length > 0) { entries.add(new GitTreeEntry(FileMode.REGULAR_FILE, new TaskKey(TaskType.Attribute, null, ObjectId.zeroId()), GIT_ATTRIBUTES)); } return entries; }
r.append(p.getEntryObjectId().name()); r.append(' '); r.append(p.getEntryPathString()); r.append('\n'); p.next();
r.append(p.getEntryObjectId().name()); r.append(' '); r.append(p.getEntryPathString()); r.append('\n'); p.next();
@Nullable public static RevCommit loadOriginalCommit(@NotNull ObjectReader reader, @Nullable ObjectId cacheCommit) throws IOException { final RevWalk revWalk = new RevWalk(reader); if (cacheCommit != null) { final RevCommit revCommit = revWalk.parseCommit(cacheCommit); revWalk.parseTree(revCommit.getTree()); final CanonicalTreeParser treeParser = new CanonicalTreeParser(GitRepository.emptyBytes, reader, revCommit.getTree()); while (!treeParser.eof()) { if (treeParser.getEntryPathString().equals(ENTRY_COMMIT_REF)) { return revWalk.parseCommit(treeParser.getEntryObjectId()); } treeParser.next(); } } return null; }
@NotNull public Iterable<GitTreeEntry> loadTree(@Nullable GitTreeEntry tree) throws IOException { final GitObject<ObjectId> treeId = getTreeObject(tree); // Loading tree. if (treeId == null) { return Collections.emptyList(); } final List<GitTreeEntry> result = new ArrayList<>(); final Repository repo = treeId.getRepo(); final CanonicalTreeParser treeParser = new CanonicalTreeParser(GitRepository.emptyBytes, repo.newObjectReader(), treeId.getObject()); while (!treeParser.eof()) { result.add(new GitTreeEntry( treeParser.getEntryFileMode(), new GitObject<>(repo, treeParser.getEntryObjectId()), treeParser.getEntryPathString() )); treeParser.next(); } return result; }
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException { try { int ptr = t.getNameOffset(); int end = ptr + t.getNameLength(); chk.checkPathSegment(t.getEntryPathBuffer(), ptr, end); } catch (CorruptObjectException err) { String path = t.getEntryPathString(); InvalidPathException i = new InvalidPathException(path); i.initCause(err); throw i; } } }
private static void checkValidPathSegment(ObjectChecker chk, CanonicalTreeParser t) throws InvalidPathException { try { int ptr = t.getNameOffset(); int end = ptr + t.getNameLength(); chk.checkPathSegment(t.getEntryPathBuffer(), ptr, end); } catch (CorruptObjectException err) { String path = t.getEntryPathString(); InvalidPathException i = new InvalidPathException(path); i.initCause(err); throw i; } } }
private ObjectId findIdForPath(final Git origin, final RevCommit originMasterTip, final String searchPath) throws Exception { try (TreeWalk treeWalk = new TreeWalk(origin.getRepository())) { final int treeId = treeWalk.addTree(originMasterTip.getTree()); treeWalk.setRecursive(false); final CanonicalTreeParser treeParser = treeWalk.getTree(treeId, CanonicalTreeParser.class); while (treeWalk.next()) { final String path = treeParser.getEntryPathString(); if (path.equals(searchPath)) { return treeParser.getEntryObjectId(); } } } throw new AssertionError(String.format("Could not find path [%s] in commit [%s].", searchPath, originMasterTip.name())); }
private ObjectId findIdForPath(final Git origin, final RevCommit originMasterTip, final String searchPath) throws Exception { try (TreeWalk treeWalk = new TreeWalk(origin.getRepository())) { final int treeId = treeWalk.addTree(originMasterTip.getTree()); treeWalk.setRecursive(false); final CanonicalTreeParser treeParser = treeWalk.getTree(treeId, CanonicalTreeParser.class); while (treeWalk.next()) { final String path = treeParser.getEntryPathString(); if (path.equals(searchPath)) { return treeParser.getEntryObjectId(); } } } throw new AssertionError(String.format("Could not find path [%s] in commit [%s].", searchPath, originMasterTip.name())); }
update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (f == null || !m.idEqual(i)) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (i.getDirCacheEntry() != null) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); else {
public static Map<String, ObjectId> getEntries(Repository repository, RevTree tree) throws IOException { TreeWalk walk = new TreeWalk(repository); walk.addTree(tree); walk.setRecursive(true); walk.setFilter(new IgnoreHiddenFilter()); ImmutableSortedMap.Builder<String, ObjectId> builder = ImmutableSortedMap.naturalOrder(); while (walk.next()) { String path = walk.getTree(0, CanonicalTreeParser.class).getEntryPathString(); ObjectId objectId = walk.getObjectId(0); builder.put(path, objectId); } return builder.build(); }
update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (f == null || !m.idEqual(i)) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); } else if (i.getDirCacheEntry() != null) { update(m.getEntryPathString(), m.getEntryObjectId(), m.getEntryFileMode()); else {