Changeset 2986

Show
Ignore:
Timestamp:
12/10/07 16:52:51 (5 years ago)
Author:
cho45
Message:

websites/coderepos.org/trac/share/js/TracUtils.js:

コミッタページにコミット履歴を表示してみる。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • websites/coderepos.org/trac/share/js/TracUtils.js

    r2952 r2986  
    8383                TracUtils.clickableCodeArea(); 
    8484                TracUtils.addBodyClass(); 
    85                 // TracUtils.addCommitterRecentCommits(); 
     85                TracUtils.addCommitterRecentCommits(); 
    8686                TracUtils.AuthorIcons.showAuthorIcons(); 
    8787        } 
     
    149149                if (/wiki\/Committers\/([^\/]+)/.test(location.pathname)) { 
    150150                        var author = RegExp.$1; 
    151                         $.get(TracUtils.TRAC_BASE + "/log/?limit=100&mode=stop_on_copy&format=changelog", {}, function (data) { 
    152                                 var parser = new ChangeLogParser(ChangeLogParser.Trac); 
    153                                 var log    = parser.parse(data); 
    154                                 var div    = $("<div class='recent-commits'><h2>Recent Commits</h2></div>"); 
    155                                 var n      = 0; 
    156                                 for (var i = 0, l = log.length; i < l; i++) { 
    157                                         var item = log[i]; 
    158                                         if (item.author == author) { 
    159                                                 // why not have inject function. 
    160                                                 var t = {}; $.each(item.paths, function (_, i) { 
    161                                                         t[i.path.split("/").slice(0, 3).join("/")] = true; 
    162                                                 }); 
    163                                                 item.paths = []; 
    164                                                 for (var j in t) if (t.hasOwnProperty(j)) item.paths.push(j); 
    165                                                 $("<div class='commit'></div>") 
    166                                                         .append( 
    167                                                                 $("<a class='revision'>["+item.revision+"]</a>") 
    168                                                                 .attr("href", TracUtils.TRAC_BASE + "/changeset/" + item.revision) 
    169                                                         ) 
    170                                                         .append(" ") 
    171                                                         .append("<span class='path'>"   + item.paths.join(", ") + "</span>") 
    172                                                         .append("<div class='message'>" + item.message + "</div>") 
    173                                                         .appendTo(div); 
    174                                                 n++; 
    175                                                 if (n > 5) break; 
    176                                         } 
    177                                 } 
    178                                 if (n == 0) div.append("<span class='none'>none...</span>"); 
     151                        $.get(TracUtils.TRAC_BASE + "/search?q="+author+"&noquickjump=1&changeset=on", {}, function (data) { 
     152                                var div = $("<div class='recent-commits'/>"); 
     153                                div.append("<h2>Recent Commits</h2>") 
     154                                   .append($(data).xfind(".//dl")); 
    179155                                $("#searchable").append(div); 
    180156                        }); 
     
    269245}; 
    270246 
    271  
    272 /* 
    273  * Copied lib 
    274  */ 
    275  
    276 function ChangeLogParser (callback) { 
    277         this.initialize.apply(this, arguments); 
    278 } 
    279  
    280 ChangeLogParser.prototype = { 
    281         initialize : function (callback) { 
    282                 if (!callback) callback = function (title, body) { 
    283                         return { 
    284                                 title: title, 
    285                                 body : body 
    286                         }; 
    287                 }; 
    288                 this.callback = callback; 
    289         }, 
    290  
    291         parse : function (str) { 
    292                 var ret = [], cur = null; 
    293                 var lines = str.split(/\n/); 
    294                 for (var i = 0, l = lines.length; i < l; i++) { 
    295                         var line = lines[i]; 
    296                         if (line.indexOf("\t") == 0) { 
    297                                 cur.body.push(line.substring(1)); 
    298                         } else 
    299                         if (line.indexOf("#") == 0 || // skip comment 
    300                             line.length == 0) { 
    301                                 continue; 
    302                         } else { 
    303                                 if (cur) ret.push(this.callback(cur.title, cur.body)); 
    304                                 cur = { 
    305                                         title : line, 
    306                                         body  : [] 
    307                                 }; 
    308                         } 
    309                 } 
    310                 if (cur) ret.push(this.callback(cur.title, cur.body)); 
    311                 return ret; 
    312         } 
    313 }; 
    314 ChangeLogParser.Trac = function (title, body) { 
    315         var m = title.match(/(\d{2})\/(\d{2})\/(\d{2}) (\d{2}):(\d{2}):(\d{2}) (\S+) \[(\d+)\]/); 
    316         var d = new Date(+m[3] + 2000, +m[1] - 1, +m[2], +m[4], +m[5], +m[6]); 
    317         var author = m[7], revision = +m[8]; 
    318  
    319         var paths = [], message = []; 
    320         for (var i = 0, l = body.length; i < l; i++) { 
    321                 if (body[i].indexOf("*") == 0 && /^\* (\S+) \(([^\)]+)\)/.test(body[i])) { 
    322                         paths.push({ action : RegExp.$2, path : RegExp.$1 }); 
    323                 } else { 
    324                         message.push(body[i]); 
    325                 } 
    326         } 
    327  
    328         return { 
    329                 date     : d, 
    330                 author   : author, 
    331                 revision : revision, 
    332                 message  : message.join("\n"), 
    333                 paths    : paths 
    334         }; 
    335 }; 
    336 /* 
    337 $.get("trac-changelog", {}, function (data) { 
    338         var parser = new ChangeLogParser(ChangeLogParser.Trac); 
    339         log(parser.parse(data)); 
    340 }) 
    341 */