| | |
| | | import org.eclipse.jgit.revwalk.RevWalk;
|
| | | import org.eclipse.jgit.revwalk.filter.CommitTimeRevFilter;
|
| | | import org.eclipse.jgit.revwalk.filter.RevFilter;
|
| | | import org.eclipse.jgit.storage.file.FileRepository;
|
| | | import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
| | | import org.eclipse.jgit.transport.CredentialsProvider;
|
| | | import org.eclipse.jgit.transport.FetchResult;
|
| | | import org.eclipse.jgit.transport.RefSpec;
|
| | |
| | | File folder = new File(repositoriesFolder, name);
|
| | | if (folder.exists()) {
|
| | | File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);
|
| | | FileRepository repository = new FileRepository(gitDir);
|
| | | Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
|
| | | result.fetchResult = fetchRepository(credentialsProvider, repository);
|
| | | repository.close();
|
| | | } else {
|
| | |
| | | list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder,
|
| | | onlyBare, searchSubfolders, depth, patterns));
|
| | | StringUtils.sortRepositorynames(list);
|
| | | list.remove(".git"); // issue-256
|
| | | return list;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | return false;
|
| | | }
|
| | | |
| | | /**
|
| | | * Encapsulates the result of cloning or pulling from a repository.
|
| | | */
|
| | | public static class LastChange {
|
| | | public Date when;
|
| | | public String who;
|
| | | |
| | | LastChange() {
|
| | | when = new Date(0); |
| | | }
|
| | | |
| | | LastChange(long lastModified) {
|
| | | this.when = new Date(lastModified);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the date of the most recent commit on a branch. If the repository
|
| | | * does not exist Date(0) is returned. If it does exist but is empty, the
|
| | | * last modified date of the repository folder is returned.
|
| | | * Returns the date and author of the most recent commit on a branch. If the
|
| | | * repository does not exist Date(0) is returned. If it does exist but is
|
| | | * empty, the last modified date of the repository folder is returned.
|
| | | *
|
| | | * @param repository
|
| | | * @return
|
| | | * @return a LastChange object
|
| | | */
|
| | | public static Date getLastChange(Repository repository) {
|
| | | public static LastChange getLastChange(Repository repository) {
|
| | | if (!hasCommits(repository)) {
|
| | | // null repository
|
| | | if (repository == null) {
|
| | | return new Date(0);
|
| | | return new LastChange();
|
| | | }
|
| | | // fresh repository
|
| | | return new Date(repository.getDirectory().lastModified());
|
| | | return new LastChange(repository.getDirectory().lastModified());
|
| | | }
|
| | |
|
| | | List<RefModel> branchModels = getLocalBranches(repository, true, -1);
|
| | | if (branchModels.size() > 0) {
|
| | | // find most recent branch update
|
| | | Date lastChange = new Date(0);
|
| | | LastChange lastChange = new LastChange(); |
| | | for (RefModel branchModel : branchModels) {
|
| | | if (branchModel.getDate().after(lastChange)) {
|
| | | lastChange = branchModel.getDate();
|
| | | if (branchModel.getDate().after(lastChange.when)) {
|
| | | lastChange.when = branchModel.getDate();
|
| | | lastChange.who = branchModel.getAuthorIdent().getName();
|
| | | }
|
| | | }
|
| | | return lastChange;
|
| | | }
|
| | |
|
| | | // default to the repository folder modification date
|
| | | return new Date(repository.getDirectory().lastModified());
|
| | | return new LastChange(repository.getDirectory().lastModified());
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | try {
|
| | | if (tree == null) {
|
| | | ObjectId object = getDefaultBranch(repository);
|
| | | if (object == null)
|
| | | return null;
|
| | | RevCommit commit = rw.parseCommit(object);
|
| | | tree = commit.getTree();
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of files changed in a specified commit. If the
|
| | | * repository does not exist or is empty, an empty list is returned.
|
| | | * |
| | | * @param repository
|
| | | * @param startCommit
|
| | | * earliest commit
|
| | | * @param endCommit
|
| | | * most recent commit. if null, HEAD is assumed.
|
| | | * @return list of files changed in a commit range
|
| | | */
|
| | | public static List<PathChangeModel> getFilesInRange(Repository repository, RevCommit startCommit, RevCommit endCommit) {
|
| | | List<PathChangeModel> list = new ArrayList<PathChangeModel>();
|
| | | if (!hasCommits(repository)) {
|
| | | return list;
|
| | | }
|
| | | try {
|
| | | DiffFormatter df = new DiffFormatter(null);
|
| | | df.setRepository(repository);
|
| | | df.setDiffComparator(RawTextComparator.DEFAULT);
|
| | | df.setDetectRenames(true);
|
| | |
|
| | | List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
|
| | | for (DiffEntry diff : diffEntries) {
|
| | | |
| | | if (diff.getChangeType().equals(ChangeType.DELETE)) {
|
| | | list.add(new PathChangeModel(diff.getOldPath(), diff.getOldPath(), 0, diff
|
| | | .getNewMode().getBits(), diff.getOldId().name(), null, diff
|
| | | .getChangeType()));
|
| | | } else if (diff.getChangeType().equals(ChangeType.RENAME)) {
|
| | | list.add(new PathChangeModel(diff.getOldPath(), diff.getNewPath(), 0, diff
|
| | | .getNewMode().getBits(), diff.getNewId().name(), null, diff
|
| | | .getChangeType()));
|
| | | } else {
|
| | | list.add(new PathChangeModel(diff.getNewPath(), diff.getNewPath(), 0, diff
|
| | | .getNewMode().getBits(), diff.getNewId().name(), null, diff
|
| | | .getChangeType()));
|
| | | }
|
| | | } |
| | | Collections.sort(list);
|
| | | } catch (Throwable t) {
|
| | | error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit);
|
| | | }
|
| | | return list;
|
| | | }
|
| | | /**
|
| | | * Returns the list of files in the repository on the default branch that
|
| | | * match one of the specified extensions. This is a CASE-SENSITIVE search.
|
| | | * If the repository does not exist or is empty, an empty list is returned.
|
| | |
| | | }
|
| | | try {
|
| | | // resolve branch
|
| | | ObjectId branchObject;
|
| | | ObjectId startRange = null;
|
| | | ObjectId endRange;
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | branchObject = getDefaultBranch(repository);
|
| | | endRange = getDefaultBranch(repository);
|
| | | } else {
|
| | | branchObject = repository.resolve(objectId);
|
| | | if( objectId.contains("..") ) {
|
| | | // range expression
|
| | | String[] parts = objectId.split("\\.\\.");
|
| | | startRange = repository.resolve(parts[0]);
|
| | | endRange = repository.resolve(parts[1]);
|
| | | } else {
|
| | | // objectid
|
| | | endRange= repository.resolve(objectId);
|
| | | }
|
| | | }
|
| | | if (branchObject == null) {
|
| | | if (endRange == null) {
|
| | | return list;
|
| | | }
|
| | |
|
| | | RevWalk rw = new RevWalk(repository);
|
| | | rw.markStart(rw.parseCommit(branchObject));
|
| | | rw.markStart(rw.parseCommit(endRange));
|
| | | if (startRange != null) {
|
| | | rw.markUninteresting(rw.parseCommit(startRange)); |
| | | }
|
| | | if (!StringUtils.isEmpty(path)) {
|
| | | TreeFilter filter = AndTreeFilter.create(
|
| | | PathFilterGroup.createFromStrings(Collections.singleton(path)),
|