From 0e287b2e5c29e7674e54d80ed90e79f5b5432968 Mon Sep 17 00:00:00 2001 From: Jan Å mucr <jan.smucr@aimtec.cz> Date: Thu, 27 Nov 2014 08:00:48 -0500 Subject: [PATCH] Added a new property: web.displayUserPanel --- src/main/java/com/gitblit/utils/JGitUtils.java | 80 +++++++++++++++++++++++++++++++++++----- 1 files changed, 70 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java index c6526c2..68c62ea 100644 --- a/src/main/java/com/gitblit/utils/JGitUtils.java +++ b/src/main/java/com/gitblit/utils/JGitUtils.java @@ -711,7 +711,7 @@ 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); @@ -1668,6 +1668,24 @@ } /** + * 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. * @@ -1748,6 +1766,27 @@ */ 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; @@ -1771,7 +1810,14 @@ 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); @@ -2224,7 +2270,7 @@ } public static enum MergeStatus { - NOT_MERGEABLE, FAILED, ALREADY_MERGED, MERGEABLE, MERGED; + MISSING_INTEGRATION_BRANCH, MISSING_SRC_BRANCH, NOT_MERGEABLE, FAILED, ALREADY_MERGED, MERGEABLE, MERGED; } /** @@ -2239,9 +2285,17 @@ public static MergeStatus canMerge(Repository repository, String src, String toBranch) { RevWalk revWalk = null; try { - revWalk = new RevWalk(repository); - RevCommit branchTip = revWalk.lookupCommit(repository.resolve(toBranch)); - RevCommit srcTip = revWalk.lookupCommit(repository.resolve(src)); + revWalk = new RevWalk(repository); + ObjectId branchId = repository.resolve(toBranch); + if (branchId == null) { + return MergeStatus.MISSING_INTEGRATION_BRANCH; + } + ObjectId srcId = repository.resolve(src); + if (srcId == null) { + return MergeStatus.MISSING_SRC_BRANCH; + } + RevCommit branchTip = revWalk.lookupCommit(branchId); + RevCommit srcTip = revWalk.lookupCommit(srcId); if (revWalk.isMergedInto(srcTip, branchTip)) { // already merged return MergeStatus.ALREADY_MERGED; @@ -2254,10 +2308,14 @@ if (canMerge) { return MergeStatus.MERGEABLE; } + } catch (NullPointerException e) { + LOGGER.error("Failed to determine canMerge", e); } catch (IOException e) { LOGGER.error("Failed to determine canMerge", e); - } finally { - revWalk.release(); + } finally { + if (revWalk != null) { + revWalk.release(); + } } return MergeStatus.NOT_MERGEABLE; } @@ -2347,8 +2405,10 @@ } } catch (IOException e) { LOGGER.error("Failed to merge", e); - } finally { - revWalk.release(); + } finally { + if (revWalk != null) { + revWalk.release(); + } } return new MergeResult(MergeStatus.FAILED, null); } -- Gitblit v1.9.1