From 23c416f30f4a1e69e76b70d71f6a9a7da4a020f1 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 10 Apr 2014 18:58:09 -0400 Subject: [PATCH] Hook-up comprensive command cleanup (destroy) --- src/main/java/com/gitblit/git/PatchsetReceivePack.java | 42 ++++++++++++++++++++++++++++++++---------- 1 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gitblit/git/PatchsetReceivePack.java b/src/main/java/com/gitblit/git/PatchsetReceivePack.java index 1d3312a..2c3b957 100644 --- a/src/main/java/com/gitblit/git/PatchsetReceivePack.java +++ b/src/main/java/com/gitblit/git/PatchsetReceivePack.java @@ -437,7 +437,10 @@ patchsetRefCmd.setResult(Result.OK); // update the ticket branch ref - RefUpdate ru = updateRef(patchsetCmd.getTicketBranch(), patchsetCmd.getNewId()); + RefUpdate ru = updateRef( + patchsetCmd.getTicketBranch(), + patchsetCmd.getNewId(), + patchsetCmd.getPatchsetType()); updateReflog(ru); TicketModel ticket = processPatchset(patchsetCmd); @@ -835,8 +838,8 @@ psCmd.updateTicket(c, mergeTo, ticket, null); // create a ticket patchset ref - updateRef(psCmd.getPatchsetBranch(), c.getId()); - RefUpdate ru = updateRef(psCmd.getTicketBranch(), c.getId()); + updateRef(psCmd.getPatchsetBranch(), c.getId(), patchset.type); + RefUpdate ru = updateRef(psCmd.getTicketBranch(), c.getId(), patchset.type); updateReflog(ru); // create a change from the patchset command @@ -897,11 +900,20 @@ if (parseMessage) { // parse commit message looking for fixes/closes #n - Pattern p = Pattern.compile("(?:fixes|closes)[\\s-]+#?(\\d+)", Pattern.CASE_INSENSITIVE); - Matcher m = p.matcher(commit.getFullMessage()); - while (m.find()) { - String val = m.group(1); - return Long.parseLong(val); + String dx = "(?:fixes|closes)[\\s-]+#?(\\d+)"; + String x = settings.getString(Keys.tickets.closeOnPushCommitMessageRegex, dx); + if (StringUtils.isEmpty(x)) { + x = dx; + } + try { + Pattern p = Pattern.compile(x, Pattern.CASE_INSENSITIVE); + Matcher m = p.matcher(commit.getFullMessage()); + while (m.find()) { + String val = m.group(1); + return Long.parseLong(val); + } + } catch (Exception e) { + LOGGER.error(String.format("Failed to parse \"%s\" in commit %s", x, commit.getName()), e); } } return 0L; @@ -1043,7 +1055,7 @@ return newPatchset; } - private RefUpdate updateRef(String ref, ObjectId newId) { + private RefUpdate updateRef(String ref, ObjectId newId, PatchsetType type) { ObjectId ticketRefId = ObjectId.zeroId(); try { ticketRefId = getRepository().resolve(ref); @@ -1054,7 +1066,17 @@ try { RefUpdate ru = getRepository().updateRef(ref, false); ru.setRefLogIdent(getRefLogIdent()); - ru.setForceUpdate(true); + switch (type) { + case Amend: + case Rebase: + case Rebase_Squash: + case Squash: + ru.setForceUpdate(true); + break; + default: + break; + } + ru.setExpectedOldObjectId(ticketRefId); ru.setNewObjectId(newId); RefUpdate.Result result = ru.update(getRevWalk()); -- Gitblit v1.9.1