summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-07-31 15:55:28 -0400
committerJames Moger <james.moger@gitblit.com>2013-07-31 15:56:11 -0400
commit88ec32f91b3df15e063a2b2dcea3c90f3c65d835 (patch)
tree4a820a90e4f3a0286fef6c6058072cea1a24314a /src/main
parente523d77e5f9d61a7cbf0b2242c8795a22fdf7b45 (diff)
downloadgitblit-88ec32f91b3df15e063a2b2dcea3c90f3c65d835.tar.gz
gitblit-88ec32f91b3df15e063a2b2dcea3c90f3c65d835.zip
Improvements to reflog branch deletion
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/gitblit/utils/RefLogUtils.java34
-rw-r--r--src/main/java/com/gitblit/wicket/panels/BranchesPanel.java42
2 files changed, 45 insertions, 31 deletions
diff --git a/src/main/java/com/gitblit/utils/RefLogUtils.java b/src/main/java/com/gitblit/utils/RefLogUtils.java
index dfb5f56d..df09a76f 100644
--- a/src/main/java/com/gitblit/utils/RefLogUtils.java
+++ b/src/main/java/com/gitblit/utils/RefLogUtils.java
@@ -180,22 +180,22 @@ public class RefLogUtils {
* @param ref
* @return true, if the update was successful
*/
- public static boolean deleteRef(UserModel user, Repository repository, String ref) {
+ public static boolean deleteRef(UserModel user, Repository repository, Ref ref) {
try {
- Ref refObj = repository.getRef(ref);
- if (refObj == null && !ref.startsWith(Constants.R_HEADS) && ref.startsWith(Constants.R_TAGS)) {
- // find fully qualified ref
- refObj = repository.getRef(Constants.R_HEADS + ref);
- if (refObj == null) {
- refObj = repository.getRef(Constants.R_TAGS + ref);
- }
+ if (ref == null) {
+ return false;
}
-
- if (refObj == null) {
+ RefModel reflogBranch = getRefLogBranch(repository);
+ if (reflogBranch == null) {
return false;
}
- ReceiveCommand cmd = new ReceiveCommand(refObj.getObjectId(), ObjectId.zeroId(), refObj.getName());
+ List<RevCommit> log = JGitUtils.getRevLog(repository, reflogBranch.getName(), ref.getName(), 0, 1);
+ if (log.isEmpty()) {
+ // this ref is not in the reflog branch
+ return false;
+ }
+ ReceiveCommand cmd = new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName());
return updateRefLog(user, repository, Arrays.asList(cmd));
} catch (Throwable t) {
error(t, repository, "Failed to commit reflog entry to {0}");
@@ -442,9 +442,13 @@ public class RefLogUtils {
UserModel user = newUserModelFrom(push.getAuthorIdent());
Date date = push.getAuthorIdent().getWhen();
- RefLogEntry log = new RefLogEntry(repositoryName, date, user);
- list.add(log);
+ RefLogEntry log = new RefLogEntry(repositoryName, date, user);
List<PathChangeModel> changedRefs = JGitUtils.getFilesInCommit(repository, push);
+ if (changedRefs.isEmpty()) {
+ // skip empty commits
+ continue;
+ }
+ list.add(log);
for (PathChangeModel change : changedRefs) {
switch (change.changeType) {
case DELETE:
@@ -458,6 +462,10 @@ public class RefLogUtils {
String oldId = fields[1];
String newId = fields[2];
log.updateRef(change.path, ReceiveCommand.Type.valueOf(fields[0]), oldId, newId);
+ if (ObjectId.zeroId().getName().equals(newId)) {
+ // ref deletion
+ continue;
+ }
List<RevCommit> pushedCommits = JGitUtils.getRevLog(repository, oldId, newId);
for (RevCommit pushedCommit : pushedCommits) {
RepositoryCommit repoCommit = log.addCommit(change.path, pushedCommit);
diff --git a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java
index 85d00296..dba40897 100644
--- a/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/BranchesPanel.java
@@ -199,29 +199,35 @@ public class BranchesPanel extends BasePanel {
return;
}
final String branch = entry.getName();
- boolean success = JGitUtils.deleteBranchRef(r, branch);
- if (success) {
- // clear commit cache
- CommitCache.instance().clear(repositoryModel.name, branch);
+ Ref ref = null;
+ try {
+ ref = r.getRef(branch);
+ if (ref == null && !branch.startsWith(Constants.R_HEADS)) {
+ ref = r.getRef(Constants.R_HEADS + branch);
+ }
+ } catch (IOException e) {
+ }
+ if (ref != null) {
+ boolean success = JGitUtils.deleteBranchRef(r, ref.getName());
+ if (success) {
+ // clear commit cache
+ CommitCache.instance().clear(repositoryModel.name, branch);
+
+ // optionally update reflog
+ if (RefLogUtils.hasRefLogBranch(r)) {
+ UserModel user = GitBlitWebSession.get().getUser();
+ RefLogUtils.deleteRef(user, r, ref);
+ }
+ }
- // optionally update reflog
- if (RefLogUtils.hasRefLogBranch(r)) {
- UserModel user = GitBlitWebSession.get().getUser();
- success = RefLogUtils.deleteRef(user, r, branch);
+ if (success) {
+ info(MessageFormat.format("Branch \"{0}\" deleted", branch));
+ } else {
+ error(MessageFormat.format("Failed to delete branch \"{0}\"", branch));
}
}
-
r.close();
- if (success) {
- info(MessageFormat.format("Branch \"{0}\" deleted", branch));
- // redirect to the owning page
- setResponsePage(getPage().getClass(), WicketUtils.newRepositoryParameter(repositoryModel.name));
- }
- else {
- error(MessageFormat.format("Failed to delete branch \"{0}\"", branch));
- }
-
// redirect to the owning page
PageParameters params = WicketUtils.newRepositoryParameter(repositoryModel.name);
String relativeUrl = urlFor(getPage().getClass(), params).toString();