use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class RepositoryPage method registerNavLinks.
private List<NavLink> registerNavLinks() {
Repository r = getRepository();
RepositoryModel model = getRepositoryModel();
PageParameters params = null;
PageParameters objectParams = null;
if (!StringUtils.isEmpty(repositoryName)) {
params = WicketUtils.newRepositoryParameter(getRepositoryName());
objectParams = params;
// preserve the objectid iff the objectid directly (or indirectly) refers to a ref
if (isCommitPage() && !StringUtils.isEmpty(objectId)) {
RevCommit commit = JGitUtils.getCommit(r, objectId);
if (commit != null) {
String bestId = getBestCommitId(commit);
if (!commit.getName().equals(bestId)) {
objectParams = WicketUtils.newObjectParameter(getRepositoryName(), bestId);
}
}
}
}
List<NavLink> navLinks = new ArrayList<NavLink>();
// standard links
if (RefLogUtils.getRefLogBranch(r) == null) {
navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
} else {
navLinks.add(new PageNavLink("gb.summary", SummaryPage.class, params));
// pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
navLinks.add(new PageNavLink("gb.reflog", ReflogPage.class, params));
}
if (!model.hasCommits) {
return navLinks;
}
navLinks.add(new PageNavLink("gb.commits", LogPage.class, objectParams));
navLinks.add(new PageNavLink("gb.tree", TreePage.class, objectParams));
if (app().tickets().isReady() && (app().tickets().isAcceptingNewTickets(model) || app().tickets().hasTickets(model))) {
PageParameters tParams = WicketUtils.newOpenTicketsParameter(getRepositoryName());
navLinks.add(new PageNavLink("gb.tickets", TicketsPage.class, tParams));
}
navLinks.add(new PageNavLink("gb.docs", DocsPage.class, objectParams, true));
if (app().settings().getBoolean(Keys.web.allowForking, true)) {
navLinks.add(new PageNavLink("gb.forks", ForksPage.class, params, true));
}
navLinks.add(new PageNavLink("gb.compare", ComparePage.class, params, true));
// per-repository extra navlinks
if (JGitUtils.getPagesBranch(r) != null) {
ExternalNavLink pagesLink = new ExternalNavLink("gb.pages", PagesServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), getRepositoryName(), null), true);
navLinks.add(pagesLink);
}
UserModel user = UserModel.ANONYMOUS;
if (GitBlitWebSession.get().isLoggedIn()) {
user = GitBlitWebSession.get().getUser();
}
// add repository nav link extensions
List<RepositoryNavLinkExtension> extensions = app().plugins().getExtensions(RepositoryNavLinkExtension.class);
for (RepositoryNavLinkExtension ext : extensions) {
navLinks.addAll(ext.getNavLinks(user, model));
}
return navLinks;
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtils method cloneRepository.
/**
* Clone or Fetch a repository. If the local repository does not exist,
* clone is called. If the repository does exist, fetch is called. By
* default the clone/fetch retrieves the remote heads, tags, and notes.
*
* @param repositoriesFolder
* @param name
* @param fromUrl
* @param bare
* @param credentialsProvider
* @return CloneResult
* @throws Exception
*/
public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl, boolean bare, CredentialsProvider credentialsProvider) throws Exception {
CloneResult result = new CloneResult();
if (bare) {
// bare repository, ensure .git suffix
if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
name += Constants.DOT_GIT_EXT;
}
} else {
// normal repository, strip .git suffix
if (name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
name = name.substring(0, name.indexOf(Constants.DOT_GIT_EXT));
}
}
result.name = name;
File folder = new File(repositoriesFolder, name);
if (folder.exists()) {
File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);
Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
result.fetchResult = fetchRepository(credentialsProvider, repository);
repository.close();
} else {
CloneCommand clone = new CloneCommand();
clone.setBare(bare);
clone.setCloneAllBranches(true);
clone.setURI(fromUrl);
clone.setDirectory(folder);
if (credentialsProvider != null) {
clone.setCredentialsProvider(credentialsProvider);
}
Repository repository = clone.call().getRepository();
// Now we have to fetch because CloneCommand doesn't fetch
// refs/notes nor does it allow manual RefSpec.
result.createdRepository = true;
result.fetchResult = fetchRepository(credentialsProvider, repository);
repository.close();
}
return result;
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class ActivityUtils method getRecentActivity.
/**
* Gets the recent activity from the repositories for the last daysBack days
* on the specified branch.
*
* @param settings
* the runtime settings
* @param repositoryManager
* the repository manager
* @param models
* the list of repositories to query
* @param daysBack
* the number of days back from Now to collect
* @param objectId
* the branch to retrieve. If this value is null or empty all
* branches are queried.
* @param timezone
* the timezone for aggregating commits
* @return
*/
public static List<Activity> getRecentActivity(IStoredSettings settings, IRepositoryManager repositoryManager, List<RepositoryModel> models, int daysBack, String objectId, TimeZone timezone) {
// Activity panel shows last daysBack of activity across all
// repositories.
Date thresholdDate = new Date(System.currentTimeMillis() - daysBack * TimeUtils.ONEDAY);
// Build a map of DailyActivity from the available repositories for the
// specified threshold date.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
df.setTimeZone(timezone);
Calendar cal = Calendar.getInstance();
cal.setTimeZone(timezone);
// aggregate author exclusions
Set<String> authorExclusions = new TreeSet<String>();
authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));
for (RepositoryModel model : models) {
if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
authorExclusions.addAll(model.metricAuthorExclusions);
}
}
Map<String, Activity> activity = new HashMap<String, Activity>();
for (RepositoryModel model : models) {
if (!model.isShowActivity()) {
// skip this repository
continue;
}
if (model.hasCommits && model.lastChange.after(thresholdDate)) {
if (model.isCollectingGarbage) {
continue;
}
Repository repository = repositoryManager.getRepository(model.name);
List<String> branches = new ArrayList<String>();
if (StringUtils.isEmpty(objectId)) {
for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) {
if (!local.getDate().after(thresholdDate)) {
// branch not recently updated
continue;
}
branches.add(local.getName());
}
} else {
branches.add(objectId);
}
for (String branch : branches) {
String shortName = branch;
if (shortName.startsWith(Constants.R_HEADS)) {
shortName = shortName.substring(Constants.R_HEADS.length());
}
List<RepositoryCommit> commits = CommitCache.instance().getCommits(model.name, repository, branch, thresholdDate);
if (model.maxActivityCommits > 0 && commits.size() > model.maxActivityCommits) {
// trim commits to maximum count
commits = commits.subList(0, model.maxActivityCommits);
}
for (RepositoryCommit commit : commits) {
Date date = commit.getCommitDate();
String dateStr = df.format(date);
if (!activity.containsKey(dateStr)) {
// Normalize the date to midnight
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Activity a = new Activity(cal.getTime());
a.excludeAuthors(authorExclusions);
activity.put(dateStr, a);
}
activity.get(dateStr).addCommit(commit);
}
}
// close the repository
repository.close();
}
}
List<Activity> recentActivity = new ArrayList<Activity>(activity.values());
return recentActivity;
}
use of org.eclipse.jgit.lib.Repository in project camel by apache.
the class AbstractGitConsumer method getLocalRepository.
private Repository getLocalRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = // scan environment GIT_* variables
builder.setGitDir(new File(endpoint.getLocalPath(), ".git")).readEnvironment().findGitDir().build();
} catch (IOException e) {
LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
throw e;
}
return repo;
}
use of org.eclipse.jgit.lib.Repository in project camel by apache.
the class GitTestSupport method getTestRepository.
protected Repository getTestRepository() throws IOException, IllegalStateException, GitAPIException {
File gitRepo = new File(gitLocalRepo, ".git");
Git.init().setDirectory(new File(gitLocalRepo, "")).setBare(false).call();
// now open the resulting repository with a FileRepositoryBuilder
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = // scan
builder.setGitDir(gitRepo).readEnvironment().findGitDir().build();
return repo;
}
Aggregations