Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!-- | 1 <!-- |
| 2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. | 4 found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 | 6 |
| 7 <link rel="import" href="../lib/net.html"> | 7 <link rel="import" href="../lib/net.html"> |
| 8 <link rel='import' href='ct-commit.html'> | 8 <link rel='import' href='ct-commit.html'> |
| 9 <link rel='import' href='ct-repositories.html'> | 9 <link rel='import' href='ct-repositories.html'> |
| 10 | 10 |
| 11 <script> | 11 <script> |
| 12 function CTCommitLog() { | 12 function CTCommitLog() { |
| 13 this.commits = {}; | 13 this.commits = {}; |
| 14 this.firstRevision = {}; | 14 this.firstRevision = {}; |
| 15 this.lastRevision = {}; | 15 this.lastRevision = {}; |
| 16 this._repositories = new CTRepositories(); | 16 this._repositories = new CTRepositories(); |
| 17 | |
| 18 this._repositories.names().forEach(function(name) { | |
| 19 this.commits[name] = {}; | |
| 20 }.bind(this)); | |
| 17 } | 21 } |
| 18 | 22 |
| 19 CTCommitLog.prototype.update = function() { | 23 CTCommitLog.prototype.update = function() { |
| 20 var requests = []; | 24 var requests = []; |
| 21 Object.keys(this._repositories.repositories, (function(name, repository) { | 25 Object.keys(this._repositories.repositories, (function(name, repository) { |
| 22 var responseHandler = this._handleResponse.bind(this, repository.repositoryU rl, repository.name); | 26 var responseHandler = this._handleResponse.bind(this, repository.repositoryU rl, repository.name); |
| 23 // FIXME: Turn net.js into net.html and import it at the top of this file. | 27 // FIXME: Turn net.js into net.html and import it at the top of this file. |
| 24 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler)); | 28 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler)); |
| 25 }.bind(this))); | 29 }.bind(this))); |
| 26 return Promise.all(requests); | 30 return Promise.all(requests); |
| 27 } | 31 } |
| 28 | 32 |
| 29 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json ) { | 33 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json ) { |
| 30 if (!this.commits[repository]) | |
| 31 this.commits[repository] = {}; | |
| 32 | |
| 33 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation. | 34 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation. |
| 34 json = json.substring(')]}\n'.length); | 35 json = json.substring(')]}\n'.length); |
| 35 JSON.parse(json).log.forEach(function(entry) { | 36 JSON.parse(json).log.forEach(function(entry) { |
| 36 var commit = CTCommit.create(entry.author.name, entry.message, repositoryUrl , repository); | 37 var author = entry.author.name; |
| 38 var message = entry.message; | |
| 39 var commit = CTCommit.create(author, message, repositoryUrl, repository); | |
|
michaelpg
2014/08/20 19:32:32
This is a weird pattern to me, you're creating a c
Mathieu
2014/08/21 14:08:21
Done.
| |
| 40 | |
| 41 // Update the existing commit instead of creating a new one so that | |
| 42 // the data-binding properly updates all the <ct-commit>'s. | |
| 43 var existingCommit = this.commits[repository][commit.revision]; | |
| 44 if (existingCommit && !existingCommit.isComplete) { | |
| 45 existingCommit.complete(author, message); | |
| 46 return; | |
| 47 } | |
| 48 | |
| 37 this.commits[repository][commit.revision] = commit; | 49 this.commits[repository][commit.revision] = commit; |
| 38 }.bind(this)); | 50 }.bind(this)); |
| 39 | 51 |
| 40 this._findFirstAndLastRevisions(repository); | 52 this._findFirstAndLastRevisions(repository); |
| 41 } | 53 } |
| 42 | 54 |
| 43 CTCommitLog.prototype._findFirstAndLastRevisions = function(repository) { | 55 CTCommitLog.prototype._findFirstAndLastRevisions = function(repository) { |
| 44 var sortedCommits = Object.keys(this.commits[repository]).sort(); | 56 var sortedCommits = Object.keys(this.commits[repository]).sort(); |
| 45 this.firstRevision[repository] = parseInt(sortedCommits.first()); | 57 this.firstRevision[repository] = parseInt(sortedCommits.first()); |
| 46 this.lastRevision[repository] = parseInt(sortedCommits.last()); | 58 this.lastRevision[repository] = parseInt(sortedCommits.last()); |
| 47 } | 59 } |
| 48 | 60 |
| 49 CTCommitLog.prototype.range = function(repository, first, last) { | 61 CTCommitLog.prototype.range = function(repository, first, last) { |
| 50 var commits = []; | 62 var commits = []; |
| 51 for (var revision = first; revision <= last; revision++) { | 63 for (var revision = first; revision <= last; revision++) { |
| 52 // Until we've seen a commit we have data for, fill in dummy data | 64 var commit = this.commits[repository][revision]; |
| 53 // so that we show something. Assume that we have the correct data | 65 if (!commit) { |
| 54 // for all the commits after the first one we have data for. | 66 // FIXME: This is wrong. If we iterate through revisions and then later |
| 55 if (revision >= this.firstRevision[repository]) { | 67 // in handleReponse we realize that this revision doesn't actually exist |
| 56 var commit = this.commits[repository][revision]; | 68 // in the repo (e.g. because it corresponds to a branch commit), then we |
| 57 if (commit) | 69 // don't remove the incomplete commit. |
| 58 commits.push(commit); | 70 var url = this._repositories.repositories[repository].repositoryUrl; |
| 59 } else { | 71 commit = CTCommit.createIncomplete(url, revision, repository); |
| 60 var url = this._repositories.repositories[repository].repositoryUrl; | 72 this.commits[repository][revision] = commit; |
| 61 commits.push(CTCommit.createIncomplete(url, revision, repository)); | 73 } |
| 62 } | 74 |
| 75 if (commit) | |
| 76 commits.push(commit); | |
| 63 } | 77 } |
| 64 return commits; | 78 return commits; |
| 65 } | 79 } |
| 66 </script> | 80 </script> |
| OLD | NEW |