]> source.dussan.org Git - gitblit.git/commitdiff
Tag server-side merges when incremental push tags are enabled 85/85/3
authorJames Moger <james.moger@gitblit.com>
Fri, 23 May 2014 13:01:28 +0000 (09:01 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 23 May 2014 13:19:01 +0000 (09:19 -0400)
releases.moxie
src/main/java/com/gitblit/git/GitblitReceivePack.java
src/main/java/com/gitblit/git/PatchsetReceivePack.java

index afd1d8e8a8d78d637eb7e154c275f6ad2c473996..1ca462eaf534d01bafc6aa8ad05d3296f0bbaaee 100644 (file)
@@ -34,6 +34,7 @@ r24: {
     - Add object type (ot) parameter for RSS queries to retrieve tag details (pr-165, ticket-66)
     - Add setting to allow STARTTLS without requiring SMTPS (pr-183)
     - Added an extension point for monitoring onStartup and onShutdown (ticket-79)
+    - Tag server-side merges when incremental push tags are enabled (issue-432, ticket-85)
     dependencyChanges:
     - Update to javax.mail 1.5.1 (issue-417, ticket-58)
     contributors:
@@ -45,6 +46,7 @@ r24: {
     - Berke Viktor
     - Marcus Hunger
     - Matthias Cullmann
+    - Emmeran Seehuber
     settings:
     - { name: 'web.allowDeletingNonEmptyRepositories', defaultValue: 'true' }
     - { name: 'mail.starttls', defaultValue: 'false' }
index b4449f06f00c8e664683f6a97d9281f27e6b8dca..34bbea27a24755915acaabee2074271c5d437c39 100644 (file)
@@ -331,6 +331,43 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                        return;\r
                }\r
 \r
+               logRefChange(commands);\r
+               updateIncrementalPushTags(commands);\r
+               updateGitblitRefLog(commands);\r
+\r
+               // check for updates pushed to the BranchTicketService branch\r
+               // if the BranchTicketService is active it will reindex, as appropriate\r
+               for (ReceiveCommand cmd : commands) {\r
+                       if (Result.OK.equals(cmd.getResult())\r
+                                       && BranchTicketService.BRANCH.equals(cmd.getRefName())) {\r
+                               rp.getRepository().fireEvent(new ReceiveCommandEvent(repository, cmd));\r
+                       }\r
+               }\r
+\r
+               // call post-receive plugins\r
+               for (ReceiveHook hook : gitblit.getExtensions(ReceiveHook.class)) {\r
+                       try {\r
+                               hook.onPostReceive(this, commands);\r
+                       } catch (Exception e) {\r
+                               LOGGER.error("Failed to execute extension", e);\r
+                       }\r
+               }\r
+\r
+               // run Groovy hook scripts\r
+               Set<String> scripts = new LinkedHashSet<String>();\r
+               scripts.addAll(gitblit.getPostReceiveScriptsInherited(repository));\r
+               if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {\r
+                       scripts.addAll(repository.postReceiveScripts);\r
+               }\r
+               runGroovy(commands, scripts);\r
+       }\r
+\r
+       /**\r
+        * Log the ref changes in the container log.\r
+        *\r
+        * @param commands\r
+        */\r
+       protected void logRefChange(Collection<ReceiveCommand> commands) {\r
                boolean isRefCreationOrDeletion = false;\r
 \r
                // log ref changes\r
@@ -362,76 +399,65 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                if (isRefCreationOrDeletion) {\r
                        gitblit.resetRepositoryCache(repository.name);\r
                }\r
+       }\r
 \r
-               if (repository.useIncrementalPushTags) {\r
-                       // tag each pushed branch tip\r
-                       String emailAddress = user.emailAddress == null ? rp.getRefLogIdent().getEmailAddress() : user.emailAddress;\r
-                       PersonIdent userIdent = new PersonIdent(user.getDisplayName(), emailAddress);\r
-\r
-                       for (ReceiveCommand cmd : commands) {\r
-                               if (!cmd.getRefName().startsWith(Constants.R_HEADS)) {\r
-                                       // only tag branch ref changes\r
-                                       continue;\r
-                               }\r
-\r
-                               if (!ReceiveCommand.Type.DELETE.equals(cmd.getType())\r
-                                               && ReceiveCommand.Result.OK.equals(cmd.getResult())) {\r
-                                       String objectId = cmd.getNewId().getName();\r
-                                       String branch = cmd.getRefName().substring(Constants.R_HEADS.length());\r
-                                       // get translation based on the server's locale setting\r
-                                       String template = Translation.get("gb.incrementalPushTagMessage");\r
-                                       String msg = MessageFormat.format(template, branch);\r
-                                       String prefix;\r
-                                       if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {\r
-                                               prefix = settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
-                                       } else {\r
-                                               prefix = repository.incrementalPushTagPrefix;\r
-                                       }\r
-\r
-                                       JGitUtils.createIncrementalRevisionTag(\r
-                                                       rp.getRepository(),\r
-                                                       objectId,\r
-                                                       userIdent,\r
-                                                       prefix,\r
-                                                       "0",\r
-                                                       msg);\r
-                               }\r
-                       }\r
+       /**\r
+        * Optionally update the incremental push tags.\r
+        *\r
+        * @param commands\r
+        */\r
+       protected void updateIncrementalPushTags(Collection<ReceiveCommand> commands) {\r
+               if (!repository.useIncrementalPushTags) {\r
+                       return;\r
                }\r
 \r
-               // update push log\r
-               try {\r
-                       RefLogUtils.updateRefLog(user, rp.getRepository(), commands);\r
-                       LOGGER.debug(MessageFormat.format("{0} push log updated", repository.name));\r
-               } catch (Exception e) {\r
-                       LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);\r
-               }\r
+               // tag each pushed branch tip\r
+               String emailAddress = user.emailAddress == null ? getRefLogIdent().getEmailAddress() : user.emailAddress;\r
+               PersonIdent userIdent = new PersonIdent(user.getDisplayName(), emailAddress);\r
 \r
-               // check for updates pushed to the BranchTicketService branch\r
-               // if the BranchTicketService is active it will reindex, as appropriate\r
                for (ReceiveCommand cmd : commands) {\r
-                       if (Result.OK.equals(cmd.getResult())\r
-                                       && BranchTicketService.BRANCH.equals(cmd.getRefName())) {\r
-                               rp.getRepository().fireEvent(new ReceiveCommandEvent(repository, cmd));\r
+                       if (!cmd.getRefName().startsWith(Constants.R_HEADS)) {\r
+                               // only tag branch ref changes\r
+                               continue;\r
                        }\r
-               }\r
 \r
-               // call post-receive plugins\r
-               for (ReceiveHook hook : gitblit.getExtensions(ReceiveHook.class)) {\r
-                       try {\r
-                               hook.onPostReceive(this, commands);\r
-                       } catch (Exception e) {\r
-                               LOGGER.error("Failed to execute extension", e);\r
+                       if (!ReceiveCommand.Type.DELETE.equals(cmd.getType())\r
+                                       && ReceiveCommand.Result.OK.equals(cmd.getResult())) {\r
+                               String objectId = cmd.getNewId().getName();\r
+                               String branch = cmd.getRefName().substring(Constants.R_HEADS.length());\r
+                               // get translation based on the server's locale setting\r
+                               String template = Translation.get("gb.incrementalPushTagMessage");\r
+                               String msg = MessageFormat.format(template, branch);\r
+                               String prefix;\r
+                               if (StringUtils.isEmpty(repository.incrementalPushTagPrefix)) {\r
+                                       prefix = settings.getString(Keys.git.defaultIncrementalPushTagPrefix, "r");\r
+                               } else {\r
+                                       prefix = repository.incrementalPushTagPrefix;\r
+                               }\r
+\r
+                               JGitUtils.createIncrementalRevisionTag(\r
+                                               getRepository(),\r
+                                               objectId,\r
+                                               userIdent,\r
+                                               prefix,\r
+                                               "0",\r
+                                               msg);\r
                        }\r
                }\r
+       }\r
 \r
-               // run Groovy hook scripts\r
-               Set<String> scripts = new LinkedHashSet<String>();\r
-               scripts.addAll(gitblit.getPostReceiveScriptsInherited(repository));\r
-               if (!ArrayUtils.isEmpty(repository.postReceiveScripts)) {\r
-                       scripts.addAll(repository.postReceiveScripts);\r
+       /**\r
+        * Update Gitblit's internal reflog.\r
+        *\r
+        * @param commands\r
+        */\r
+       protected void updateGitblitRefLog(Collection<ReceiveCommand> commands) {\r
+               try {\r
+                       RefLogUtils.updateRefLog(user, getRepository(), commands);\r
+                       LOGGER.debug(MessageFormat.format("{0} reflog updated", repository.name));\r
+               } catch (Exception e) {\r
+                       LOGGER.error(MessageFormat.format("Failed to update {0} reflog", repository.name), e);\r
                }\r
-               runGroovy(commands, scripts);\r
        }\r
 \r
        /** Execute commands to update references. */\r
index f7412a346cac4f2ec98fcb58aa81437ef2b0fb60..9e55524d1b4222d33ed6d13385cec576248578b9 100644 (file)
@@ -1202,11 +1202,15 @@ public class PatchsetReceivePack extends GitblitReceivePack {
                if (ticket != null) {\r
                        ticketNotifier.queueMailing(ticket);\r
 \r
-                       // update the reflog with the merge\r
                        if (oldRef != null) {\r
                                ReceiveCommand cmd = new ReceiveCommand(oldRef.getObjectId(),\r
                                                ObjectId.fromString(mergeResult.sha), oldRef.getName());\r
-                               RefLogUtils.updateRefLog(user, getRepository(), Arrays.asList(cmd));\r
+                               cmd.setResult(Result.OK);\r
+                               List<ReceiveCommand> commands = Arrays.asList(cmd);\r
+\r
+                               logRefChange(commands);\r
+                               updateIncrementalPushTags(commands);\r
+                               updateGitblitRefLog(commands);\r
                        }\r
 \r
                        // call patchset hooks\r