| | |
| | | try {
|
| | | // resolve object id
|
| | | ObjectId branchObject;
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | if (StringUtils.isEmpty(objectId) || "HEAD".equalsIgnoreCase(objectId)) {
|
| | | branchObject = getDefaultBranch(repository);
|
| | | } else {
|
| | | branchObject = repository.resolve(objectId);
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of tags in the repository. If repository does not exist
|
| | | * or is empty, an empty list is returned.
|
| | | *
|
| | | * @param repository
|
| | | * @param fullName
|
| | | * if true, /refs/tags/yadayadayada is returned. If false,
|
| | | * yadayadayada is returned.
|
| | | * @param maxCount
|
| | | * if < 0, all tags are returned
|
| | | * @param offset
|
| | | * if maxCount provided sets the starting point of the records to return
|
| | | * @return list of tags
|
| | | */
|
| | | public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount, int offset) {
|
| | | return getRefs(repository, Constants.R_TAGS, fullName, maxCount, offset);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of local branches in the repository. If repository does
|
| | | * not exist or is empty, an empty list is returned.
|
| | | *
|
| | |
| | | */
|
| | | private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
|
| | | int maxCount) {
|
| | | return getRefs(repository, refs, fullName, maxCount, 0);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a list of references in the repository matching "refs". If the
|
| | | * repository is null or empty, an empty list is returned.
|
| | | *
|
| | | * @param repository
|
| | | * @param refs
|
| | | * if unspecified, all refs are returned
|
| | | * @param fullName
|
| | | * if true, /refs/something/yadayadayada is returned. If false,
|
| | | * yadayadayada is returned.
|
| | | * @param maxCount
|
| | | * if < 0, all references are returned
|
| | | * @param offset
|
| | | * if maxCount provided sets the starting point of the records to return
|
| | | * @return list of references
|
| | | */
|
| | | private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
|
| | | int maxCount, int offset) {
|
| | | List<RefModel> list = new ArrayList<RefModel>();
|
| | | if (maxCount == 0) {
|
| | | return list;
|
| | |
| | | Collections.sort(list);
|
| | | Collections.reverse(list);
|
| | | if (maxCount > 0 && list.size() > maxCount) {
|
| | | list = new ArrayList<RefModel>(list.subList(0, maxCount));
|
| | | if (offset < 0) {
|
| | | offset = 0;
|
| | | }
|
| | | int endIndex = offset + maxCount;
|
| | | if (endIndex > list.size()) {
|
| | | endIndex = list.size();
|
| | | }
|
| | | list = new ArrayList<RefModel>(list.subList(offset, endIndex));
|
| | | }
|
| | | } catch (IOException e) {
|
| | | error(e, repository, "{0} failed to retrieve {1}", refs);
|
| | |
| | | } |
| | | } catch (IOException e) { |
| | | LOGGER.error("Failed to determine canMerge", e); |
| | | } finally { |
| | | revWalk.release(); |
| | | } finally {
|
| | | if (revWalk != null) { |
| | | revWalk.release();
|
| | | } |
| | | } |
| | | return MergeStatus.NOT_MERGEABLE; |
| | | } |
| | |
| | | } |
| | | } catch (IOException e) { |
| | | LOGGER.error("Failed to merge", e); |
| | | } finally { |
| | | revWalk.release(); |
| | | } finally {
|
| | | if (revWalk != null) { |
| | | revWalk.release();
|
| | | } |
| | | } |
| | | return new MergeResult(MergeStatus.FAILED, null); |
| | | } |