Search in sources :

Example 6 with RepositoryCommit

use of com.gitblit.models.RepositoryCommit in project gitblit by gitblit.

the class RefLogUtils method getRefLog.

/**
	 * Returns the list of reflog entries as they were recorded by Gitblit.
	 * Each RefLogEntry may represent multiple ref updates.
	 *
	 * @param repositoryName
	 * @param repository
	 * @param minimumDate
	 * @param offset
	 * @param maxCount
	 * 			if < 0, all entries are returned.
	 * @return a list of reflog entries
	 */
public static List<RefLogEntry> getRefLog(String repositoryName, Repository repository, Date minimumDate, int offset, int maxCount) {
    List<RefLogEntry> list = new ArrayList<RefLogEntry>();
    RefModel ref = getRefLogBranch(repository);
    if (ref == null) {
        return list;
    }
    if (maxCount == 0) {
        return list;
    }
    Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);
    List<RevCommit> pushes;
    if (minimumDate == null) {
        pushes = JGitUtils.getRevLog(repository, GB_REFLOG, offset, maxCount);
    } else {
        pushes = JGitUtils.getRevLog(repository, GB_REFLOG, minimumDate);
    }
    for (RevCommit push : pushes) {
        if (push.getAuthorIdent().getName().equalsIgnoreCase("gitblit")) {
            // skip gitblit/internal commits
            continue;
        }
        UserModel user = newUserModelFrom(push.getAuthorIdent());
        Date date = push.getAuthorIdent().getWhen();
        RefLogEntry log = new RefLogEntry(repositoryName, date, user);
        // only report HEADS and TAGS for now
        List<PathChangeModel> changedRefs = new ArrayList<PathChangeModel>();
        for (PathChangeModel refChange : JGitUtils.getFilesInCommit(repository, push)) {
            if (refChange.path.startsWith(Constants.R_HEADS) || refChange.path.startsWith(Constants.R_TAGS)) {
                changedRefs.add(refChange);
            }
        }
        if (changedRefs.isEmpty()) {
            // skip empty commits
            continue;
        }
        list.add(log);
        for (PathChangeModel change : changedRefs) {
            switch(change.changeType) {
                case DELETE:
                    log.updateRef(change.path, ReceiveCommand.Type.DELETE);
                    break;
                default:
                    String content = JGitUtils.getStringContent(repository, push.getTree(), change.path);
                    String[] fields = content.split(" ");
                    String oldId = fields[1];
                    String newId = fields[2];
                    log.updateRef(change.path, ReceiveCommand.Type.valueOf(fields[0]), oldId, newId);
                    if (ObjectId.zeroId().getName().equals(newId)) {
                        // ref deletion
                        continue;
                    }
                    try {
                        List<RevCommit> pushedCommits = JGitUtils.getRevLog(repository, oldId, newId);
                        for (RevCommit pushedCommit : pushedCommits) {
                            RepositoryCommit repoCommit = log.addCommit(change.path, pushedCommit);
                            if (repoCommit != null) {
                                repoCommit.setRefs(allRefs.get(pushedCommit.getId()));
                            }
                        }
                    } catch (Exception e) {
                    }
            }
        }
    }
    Collections.sort(list);
    return list;
}
Also used : RefModel(com.gitblit.models.RefModel) ObjectId(org.eclipse.jgit.lib.ObjectId) PathChangeModel(com.gitblit.models.PathModel.PathChangeModel) ArrayList(java.util.ArrayList) RepositoryCommit(com.gitblit.models.RepositoryCommit) RefLogEntry(com.gitblit.models.RefLogEntry) Date(java.util.Date) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) UserModel(com.gitblit.models.UserModel) ArrayList(java.util.ArrayList) List(java.util.List) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 7 with RepositoryCommit

use of com.gitblit.models.RepositoryCommit in project gitblit by gitblit.

the class CommitCache method get.

/**
	 * Returns a list of commits for the specified repository branch.
	 *
	 * @param repositoryName
	 * @param repository
	 * @param branch
	 * @param sinceDate
	 * @return a list of commits
	 */
protected List<RepositoryCommit> get(String repositoryName, Repository repository, String branch, Date sinceDate) {
    Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, false);
    List<RevCommit> revLog = JGitUtils.getRevLog(repository, branch, sinceDate);
    List<RepositoryCommit> commits = new ArrayList<RepositoryCommit>(revLog.size());
    for (RevCommit commit : revLog) {
        RepositoryCommit commitModel = new RepositoryCommit(repositoryName, branch, commit);
        List<RefModel> commitRefs = allRefs.get(commitModel.getId());
        commitModel.setRefs(commitRefs);
        commits.add(commitModel);
    }
    return commits;
}
Also used : RefModel(com.gitblit.models.RefModel) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryCommit(com.gitblit.models.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with RepositoryCommit

use of com.gitblit.models.RepositoryCommit in project gitblit by gitblit.

the class CommitCache method get.

/**
	 * Returns a list of commits for the specified repository branch since the specified commit.
	 *
	 * @param repositoryName
	 * @param repository
	 * @param branch
	 * @param sinceCommit
	 * @return a list of commits
	 */
protected List<RepositoryCommit> get(String repositoryName, Repository repository, String branch, ObjectId sinceCommit) {
    Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, false);
    List<RevCommit> revLog = JGitUtils.getRevLog(repository, sinceCommit.getName(), branch);
    List<RepositoryCommit> commits = new ArrayList<RepositoryCommit>(revLog.size());
    for (RevCommit commit : revLog) {
        RepositoryCommit commitModel = new RepositoryCommit(repositoryName, branch, commit);
        List<RefModel> commitRefs = allRefs.get(commitModel.getId());
        commitModel.setRefs(commitRefs);
        commits.add(commitModel);
    }
    return commits;
}
Also used : RefModel(com.gitblit.models.RefModel) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryCommit(com.gitblit.models.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RepositoryCommit (com.gitblit.models.RepositoryCommit)8 ArrayList (java.util.ArrayList)6 RefModel (com.gitblit.models.RefModel)5 Date (java.util.Date)5 List (java.util.List)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RefLogEntry (com.gitblit.models.RefLogEntry)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 UserModel (com.gitblit.models.UserModel)2 Calendar (java.util.Calendar)2 Label (org.apache.wicket.markup.html.basic.Label)2 Activity (com.gitblit.models.Activity)1 DailyLogEntry (com.gitblit.models.DailyLogEntry)1 Metric (com.gitblit.models.Metric)1 PathChangeModel (com.gitblit.models.PathModel.PathChangeModel)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 TimeUtils (com.gitblit.utils.TimeUtils)1