From ec7ed84b04cd3981ae01b104bd52fc010f31e6a7 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 25 Sep 2014 09:06:39 -0400
Subject: [PATCH] Restrict Gitblit cookie to the context path
---
src/main/java/com/gitblit/utils/JGitUtils.java | 62 ++++++++++++++++++++++++++++---
1 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index c6526c2..da51ea9 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);
@@ -2256,8 +2302,10 @@
}
} 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 +2395,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