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;
}
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;
}
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;
}
Aggregations