import com.gitblit.models.GitClientApplication; | import com.gitblit.models.GitClientApplication; | ||||
import com.gitblit.models.Metric; | import com.gitblit.models.Metric; | ||||
import com.gitblit.models.ProjectModel; | import com.gitblit.models.ProjectModel; | ||||
import com.gitblit.models.RefModel; | |||||
import com.gitblit.models.RegistrantAccessPermission; | import com.gitblit.models.RegistrantAccessPermission; | ||||
import com.gitblit.models.RepositoryModel; | import com.gitblit.models.RepositoryModel; | ||||
import com.gitblit.models.RepositoryUrl; | import com.gitblit.models.RepositoryUrl; | ||||
configureJGit(); | configureJGit(); | ||||
configureFanout(); | configureFanout(); | ||||
configureGitDaemon(); | configureGitDaemon(); | ||||
CommitCache.instance().setCacheDays(settings.getInteger(Keys.web.activityCacheDays, 14)); | |||||
configureCommitCache(); | |||||
ContainerUtils.CVE_2007_0450.test(); | ContainerUtils.CVE_2007_0450.test(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
protected void configureCommitCache() { | |||||
int daysToCache = settings.getInteger(Keys.web.activityCacheDays, 14); | |||||
if (daysToCache <= 0) { | |||||
logger.info("commit cache disabled"); | |||||
} else { | |||||
long start = System.nanoTime(); | |||||
long repoCount = 0; | |||||
long commitCount = 0; | |||||
logger.info(MessageFormat.format("preparing {0} day commit cache. please wait...", daysToCache)); | |||||
CommitCache.instance().setCacheDays(daysToCache); | |||||
Date cutoff = CommitCache.instance().getCutoffDate(); | |||||
for (String repositoryName : getRepositoryList()) { | |||||
RepositoryModel model = getRepositoryModel(repositoryName); | |||||
if (model.hasCommits && model.lastChange.after(cutoff)) { | |||||
repoCount++; | |||||
Repository repository = getRepository(repositoryName); | |||||
for (RefModel ref : JGitUtils.getLocalBranches(repository, true, -1)) { | |||||
if (!ref.getDate().after(cutoff)) { | |||||
// branch not recently updated | |||||
continue; | |||||
} | |||||
List<?> commits = CommitCache.instance().getCommits(repositoryName, repository, ref.getName()); | |||||
if (commits.size() > 0) { | |||||
logger.info(MessageFormat.format(" cached {0} commits for {1}:{2}", | |||||
commits.size(), repositoryName, ref.getName())); | |||||
commitCount += commits.size(); | |||||
} | |||||
} | |||||
repository.close(); | |||||
} | |||||
} | |||||
logger.info(MessageFormat.format("built {0} day commit cache of {1} commits across {2} repositories in {3} msecs", | |||||
daysToCache, commitCount, repoCount, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start))); | |||||
} | |||||
} | |||||
protected final Logger getLogger() { | protected final Logger getLogger() { | ||||
return logger; | return logger; | ||||
} | } |
if (StringUtils.isEmpty(objectId)) { | if (StringUtils.isEmpty(objectId)) { | ||||
for (RefModel local : JGitUtils.getLocalBranches( | for (RefModel local : JGitUtils.getLocalBranches( | ||||
repository, true, -1)) { | repository, true, -1)) { | ||||
if (!local.getDate().after(thresholdDate)) { | |||||
// branch not recently updated | |||||
continue; | |||||
} | |||||
branches.add(local.getName()); | branches.add(local.getName()); | ||||
} | } | ||||
} else { | } else { |
* | * | ||||
* @return | * @return | ||||
*/ | */ | ||||
protected Date getCacheCutoffDate() { | |||||
public Date getCutoffDate() { | |||||
final Calendar cal = Calendar.getInstance(); | final Calendar cal = Calendar.getInstance(); | ||||
cal.setTimeInMillis(System.currentTimeMillis()); | cal.setTimeInMillis(System.currentTimeMillis()); | ||||
cal.set(Calendar.HOUR_OF_DAY, 0); | cal.set(Calendar.HOUR_OF_DAY, 0); | ||||
* @return a list of commits | * @return a list of commits | ||||
*/ | */ | ||||
public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch) { | public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch) { | ||||
return getCommits(repositoryName, repository, branch, getCacheCutoffDate()); | |||||
return getCommits(repositoryName, repository, branch, getCutoffDate()); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch, Date sinceDate) { | public List<RepositoryCommit> getCommits(String repositoryName, Repository repository, String branch, Date sinceDate) { | ||||
long start = System.nanoTime(); | long start = System.nanoTime(); | ||||
Date cacheCutoffDate = getCacheCutoffDate(); | |||||
Date cacheCutoffDate = getCutoffDate(); | |||||
List<RepositoryCommit> list; | List<RepositoryCommit> list; | ||||
if (cacheDays > 0 && (sinceDate.getTime() >= cacheCutoffDate.getTime())) { | if (cacheDays > 0 && (sinceDate.getTime() >= cacheCutoffDate.getTime())) { | ||||
// request fits within the cache window | // request fits within the cache window |
Map<String, DailyLogEntry> dailydigests = new HashMap<String, DailyLogEntry>(); | Map<String, DailyLogEntry> dailydigests = new HashMap<String, DailyLogEntry>(); | ||||
String linearParent = null; | String linearParent = null; | ||||
for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) { | for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) { | ||||
if (!local.getDate().after(minimumDate)) { | |||||
// branch not recently updated | |||||
continue; | |||||
} | |||||
String branch = local.getName(); | String branch = local.getName(); | ||||
List<RepositoryCommit> commits = CommitCache.instance().getCommits(repositoryName, repository, branch, minimumDate); | List<RepositoryCommit> commits = CommitCache.instance().getCommits(repositoryName, repository, branch, minimumDate); | ||||
for (RepositoryCommit commit : commits) { | for (RepositoryCommit commit : commits) { |
package com.gitblit.wicket.pages; | package com.gitblit.wicket.pages; | ||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.text.DateFormat; | |||||
import java.text.MessageFormat; | import java.text.MessageFormat; | ||||
import java.text.SimpleDateFormat; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Calendar; | import java.util.Calendar; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import com.gitblit.wicket.charting.GoogleChart; | import com.gitblit.wicket.charting.GoogleChart; | ||||
import com.gitblit.wicket.charting.GoogleCharts; | import com.gitblit.wicket.charting.GoogleCharts; | ||||
import com.gitblit.wicket.charting.GooglePieChart; | import com.gitblit.wicket.charting.GooglePieChart; | ||||
import com.gitblit.wicket.ng.NgController; | |||||
import com.gitblit.wicket.panels.DigestsPanel; | import com.gitblit.wicket.panels.DigestsPanel; | ||||
import com.gitblit.wicket.panels.LinkPanel; | import com.gitblit.wicket.panels.LinkPanel; | ||||
// create daily commit digest feed | // create daily commit digest feed | ||||
List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>(); | List<DailyLogEntry> digests = new ArrayList<DailyLogEntry>(); | ||||
for (RepositoryModel model : repositories) { | for (RepositoryModel model : repositories) { | ||||
Repository repository = GitBlit.self().getRepository(model.name); | |||||
List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone); | |||||
digests.addAll(entries); | |||||
repository.close(); | |||||
if (model.isCollectingGarbage) { | |||||
continue; | |||||
} | |||||
if (model.hasCommits && model.lastChange.after(minimumDate)) { | |||||
Repository repository = GitBlit.self().getRepository(model.name); | |||||
List<DailyLogEntry> entries = RefLogUtils.getDailyLogByRef(model.name, repository, minimumDate, timezone); | |||||
digests.addAll(entries); | |||||
repository.close(); | |||||
} | |||||
} | } | ||||
Fragment activityFragment = new Fragment("activity", "activityFragment", this); | Fragment activityFragment = new Fragment("activity", "activityFragment", this); |