Java Code Examples for org.gitective.core.BlobUtils

The following examples show how to use org.gitective.core.BlobUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: coming   Source File: CommitGit.java    License: MIT License 6 votes vote down vote up
private String getFileContent(ObjectId idRevCommit, String pathOfFile) {
	Repository jgitRepo = this.repo.getRepository();

	// Retrieve ID of files
	ObjectId fileId = BlobUtils.getId(jgitRepo, idRevCommit, pathOfFile);

	// Retrieve the files content
	String file = "";

	// If the file is new or has been deleted
	if (fileId != null) {
		file = BlobUtils.getContent(jgitRepo, fileId);
	}

	return file;
}
 
Example 2
Source Project: coderadar   Source File: GetRawCommitContentAdapter.java    License: MIT License 6 votes vote down vote up
@Override
public HashMap<File, byte[]> getCommitContentBulkWithFiles(
    String projectRoot,
    List<io.reflectoring.coderadar.projectadministration.domain.File> files,
    String commitHash)
    throws UnableToGetCommitContentException {
  try (Git git = Git.open(new java.io.File(projectRoot))) {
    ObjectId commitId = git.getRepository().resolve(commitHash);
    HashMap<File, byte[]> bulkContent = new LinkedHashMap<>();
    for (File file : files) {
      bulkContent.put(
          file, BlobUtils.getRawContent(git.getRepository(), commitId, file.getPath()));
    }
    return bulkContent;
  } catch (IOException e) {
    throw new UnableToGetCommitContentException(e.getMessage());
  }
}
 
Example 3
Source Project: coderadar   Source File: GetRawCommitContentAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public byte[] getCommitContent(String projectRoot, String filepath, String commitHash)
    throws UnableToGetCommitContentException {
  if (filepath.isEmpty()) {
    return new byte[0];
  }
  try (Git git = Git.open(new java.io.File(projectRoot))) {
    ObjectId commitId = git.getRepository().resolve(commitHash);
    return BlobUtils.getRawContent(git.getRepository(), commitId, filepath);
  } catch (IOException e) {
    throw new UnableToGetCommitContentException(e.getMessage());
  }
}
 
Example 4
Source Project: coderadar   Source File: GetRawCommitContentAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public HashMap<String, byte[]> getCommitContentBulk(
    String projectRoot, List<String> filepaths, String commitHash)
    throws UnableToGetCommitContentException {
  try (Git git = Git.open(new java.io.File(projectRoot))) {
    ObjectId commitId = git.getRepository().resolve(commitHash);
    HashMap<String, byte[]> bulkContent = new LinkedHashMap<>();
    for (String filepath : filepaths) {
      bulkContent.put(filepath, BlobUtils.getRawContent(git.getRepository(), commitId, filepath));
    }
    return bulkContent;
  } catch (IOException e) {
    throw new UnableToGetCommitContentException(e.getMessage());
  }
}
 
Example 5
Source Project: fabric8-forge   Source File: RepositoryResource.java    License: Apache License 2.0 4 votes vote down vote up
protected String doGetContent(Git git, String objectId, String pathOrBlobPath) {
    objectId = defaultObjectId(git, objectId);
    Repository r = git.getRepository();
    String blobPath = trimLeadingSlash(pathOrBlobPath);
    return BlobUtils.getContent(r, objectId, blobPath);
}