From b674fed230bcd6488b796f49de5505cbaf448b07 Mon Sep 17 00:00:00 2001
From: Paul Martin <paul@paulsputer.com>
Date: Sat, 16 Apr 2016 11:41:45 -0400
Subject: [PATCH] fixes #966 to prevent always searching all repos
---
src/main/java/com/gitblit/utils/JGitUtils.java | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 3aaad6d..adcbb4d 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -1745,13 +1745,9 @@
* @return true if successful
*/
public static boolean deleteBranchRef(Repository repository, String branch) {
- String branchName = branch;
- if (!branchName.startsWith(Constants.R_HEADS)) {
- branchName = Constants.R_HEADS + branch;
- }
try {
- RefUpdate refUpdate = repository.updateRef(branchName, false);
+ RefUpdate refUpdate = repository.updateRef(branch, false);
refUpdate.setForceUpdate(true);
RefUpdate.Result result = refUpdate.delete();
switch (result) {
@@ -1762,10 +1758,10 @@
return true;
default:
LOGGER.error(MessageFormat.format("{0} failed to delete to {1} returned result {2}",
- repository.getDirectory().getAbsolutePath(), branchName, result));
+ repository.getDirectory().getAbsolutePath(), branch, result));
}
} catch (Throwable t) {
- error(t, repository, "{0} failed to delete {1}", branchName);
+ error(t, repository, "{0} failed to delete {1}", branch);
}
return false;
}
@@ -2727,5 +2723,22 @@
}
return success;
}
+
+ /**
+ * Returns true if the commit identified by commitId is at the tip of it's branch.
+ *
+ * @param repository
+ * @param commitId
+ * @return true if the given commit is the tip
+ */
+ public static boolean isTip(Repository repository, String commitId) {
+ try {
+ RefModel tip = getBranch(repository, commitId);
+ return (tip != null);
+ } catch (Exception e) {
+ LOGGER.error("Failed to determine isTip", e);
+ }
+ return false;
+ }
}
--
Gitblit v1.9.1