// could happen if not enough permissions, for example
if (folderCommit != null) {
// Add folder-related properties ...
String committer = commiterName(folderCommit);
String author = authorName(folderCommit);
DateTime committed = values.dateFrom(folderCommit.getCommitTime());
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, folderCommit.getId().name());
writer.addProperty(GitLexicon.AUTHOR, author);
writer.addProperty(GitLexicon.COMMITTER, committer);
writer.addProperty(GitLexicon.COMMITTED, committed);
writer.addProperty(GitLexicon.TITLE, folderCommit.getShortMessage());
} else {
connector.getLogger().warn(GitI18n.cannotReadCommit, path);
}
// And now walk the contents of the directory ...
while (tw.next()) {
String childName = tw.getNameString();
String childId = spec.childId(childName);
writer.addChild(childId, childName);
}
} else {
// The path specifies a file (or a content node) ...
// Find the commit in which this folder was last modified ...
// This may not be terribly efficient, but it seems to work faster on subsequent runs ...
RevCommit fileCommit = git.log().addPath(path).call().iterator().next();
if (isContentNode) {
writer.setPrimaryType(GitLexicon.RESOURCE);
if (fileCommit == null) {
// could happen if not enough permissions, for example
connector.getLogger().warn(GitI18n.cannotReadCommit, path);
return;
}
// Add file-related properties ...
String committer = commiterName(fileCommit);
String author = authorName(fileCommit);
DateTime committed = values.dateFrom(fileCommit.getCommitTime());
writer.addProperty(JcrLexicon.LAST_MODIFIED, committed);
writer.addProperty(JcrLexicon.LAST_MODIFIED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
writer.addProperty(GitLexicon.AUTHOR, author);
writer.addProperty(GitLexicon.COMMITTER, committer);
writer.addProperty(GitLexicon.COMMITTED, committed);
writer.addProperty(GitLexicon.TITLE, fileCommit.getShortMessage());
// Create the BinaryValue ...
ObjectId fileObjectId = tw.getObjectId(0);
ObjectLoader fileLoader = repository.open(fileObjectId);
BinaryKey key = new BinaryKey(fileObjectId.getName());
BinaryValue value = values.binaryFor(key, fileLoader.getSize());
if (value == null) {
// It wasn't found in the binary store ...
if (fileLoader.isLarge()) {
// Too large to hold in memory, so use the binary store (which reads the file immediately) ...
value = values.binaryFrom(fileLoader.openStream());
} else {
// This is small enough to fit into a byte[], but it still may be pretty big ...
value = new GitBinaryValue(fileObjectId, fileLoader, connector.getSourceName(), name,
connector.getMimeTypeDetector());
}
}
writer.addProperty(JcrLexicon.DATA, value);
if (connector.includeMimeType()) {
try {
String filename = spec.parameter(spec.parameterCount() - 1); // the last is 'jcr:content'
String mimeType = value.getMimeType(filename);
if (mimeType != null) writer.addProperty(JcrLexicon.MIMETYPE, mimeType);
} catch (RepositoryException e) {
// do nothing
} catch (IOException e) {
// do nothing
}
}
} else {
writer.setPrimaryType(GitLexicon.FILE);
if (fileCommit == null) {
// could happen if not enough permissions, for example
connector.getLogger().warn(GitI18n.cannotReadCommit, path);
return;
}
// Add file-related properties ...
String committer = commiterName(fileCommit);
String author = authorName(fileCommit);
DateTime committed = values.dateFrom(fileCommit.getCommitTime());
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
writer.addProperty(GitLexicon.AUTHOR, author);