Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: Tools/GardeningServer/model/ct-commit-log.html

Issue 485253004: [Sheriff-o-matic] Remove race condition on the commit list. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: names Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
37 this.commits[repository][commit.revision] = commit; 38 var message = entry.message;
39 var revision = CTCommit.findRevision(message);
40
41 // Check for existing commit for that revision, and possibly complete it.
42 // We update the existing commit instead of creating a new one so that the
43 // data-binding properly updates all the <ct-commit>'s.
44 var existingCommit = this.commits[repository][revision];
45 if (existingCommit && !existingCommit.isComplete) {
46 existingCommit.complete(author, message, revision);
47 } else {
48 var commit = CTCommit.create(author, message, repositoryUrl, repository);
49 this.commits[repository][commit.revision] = commit;
50 }
38 }.bind(this)); 51 }.bind(this));
39 52
40 this._findFirstAndLastRevisions(repository); 53 this._findFirstAndLastRevisions(repository);
41 } 54 }
42 55
43 CTCommitLog.prototype._findFirstAndLastRevisions = function(repository) { 56 CTCommitLog.prototype._findFirstAndLastRevisions = function(repository) {
44 var sortedCommits = Object.keys(this.commits[repository]).sort(); 57 var sortedCommits = Object.keys(this.commits[repository]).sort();
45 this.firstRevision[repository] = parseInt(sortedCommits.first()); 58 this.firstRevision[repository] = parseInt(sortedCommits.first());
46 this.lastRevision[repository] = parseInt(sortedCommits.last()); 59 this.lastRevision[repository] = parseInt(sortedCommits.last());
47 } 60 }
48 61
49 CTCommitLog.prototype.range = function(repository, first, last) { 62 CTCommitLog.prototype.range = function(repository, first, last) {
50 var commits = []; 63 var commits = [];
51 for (var revision = first; revision <= last; revision++) { 64 for (var revision = first; revision <= last; revision++) {
52 // Until we've seen a commit we have data for, fill in dummy data 65 var commit = this.commits[repository][revision];
53 // so that we show something. Assume that we have the correct data 66 if (!commit) {
54 // for all the commits after the first one we have data for. 67 // FIXME: This is wrong. If we iterate through revisions and then later
55 if (revision >= this.firstRevision[repository]) { 68 // in handleReponse we realize that this revision doesn't actually exist
56 var commit = this.commits[repository][revision]; 69 // in the repo (e.g. because it corresponds to a branch commit), then we
57 if (commit) 70 // don't remove the incomplete commit.
58 commits.push(commit); 71 var url = this._repositories.repositories[repository].repositoryUrl;
59 } else { 72 commit = CTCommit.createIncomplete(url, revision, repository);
60 var url = this._repositories.repositories[repository].repositoryUrl; 73 this.commits[repository][revision] = commit;
61 commits.push(CTCommit.createIncomplete(url, revision, repository)); 74 }
62 } 75
76 if (commit)
77 commits.push(commit);
63 } 78 }
64 return commits; 79 return commits;
65 } 80 }
66 </script> 81 </script>
OLDNEW
« no previous file with comments | « Tools/GardeningServer/model/ct-commit-list-mock.html ('k') | Tools/GardeningServer/model/ct-commit-log-mock.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698