use of com.gitblit.models.AnnotatedLine in project gitblit by gitblit.
the class DiffUtilsTest method testBlame.
@Test
public void testBlame() throws Exception {
Repository repository = GitBlitSuite.getHelloworldRepository();
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java", "1d0c2933a4ae69c362f76797d42d6bd182d05176");
repository.close();
assertTrue(lines.size() > 0);
assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
}
use of com.gitblit.models.AnnotatedLine in project gitblit by gitblit.
the class BlamePage method initializeColors.
private Map<?, String> initializeColors(BlameType blameType, List<AnnotatedLine> lines) {
ColorFactory colorFactory = new ColorFactory();
Map<?, String> colorMap;
if (BlameType.AGE == blameType) {
Set<Date> keys = new TreeSet<Date>(new Comparator<Date>() {
@Override
public int compare(Date o1, Date o2) {
// younger code has a brighter, older code lightens to white
return o1.compareTo(o2);
}
});
for (AnnotatedLine line : lines) {
keys.add(line.when);
}
// TODO consider making this a setting
colorMap = colorFactory.getGraduatedColorMap(keys, Color.decode("#FFA63A"));
} else {
Set<String> keys = new HashSet<String>();
for (AnnotatedLine line : lines) {
if (blameType == BlameType.AUTHOR) {
keys.add(line.author);
} else {
keys.add(line.commitId);
}
}
colorMap = colorFactory.getRandomColorMap(keys);
}
return colorMap;
}
use of com.gitblit.models.AnnotatedLine in project gitblit by gitblit.
the class DiffUtils method blame.
/**
* Returns the list of lines in the specified source file annotated with the
* source commit metadata.
*
* @param repository
* @param blobPath
* @param objectId
* @return list of annotated lines
*/
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
try {
ObjectId object;
if (StringUtils.isEmpty(objectId)) {
object = JGitUtils.getDefaultBranch(repository);
} else {
object = repository.resolve(objectId);
}
BlameCommand blameCommand = new BlameCommand(repository);
blameCommand.setFilePath(blobPath);
blameCommand.setStartCommit(object);
BlameResult blameResult = blameCommand.call();
RawText rawText = blameResult.getResultContents();
int length = rawText.size();
for (int i = 0; i < length; i++) {
RevCommit commit = blameResult.getSourceCommit(i);
AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
lines.add(line);
}
} catch (Throwable t) {
LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
}
return lines;
}
Aggregations