use of com.gitblit.models.PathModel in project gitblit by gitblit.
the class JGitUtils method getFilesInPath.
/**
* Returns the list of files in the specified folder at the specified
* commit. If the repository does not exist or is empty, an empty list is
* returned.
*
* @param repository
* @param path
* if unspecified, root folder is assumed.
* @param commit
* if null, HEAD is assumed.
* @return list of files in specified path
*/
public static List<PathModel> getFilesInPath(Repository repository, String path, RevCommit commit) {
List<PathModel> list = new ArrayList<PathModel>();
if (!hasCommits(repository)) {
return list;
}
if (commit == null) {
commit = getCommit(repository, null);
}
final TreeWalk tw = new TreeWalk(repository);
try {
tw.addTree(commit.getTree());
if (!StringUtils.isEmpty(path)) {
PathFilter f = PathFilter.create(path);
tw.setFilter(f);
tw.setRecursive(false);
boolean foundFolder = false;
while (tw.next()) {
if (!foundFolder && tw.isSubtree()) {
tw.enterSubtree();
}
if (tw.getPathString().equals(path)) {
foundFolder = true;
continue;
}
if (foundFolder) {
list.add(getPathModel(tw, path, commit));
}
}
} else {
tw.setRecursive(false);
while (tw.next()) {
list.add(getPathModel(tw, null, commit));
}
}
} catch (IOException e) {
error(e, repository, "{0} failed to get files for commit {1}", commit.getName());
} finally {
tw.close();
}
Collections.sort(list);
return list;
}
use of com.gitblit.models.PathModel in project gitblit by gitblit.
the class MarkupProcessor method getDocs.
private List<MarkupDocument> getDocs(Repository r, String repositoryName, String commitId, List<String> names) {
List<String> extensions = getAllExtensions();
String[] encodings = getEncodings();
Map<String, MarkupDocument> map = new HashMap<String, MarkupDocument>();
RevCommit commit = JGitUtils.getCommit(r, commitId);
List<PathModel> paths = JGitUtils.getFilesInPath(r, null, commit);
for (PathModel path : paths) {
if (!path.isTree()) {
String ext = StringUtils.getFileExtension(path.name).toLowerCase();
String name = StringUtils.stripFileExtension(path.name).toLowerCase();
if (names.contains(name)) {
if (StringUtils.isEmpty(ext) || extensions.contains(ext)) {
String markup = JGitUtils.getStringContent(r, commit.getTree(), path.name, encodings);
MarkupDocument doc = parse(repositoryName, commitId, path.name, markup);
map.put(name, doc);
}
}
}
}
// return document list in requested order
List<MarkupDocument> list = new ArrayList<MarkupDocument>();
for (String name : names) {
if (map.containsKey(name)) {
list.add(map.get(name));
}
}
return list;
}
use of com.gitblit.models.PathModel in project gitblit by gitblit.
the class MarkupProcessor method hasRootDocs.
public boolean hasRootDocs(Repository r) {
List<String> roots = getRoots();
List<String> extensions = getAllExtensions();
List<PathModel> paths = JGitUtils.getFilesInPath(r, null, null);
for (PathModel path : paths) {
if (!path.isTree()) {
String ext = StringUtils.getFileExtension(path.name).toLowerCase();
String name = StringUtils.stripFileExtension(path.name).toLowerCase();
if (roots.contains(name)) {
if (StringUtils.isEmpty(ext) || extensions.contains(ext)) {
return true;
}
}
}
}
return false;
}
Aggregations