use of com.gitblit.models.RefLogEntry in project gitblit by gitblit.
the class RefLogUtils method getLogByRef.
/**
* Returns the list of entries organized by ref (e.g. each ref has it's own
* RefLogEntry object).
*
* @param repositoryName
* @param repository
* @param offset
* @param maxCount
* @return a list of reflog entries separated by ref
*/
public static List<RefLogEntry> getLogByRef(String repositoryName, Repository repository, int offset, int maxCount) {
// break the reflog into ref entries and then merge them back into a list
Map<String, List<RefLogEntry>> refMap = new HashMap<String, List<RefLogEntry>>();
List<RefLogEntry> refLog = getRefLog(repositoryName, repository, offset, maxCount);
for (RefLogEntry entry : refLog) {
for (String ref : entry.getChangedRefs()) {
if (!refMap.containsKey(ref)) {
refMap.put(ref, new ArrayList<RefLogEntry>());
}
// construct new ref-specific ref change entry
RefLogEntry refChange;
if (entry instanceof DailyLogEntry) {
// simulated reflog from commits grouped by date
refChange = new DailyLogEntry(entry.repository, entry.date);
} else {
// real reflog entry
refChange = new RefLogEntry(entry.repository, entry.date, entry.user);
}
refChange.updateRef(ref, entry.getChangeType(ref), entry.getOldId(ref), entry.getNewId(ref));
refChange.addCommits(entry.getCommits(ref));
refMap.get(ref).add(refChange);
}
}
// merge individual ref changes into master list
List<RefLogEntry> mergedRefLog = new ArrayList<RefLogEntry>();
for (List<RefLogEntry> refPush : refMap.values()) {
mergedRefLog.addAll(refPush);
}
// sort ref log
Collections.sort(mergedRefLog);
return mergedRefLog;
}
use of com.gitblit.models.RefLogEntry in project gitblit by gitblit.
the class RefLogUtils method getDailyLog.
/**
* Returns a commit log grouped by day.
*
* @param repositoryName
* @param repository
* @param minimumDate
* @param offset
* @param maxCount
* if < 0, all entries are returned.
* @param the timezone to use when aggregating commits by date
* @return a list of grouped commit log entries
*/
public static List<DailyLogEntry> getDailyLog(String repositoryName, Repository repository, Date minimumDate, int offset, int maxCount, TimeZone timezone) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setTimeZone(timezone);
Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);
Map<String, DailyLogEntry> tags = new HashMap<String, DailyLogEntry>();
Map<String, DailyLogEntry> pulls = new HashMap<String, DailyLogEntry>();
Map<String, DailyLogEntry> dailydigests = new HashMap<String, DailyLogEntry>();
String linearParent = null;
for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) {
if (!local.getDate().after(minimumDate)) {
// branch not recently updated
continue;
}
String branch = local.getName();
List<RepositoryCommit> commits = CommitCache.instance().getCommits(repositoryName, repository, branch, minimumDate);
linearParent = null;
for (RepositoryCommit commit : commits) {
if (linearParent != null) {
if (!commit.getName().equals(linearParent)) {
// only follow linear branch commits
continue;
}
}
Date date = commit.getCommitDate();
String dateStr = df.format(date);
if (!dailydigests.containsKey(dateStr)) {
dailydigests.put(dateStr, new DailyLogEntry(repositoryName, date));
}
DailyLogEntry digest = dailydigests.get(dateStr);
if (commit.getParentCount() == 0) {
linearParent = null;
digest.updateRef(branch, ReceiveCommand.Type.CREATE);
} else {
linearParent = commit.getParents()[0].getId().getName();
digest.updateRef(branch, ReceiveCommand.Type.UPDATE, linearParent, commit.getName());
}
RepositoryCommit repoCommit = digest.addCommit(commit);
if (repoCommit != null) {
List<RefModel> matchedRefs = allRefs.get(commit.getId());
repoCommit.setRefs(matchedRefs);
if (!ArrayUtils.isEmpty(matchedRefs)) {
for (RefModel ref : matchedRefs) {
if (ref.getName().startsWith(Constants.R_TAGS)) {
// treat tags as special events in the log
if (!tags.containsKey(dateStr)) {
UserModel tagUser = newUserModelFrom(ref.getAuthorIdent());
Date tagDate = commit.getAuthorIdent().getWhen();
tags.put(dateStr, new DailyLogEntry(repositoryName, tagDate, tagUser));
}
RefLogEntry tagEntry = tags.get(dateStr);
tagEntry.updateRef(ref.getName(), ReceiveCommand.Type.CREATE);
RepositoryCommit rc = repoCommit.clone(ref.getName());
tagEntry.addCommit(rc);
} else if (ref.getName().startsWith(Constants.R_PULL)) {
// treat pull requests as special events in the log
if (!pulls.containsKey(dateStr)) {
UserModel commitUser = newUserModelFrom(ref.getAuthorIdent());
Date commitDate = commit.getAuthorIdent().getWhen();
pulls.put(dateStr, new DailyLogEntry(repositoryName, commitDate, commitUser));
}
RefLogEntry pullEntry = pulls.get(dateStr);
pullEntry.updateRef(ref.getName(), ReceiveCommand.Type.CREATE);
RepositoryCommit rc = repoCommit.clone(ref.getName());
pullEntry.addCommit(rc);
}
}
}
}
}
}
List<DailyLogEntry> list = new ArrayList<DailyLogEntry>(dailydigests.values());
list.addAll(tags.values());
// list.addAll(pulls.values());
Collections.sort(list);
return list;
}
use of com.gitblit.models.RefLogEntry in project gitblit by gitblit.
the class DashboardPage method addCharts.
/**
* Creates the daily activity line chart, the active repositories pie chart,
* and the active authors pie chart
*
* @param recentChanges
* @param authorExclusions
* @param daysBack
*/
protected void addCharts(Fragment frag, List<DailyLogEntry> recentChanges, Set<String> authorExclusions, int daysBack) {
// activity metrics
Map<String, Metric> repositoryMetrics = new HashMap<String, Metric>();
Map<String, Metric> authorMetrics = new HashMap<String, Metric>();
// aggregate repository and author metrics
int totalCommits = 0;
for (RefLogEntry change : recentChanges) {
// aggregate repository metrics
String repository = StringUtils.stripDotGit(change.repository);
if (!repositoryMetrics.containsKey(repository)) {
repositoryMetrics.put(repository, new Metric(repository));
}
repositoryMetrics.get(repository).count += 1;
for (RepositoryCommit commit : change.getCommits()) {
totalCommits++;
String author = StringUtils.removeNewlines(commit.getAuthorIdent().getName());
String authorName = author.toLowerCase();
String authorEmail = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();
if (!authorExclusions.contains(authorName) && !authorExclusions.contains(authorEmail)) {
if (!authorMetrics.containsKey(author)) {
authorMetrics.put(author, new Metric(author));
}
authorMetrics.get(author).count += 1;
}
}
}
String headerPattern;
if (daysBack == 1) {
// today
if (totalCommits == 0) {
headerPattern = getString("gb.todaysActivityNone");
} else {
headerPattern = getString("gb.todaysActivityStats");
}
} else {
// multiple days
if (totalCommits == 0) {
headerPattern = getString("gb.recentActivityNone");
} else {
headerPattern = getString("gb.recentActivityStats");
}
}
frag.add(new Label("feedheader", MessageFormat.format(headerPattern, daysBack, totalCommits, authorMetrics.size())));
if (app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
// build google charts
Charts charts = new Flotr2Charts();
// active repositories pie chart
Chart chart = charts.createPieChart("chartRepositories", getString("gb.activeRepositories"), getString("gb.repository"), getString("gb.commits"));
for (Metric metric : repositoryMetrics.values()) {
chart.addValue(metric.name, metric.count);
}
chart.setShowLegend(false);
String url = urlFor(SummaryPage.class, null).toString() + "?r=";
chart.setClickUrl(url);
charts.addChart(chart);
// active authors pie chart
chart = charts.createPieChart("chartAuthors", getString("gb.activeAuthors"), getString("gb.author"), getString("gb.commits"));
for (Metric metric : authorMetrics.values()) {
chart.addValue(metric.name, metric.count);
}
chart.setShowLegend(false);
charts.addChart(chart);
add(new HeaderContributor(charts));
frag.add(new Fragment("charts", "chartsFragment", this));
} else {
frag.add(new Label("charts").setVisible(false));
}
}
Aggregations