2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 var trac = trac || {};
30 function findUsingRegExp(string, regexp)
32 var match = regexp.exec(string);
38 function findReviewer(message)
40 var regexp = /Reviewed by ([^.]+)/;
41 return findUsingRegExp(message, regexp);
44 function findAuthor(message)
46 var regexp = /Patch by ([^<]+) </;
47 return findUsingRegExp(message, regexp);
50 function findBugID(message)
52 var regexp = /\/show_bug.cgi\?id=(\d+)/;
53 return parseInt(findUsingRegExp(message, regexp), 10);
56 function findRevision(title)
58 var regexp = /^Revision (\d+):/;
59 return parseInt(findUsingRegExp(title, regexp), 10);
62 function findSummary(message)
64 var lines = message.split('\n');
65 for (var i = 0; i < lines.length; ++i) {
69 if (findReviewer(line))
71 // Old-style commit message.
72 if (/^\d\d\d\d-\d\d-\d\d/.exec(line))
79 function findRevert(message)
81 var regexp = /rolling out r(\d+)\./;
82 var revision = findUsingRegExp(message, regexp);
85 return parseInt(revision, 10);
88 // FIXME: Consider exposing this method for unit testing.
89 function parseCommitData(responseXML)
91 var commits = Array.prototype.map.call(responseXML.getElementsByTagName('item'), function(item) {
92 var title = item.getElementsByTagName('title')[0].textContent;
93 var author = item.getElementsByTagName('author')[0].textContent;
94 var time = item.getElementsByTagName('pubDate')[0].textContent;
96 // FIXME: This isn't a very high-fidelity reproduction of the commit message,
97 // but it's good enough for our purposes.
98 var container = document.createElement('div');
99 container.innerHTML = item.getElementsByTagName('description')[0].textContent;
100 var message = container.innerText;
103 'revision': findRevision(title),
106 'summary': findSummary(message),
107 'author': findAuthor(message) || author,
108 'reviewer': findReviewer(message),
109 'bugID': findBugID(message),
111 'revertedRevision': findRevert(message),
118 var g_cache = new base.AsynchronousCache(function(key, callback) {
119 var explodedKey = key.split('\n');
121 var path = explodedKey[0];
122 var startRevision = explodedKey[1];
123 var endRevision = explodedKey[2];
125 var url = trac.logURL(path, startRevision, endRevision, true, true);
127 net.get(url, function(commitData) {
128 callback(parseCommitData(commitData));
132 trac.changesetURL = function(revision)
134 return config.kTracURL + '/changeset/' + revision;
137 trac.logURL = function(path, startRevision, endRevision, showFullCommitLogs, formatAsRSS)
139 var queryParameters = {
141 stop_rev: startRevision,
142 // Trac requires limit to be 1 more than the number of revisions we actually want to show.
143 // See <http://trac.edgewall.org/ticket/10317>.
144 limit: endRevision - startRevision + 2,
147 if (showFullCommitLogs)
148 queryParameters.verbose = 'on';
150 queryParameters.format = 'rss';
152 return config.kTracURL + '/log/' + path + '?' + $.param(queryParameters);
155 trac.recentCommitData = function(path, limit, callback)
157 var url = config.kTracURL + '/log/' + path + '?' + $.param({
163 net.get(url, function(commitData) {
164 callback(parseCommitData(commitData));
168 trac.commitDataForRevisionRange = function(path, startRevision, endRevision, callback)
170 var key = [path, startRevision, endRevision].join('\n');
171 g_cache.get(key, callback);