Skip to content

Commit

Permalink
[build.webkit.org] Replace Trac with commitStore
Browse files Browse the repository at this point in the history
rdar://118421383
https://bugs.webkit.org/show_bug.cgi?id=264842

Reviewed by Alexey Proskuryakov.

Remove code using trac.webkit.org and replace it with a CommitStore based on commits.webkit.org
which allows callers to both query for and store commit objects themselves.

* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/BuildbotIteration.js:
(BuildbotIteration.prototype._deprecatedUpdateWithData): No need to propigate revision to Queue,
it already has the revision data.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/BuildbotQueue.js:
(BuildbotQueue.prototype.compareIterationsByRevisions): Use commitStore instead of trac object.
(BuildbotQueue.prototype.updateIterationPosition): Deleted.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/BuildbotQueueView.js:
(BuildbotQueueView.prototype._presentPopoverForRevisionRange): Use commitStore instead of trac object.
(BuildbotQueueView.prototype._revisionContentWithPopoverForIteration): Ditto.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/CommitStore.js: Added.
(CommitStore): Base class for all CommitSores.
(CommitStore.prototype.update): Update cached commit information for all branches.
(CommitStore.prototype.repr): Return the string representation of a commit.
(CommitStore.prototype.startPeriodicUpdates): Periodically run the 'update' function.
(CommitStore.prototype.uuidFor): Convert commit object to UUID integer for sorting.
(CommitStore.prototype.addCommit): Add commit object to store.
(CommitStore.prototype.branchPosition): Return an integer indicating what position a commit is on
a branch. Note that for git repositories, this will be a position relative to the set of cached commits.
(CommitStore.prototype.nextRevision): Return the next-oldest commit for a commit ref.
(CommitStore.prototype.indexOfRef): Return local index of a specified commit.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/Commits.js: Removed.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/CommitsWebKitOrg.js: Added.
(CommitsWebKitOrg.prototype.urlFor): Return commits.webkit.org URL for the specified ref.
(CommitsWebKitOrg.prototype.fetch): Start processing of fetch specified number commits from specified ref.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/Initialization.js: Replace trac with commitStore.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/Main.js: Replace trac with commitStore.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/QueueView.js:
(QueueView.prototype._appendPendingRevisionCount): Replace trac with commitStore, handle overflow from
for relativel branch positions.
(QueueView.prototype._popoverLinesForCommitRange): Consult commitStore to determine how to stringify a commit.
(QueueView.prototype._presentPopoverForPendingCommits): Ditto.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/ResultsDatabase.js:
(ResultsDatabase): Draft class to demonstrate how CommitStore protocol is extended.
(ResultsDatabase.prototype.urlFor): Return results database URL for the specified ref.
(ResultsDatabase.prototype.fetch): Start processing of fetch specified number commits from specified branch.
* Tools/CISupport/build-webkit-org/public_html/dashboard/Scripts/Trac.js: Removed.
* Tools/CISupport/build-webkit-org/public_html/dashboard/index.html: Remove Trac, include CommitStores.

Canonical link: https://commits.webkit.org/270793@main
  • Loading branch information
JonWBedard committed Nov 16, 2023
1 parent 82d979d commit f7c26dc
Show file tree
Hide file tree
Showing 12 changed files with 367 additions and 536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ BuildbotIteration.prototype = {

this._parseData(data);

// Update the sorting since it is based on the revision numbers that just became known.
this.queue.updateIterationPosition(this);

this.dispatchEventToListeners(BuildbotIteration.Event.Updated);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,18 @@ BuildbotQueue.prototype = {

compareIterationsByRevisions: function(a, b)
{
var sortedRepositories = Dashboard.sortedRepositories;
for (var i = 0; i < sortedRepositories.length; ++i) {
var repositoryName = sortedRepositories[i].name;
var trac = sortedRepositories[i].trac;
console.assert(trac);
var indexA = trac.indexOfRevision(a.revision[repositoryName]);
var indexB = trac.indexOfRevision(b.revision[repositoryName]);
const sortedRepositories = Dashboard.sortedRepositories;
for (let i = 0; i < sortedRepositories.length; ++i) {
const repositoryName = sortedRepositories[i].name;
const commitStore = sortedRepositories[i].commitStore;
if (!commitStore)
return 0;

const indexA = commitStore.indexOfRef(a.revision[repositoryName]);
const indexB = commitStore.indexOfRef(b.revision[repositoryName]);

if (indexA !== -1 && indexB !== -1) {
var result = indexB - indexA;
let result = indexB - indexA;
if (result)
return result;
}
Expand All @@ -322,28 +325,6 @@ BuildbotQueue.prototype = {
return 0;
},

// Re-insert the iteration if its sort order changed (which happens once details about it get loaded).
updateIterationPosition: function(iteration)
{
var oldIndex;
var inserted = false;
for (var i = 0; i < this.iterations.length; ++i) {
if (!inserted && this.compareIterations(this.iterations[i], iteration) > 0) {
this.iterations.splice(i, 0, iteration);
if (oldIndex !== undefined)
break;
inserted = true;
continue;
}
if (this.iterations[i] === iteration) {
oldIndex = i;
if (inserted)
break;
}
}
this.iterations.splice(oldIndex, 1);
},

sortIterations: function()
{
this.iterations.sort(this.compareIterations.bind(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ BuildbotQueueView = function(queues)
queue.addEventListener(BuildbotQueue.Event.UnauthorizedAccess, this._unauthorizedAccess, this);
}.bind(this));

var sortedRepositories = Dashboard.sortedRepositories;
for (var i = 0; i < sortedRepositories.length; i++) {
var trac = sortedRepositories[i].trac;
if (trac)
trac.addEventListener(Trac.Event.CommitsUpdated, this._newCommitsRecorded, this);
const sortedRepositories = Dashboard.sortedRepositories;
for (let i = 0; i < sortedRepositories.length; i++) {
const commitStore = sortedRepositories[i].commitStore;
if (commitStore)
commitStore.addEventListener(CommitStore.Event.CommitsUpdated, this._newCommitsRecorded, this);
}
};

Expand Down Expand Up @@ -164,13 +164,13 @@ BuildbotQueueView.prototype = {

_presentPopoverForRevisionRange: function(element, popover, context)
{
var content = document.createElement("div");
let content = document.createElement("div");
content.className = "commit-history-popover";

// FIXME: Nothing guarantees that Trac has historical data for these revisions.
var linesForCommits = this._popoverLinesForCommitRange(context.trac, context.branch, context.firstRevision, context.lastRevision);
// FIXME: Nothing guarantees that the commitStore has historical data for these revisions.
const linesForCommits = this._popoverLinesForCommitRange(context.commitStore, context.branch, context.firstRevision, context.lastRevision);

var line = document.createElement("div");
let line = document.createElement("div");
line.className = "title";

if (linesForCommits.length) {
Expand All @@ -182,10 +182,10 @@ BuildbotQueueView.prototype = {
content.appendChild(line);
}

for (var i = 0; i != linesForCommits.length; ++i)
for (let i = 0; i != linesForCommits.length; ++i)
content.appendChild(linesForCommits[i]);

var rect = Dashboard.Rect.rectFromClientRect(element.getBoundingClientRect());
const rect = Dashboard.Rect.rectFromClientRect(element.getBoundingClientRect());
popover.content = content;
popover.present(rect, [Dashboard.RectEdge.MIN_Y, Dashboard.RectEdge.MAX_Y, Dashboard.RectEdge.MAX_X, Dashboard.RectEdge.MIN_X]);

Expand All @@ -194,39 +194,42 @@ BuildbotQueueView.prototype = {

_revisionContentWithPopoverForIteration: function(iteration, previousIteration, branch)
{
var repository = branch.repository;
var repositoryName = repository.name;
const repository = branch.repository;
const repositoryName = repository.name;
console.assert(iteration.revision[repositoryName]);
var trac = repository.trac;
var content = document.createElement("span");
const commitStore = repository.commitStore;
let content = document.createElement("span");
content.textContent = this._formatRevisionForDisplay(iteration.revision[repositoryName], repository);
content.classList.add("revision-number");

if (!previousIteration)
return content;
if (!commitStore)
return content;

var previousIterationRevision = previousIteration.revision[repositoryName];
const previousIterationRevision = previousIteration.revision[repositoryName];
console.assert(previousIterationRevision);
var previousIterationRevisionIndex = trac.indexOfRevision(previousIterationRevision);
const previousIterationRevisionIndex = commitStore.indexOfRef(previousIterationRevision);
if (previousIterationRevisionIndex === -1)
return content;

var firstRevision = trac.nextRevision(branch.name, previousIterationRevision);
if (firstRevision === Trac.NO_MORE_REVISIONS)
const firstRevision = commitStore.nextRevision(branch.name, previousIterationRevision);
if (firstRevision === CommitStore.NO_MORE_REVISIONS)
return content;
const firstRevisionIndex = commitStore.indexOfRef(firstRevision);
if (firstRevisionIndex < 0)
return content;
var firstRevisionIndex = trac.indexOfRevision(firstRevision);
console.assert(firstRevisionIndex !== -1);

var lastRevision = iteration.revision[repositoryName];
var lastRevisionIndex = trac.indexOfRevision(lastRevision);
const lastRevision = iteration.revision[repositoryName];
const lastRevisionIndex = commitStore.indexOfRef(lastRevision);
if (lastRevisionIndex === -1)
return content;

if (firstRevisionIndex > lastRevisionIndex)
return content;

var context = {
trac: trac,
const context = {
commitStore: commitStore,
branch: branch,
firstRevision: firstRevision,
lastRevision: lastRevision,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

CommitStore = function()
{
BaseObject.call(this);

this.commitsByBranch = {'main': []};
this.indexForCommit = {};
this.commitsByRef = {};
this.useIdentifiers = false;
};

BaseObject.addConstructorFunctions(CommitStore);

CommitStore.UpdateInterval = 45000; // 45 seconds
CommitStore.NO_MORE_REVISIONS = null;
CommitStore.UUID_MULTIPLIER = 100;
CommitStore.MAX_BLOCK = 20

CommitStore.Event = {
CommitsUpdated: "commits-updated",
};

CommitStore.prototype = {
constructor: CommitStore,
__proto__: BaseObject.prototype,

update: function() {
let self = this
Object.entries(self.commitsByBranch).forEach(function(branch){
self.fetch(branch[0], CommitStore.MAX_BLOCK);
});
},
repr: function(commit) {
if (this.useIdentifiers && commit.identifier)
return commit.identifier;
if (commit.hash)
return commit.hash;
return null;
},
startPeriodicUpdates: function() {
this.update()
this.updateTimer = setInterval(this.update.bind(this), CommitStore.UpdateInterval);
},
uuidFor: function(data) {
return data.timestamp * CommitStore.UUID_MULTIPLIER + data.order;
},
addCommit: function(commit) {
if (this.useIdentifiers)
this.commitsByRef[commit.identifier] = commit;
this.commitsByRef[commit.hash] = commit;

if (!this.commitsByBranch[commit.branch])
this.commitsByBranch[commit.branch] = [];

let index = 0;
let didInsert = false;
while (true) {
let currentValue = this.commitsByBranch[commit.branch][index];
if (currentValue && this.uuidFor(commit) == this.uuidFor(currentValue))
didInsert = true;
else if (!didInsert && (!currentValue || this.uuidFor(commit) > this.uuidFor(currentValue))) {
this.commitsByBranch[commit.branch] = [
...this.commitsByBranch[commit.branch].slice(0, index),
commit,
...this.commitsByBranch[commit.branch].slice(index)
];
currentValue = commit;
didInsert = true;
} else if (!currentValue) {
if (didInsert)
this.dispatchEventToListeners(CommitStore.Event.CommitsUpdated, null);
return;
}

if (this.useIdentifiers)
this.indexForCommit[currentValue.identifier] = index;
this.indexForCommit[currentValue.hash] = index;
index += 1;
}
},
branchPosition: function(ref) {
data = this.commitsByRef[ref];

if (!this.useIdentifiers) {
// Git repositories without identifiers can't give an absolute branch position
// instead, compute branch position relative to the set of commits we're aware of
const result = this.indexForCommit[ref];
if (result == null || !data)
return null;
return this.commitsByBranch[data.branch].length - result;
}

let identifierParts = ref.split('@');
if (data)
identifierParts = data.identifier.split('@');

if (identifierParts.length <= 1)
return null;
const identifierCount = identifierParts[0].split('.');
if (identifierCount.length == 1)
return Number(identifierCount[0]);
else if (identifierCount.length == 2)
return Number(identifierCount[1]);
return null
},
nextRevision: function(branchName, revision) {
const index = this.indexOfRef(revision);
if (index < 0)
return CommitStore.NO_MORE_REVISIONS;
const commitsOnBranch = this.commitsByBranch[branchName];
if (commitsOnBranch && index + 1 < commitsOnBranch.length)
return commitsOnBranch[index + 1].identifier;
return CommitStore.NO_MORE_REVISIONS;
},
indexOfRef: function(ref) {
const result = this.indexForCommit[ref];
return result == null ? -1 : result;
},
};
Loading

0 comments on commit f7c26dc

Please sign in to comment.