toAddresses.add "dev-team@somewhere.com"\r
toAddresses.add "qa-team@somewhere.com"\r
break\r
- default: \r
- break\r
}\r
\r
-// get the create/update commits from the repository to build message content\r
-def commits = []\r
-for (ReceiveCommand command:commands) {\r
+// construct a simple text summary of the changes contained in the push\r
+def commitCount = 0\r
+def changes = ""\r
+def table = { it.id.name[0..8] + " " + it.authorIdent.name.padRight(20, " ") + it.shortMessage }\r
+for (command in commands) {\r
switch (command.type) {\r
- case ReceiveCommand.Type.UPDATE:\r
case ReceiveCommand.Type.CREATE:\r
- RevCommit commit = JGitUtils.getCommit(r, command.newId.name)\r
- commits.add(commit)\r
+ def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
+ commitCount += commits.size()\r
+ // new branch commits table\r
+ changes += "created ${command.refName}\n\n"\r
+ changes += commits.collect(table).join("\n")\r
+ changes += "\n"\r
+ break\r
+ case ReceiveCommand.Type.UPDATE:\r
+ def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
+ commitCount += commits.size()\r
+ // fast-forward branch commits table\r
+ changes += "updated ${command.refName}\n\n"\r
+ changes += commits.collect(table).join("\n")\r
+ changes += "\n"\r
+ break\r
+ case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:\r
+ def commits = JGitUtils.getRevLog(r, command.oldId.name, command.newId.name)\r
+ commitCount += commits.size()\r
+ // non-fast-forward branch commits table\r
+ changes += "updated ${command.refName} (NON fast-forward)\n\n"\r
+ changes += commits.collect(table).join("\n")\r
+ changes += "\n"\r
+ break\r
+ case ReceiveCommand.Type.DELETE:\r
+ // deleted branch\r
+ changes += "deleted ${command.refName}\n\n"\r
break\r
- \r
default:\r
break\r
}\r
else\r
summaryUrl = url + "/summary?r=" + repository.name\r
\r
-// create a simple commits table\r
-def table = commits.collect { it.id.name[0..8] + " " + it.authorIdent.name.padRight(20, " ") + it.shortMessage }.join("\n")\r
-\r
// create the message body\r
-def msg = """${user.username} pushed ${commits.size} commits to ${repository.name}\r
-${summaryUrl}\r
+def msg = """${summaryUrl}\r
\r
-${table}"""\r
+${changes}"""\r
\r
// tell Gitblit to send the message (Gitblit filters duplicate addresses)\r
-gitblit.notifyUsers("${emailprefix} ${user.username} pushed ${commits.size} commits => ${repository.name}", msg, toAddresses)
\ No newline at end of file
+gitblit.notifyUsers("${emailprefix} ${user.username} pushed ${commitCount} commits => ${repository.name}", msg, toAddresses)
\ No newline at end of file
return list;\r
}\r
\r
+ /**\r
+ * Returns a list of commits for the repository within the range specified\r
+ * by startRangeId and endRangeId. If the repository does not exist or is\r
+ * empty, an empty list is returned.\r
+ * \r
+ * @param repository\r
+ * @param startRangeId\r
+ * the first commit (not included in results)\r
+ * @param endRangeId\r
+ * the end commit (included in results)\r
+ * @return a list of commits\r
+ */\r
+ public static List<RevCommit> getRevLog(Repository repository, String startRangeId,\r
+ String endRangeId) {\r
+ List<RevCommit> list = new ArrayList<RevCommit>();\r
+ if (!hasCommits(repository)) {\r
+ return list;\r
+ }\r
+ try {\r
+ ObjectId endRange = repository.resolve(endRangeId);\r
+ ObjectId startRange = repository.resolve(startRangeId);\r
+\r
+ RevWalk rw = new RevWalk(repository);\r
+ rw.markStart(rw.parseCommit(endRange));\r
+ rw.markUninteresting(rw.parseCommit(startRange));\r
+\r
+ Iterable<RevCommit> revlog = rw;\r
+ for (RevCommit rev : revlog) {\r
+ list.add(rev);\r
+ }\r
+ rw.dispose();\r
+ } catch (Throwable t) {\r
+ error(t, repository, "{0} failed to get revlog for {1}..{2}", startRangeId, endRangeId);\r
+ }\r
+ return list;\r
+ }\r
+\r
/**\r
* Search the commit history for a case-insensitive match to the value.\r
* Search results require a specified SearchType of AUTHOR, COMMITTER, or\r
public void testAnonymousCommit() throws Exception {\r
Git git = Git.open(folder);\r
File file = new File(folder, "TODO");\r
- OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
- BufferedWriter w = new BufferedWriter(os);\r
- w.write("// " + new Date().toString() + "\n");\r
- w.close();\r
- git.add().addFilepattern(file.getName()).call();\r
- git.commit().setMessage("test commit").call();\r
+ for (int i = 0; i < 3; i++) {\r
+ OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true));\r
+ BufferedWriter w = new BufferedWriter(os);\r
+ w.write("// " + new Date().toString() + "\n");\r
+ w.close();\r
+ git.add().addFilepattern(file.getName()).call();\r
+ git.commit().setMessage("test commit #" + (i + 1)).call();\r
+ }\r
git.push().setPushAll().call();\r
git.getRepository().close();\r
}\r
repository.close();\r
}\r
\r
+ @Test\r
+ public void testRevLogRange() throws Exception {\r
+ Repository repository = GitBlitSuite.getHelloworldRepository();\r
+ List<RevCommit> commits = JGitUtils.getRevLog(repository,\r
+ "fbd14fa6d1a01d4aefa1fca725792683800fc67e",\r
+ "85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");\r
+ repository.close();\r
+ assertEquals(14, commits.size());\r
+ }\r
+\r
@Test\r
public void testSearchTypes() throws Exception {\r
assertEquals(SearchType.COMMIT, SearchType.forName("commit"));\r