Skip to content

Commit b1441a5

Browse files
Merge pull request #1357 from rust-lang/commit-type
Explicitly mark commits as being try or master instead of relying on their date
2 parents 0e2752d + e01ab16 commit b1441a5

File tree

8 files changed

+65
-22
lines changed

8 files changed

+65
-22
lines changed

collector/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use anyhow::{bail, Context};
44
use clap::Parser;
55
use collector::category::Category;
6-
use database::{ArtifactId, Commit};
6+
use database::{ArtifactId, Commit, CommitType};
77
use log::debug;
88
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
99
use std::collections::HashMap;
@@ -1376,12 +1376,14 @@ pub fn get_commit_or_fake_it(sha: &str) -> anyhow::Result<Commit> {
13761376
.map(|c| Commit {
13771377
sha: c.sha.as_str().into(),
13781378
date: c.time.into(),
1379+
r#type: CommitType::Master,
13791380
})
13801381
.unwrap_or_else(|| {
13811382
log::warn!("utilizing fake commit!");
13821383
Commit {
13831384
sha: sha.into(),
13841385
date: database::Date::ymd_hms(2000, 01, 01, 0, 0, 0),
1386+
r#type: CommitType::Master,
13851387
}
13861388
}))
13871389
}

database/src/bin/ingest-json.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,7 @@ async fn ingest<T: Ingesting>(conn: &T, caches: &mut IdCache, path: &Path) {
880880
let (name, date, ty, benchmarks) = match res {
881881
Res::Commit(cd) => (
882882
cd.commit.sha.to_string(),
883-
if cd.commit.is_try() {
884-
None
885-
} else {
886-
Some(cd.commit.date.0)
887-
},
883+
Some(cd.commit.date.0),
888884
if cd.commit.is_try() { "try" } else { "master" },
889885
cd.benchmarks,
890886
),

database/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use chrono::offset::TimeZone;
2-
use chrono::{DateTime, Datelike, NaiveDate, Utc};
2+
use chrono::{DateTime, Datelike, Utc};
33
use hashbrown::HashMap;
44
use intern::intern;
55
use serde::{Deserialize, Serialize};
@@ -148,16 +148,34 @@ impl<'de> Deserialize<'de> for Date {
148148
}
149149
}
150150

151+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
152+
pub enum CommitType {
153+
Try,
154+
Master,
155+
}
156+
157+
impl FromStr for CommitType {
158+
type Err = String;
159+
160+
fn from_str(ty: &str) -> Result<Self, Self::Err> {
161+
match ty {
162+
"try" => Ok(CommitType::Try),
163+
"master" => Ok(CommitType::Master),
164+
_ => Err(format!("Wrong commit type {}", ty)),
165+
}
166+
}
167+
}
168+
151169
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
152170
pub struct Commit {
153171
pub sha: String,
154172
pub date: Date,
173+
pub r#type: CommitType,
155174
}
156175

157176
impl Commit {
158177
pub fn is_try(&self) -> bool {
159-
self.date.0.naive_utc().date() == NaiveDate::from_ymd(2000, 1, 1)
160-
|| self.date.0.naive_utc().date() == NaiveDate::from_ymd(2001, 1, 1)
178+
matches!(self.r#type, CommitType::Try)
161179
}
162180
}
163181

@@ -298,6 +316,7 @@ impl Scenario {
298316
}
299317

300318
use std::cmp::Ordering;
319+
use std::str::FromStr;
301320

302321
// We sort println before all other patches.
303322
impl Ord for Scenario {

database/src/pool/postgres.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, Date, Index,
4-
Profile, QueuedCommit, Scenario,
3+
ArtifactId, ArtifactIdNumber, Benchmark, BenchmarkData, CollectionId, Commit, CommitType, Date,
4+
Index, Profile, QueuedCommit, Scenario,
55
};
66
use anyhow::Context as _;
77
use chrono::{DateTime, TimeZone, Utc};
88
use hashbrown::HashMap;
99
use native_tls::{Certificate, TlsConnector};
1010
use postgres_native_tls::MakeTlsConnector;
1111
use std::convert::TryFrom;
12+
use std::str::FromStr;
1213
use std::sync::Arc;
1314
use std::time::Duration;
1415
use tokio_postgres::GenericClient;
@@ -479,7 +480,7 @@ where
479480
commits: self
480481
.conn()
481482
.query(
482-
"select id, name, date from artifact where type = 'master' or type = 'try'",
483+
"select id, name, date, type from artifact where type = 'master' or type = 'try'",
483484
&[],
484485
)
485486
.await
@@ -497,6 +498,7 @@ where
497498
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
498499
}
499500
},
501+
r#type: CommitType::from_str(&row.get::<_, String>(3)).unwrap()
500502
},
501503
)
502504
})
@@ -1009,6 +1011,7 @@ where
10091011
.get::<_, Option<_>>(1)
10101012
.map(Date)
10111013
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
1014+
r#type: CommitType::from_str(&ty).unwrap(),
10121015
}),
10131016
"release" => ArtifactId::Tag(row.get(0)),
10141017
_ => {
@@ -1198,10 +1201,14 @@ where
11981201
"master" => Some(ArtifactId::Commit(Commit {
11991202
sha: artifact.to_owned(),
12001203
date: Date(date.expect("date present for master commits")),
1204+
r#type: CommitType::Master,
12011205
})),
12021206
"try" => Some(ArtifactId::Commit(Commit {
12031207
sha: artifact.to_owned(),
1204-
date: Date::ymd_hms(2000, 1, 1, 0, 0, 0),
1208+
date: date
1209+
.map(Date)
1210+
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
1211+
r#type: CommitType::Try,
12051212
})),
12061213
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
12071214
_ => panic!("unknown artifact type: {:?}", ty),

database/src/pool/sqlite.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
2-
use crate::{ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, Date, Profile};
2+
use crate::{
3+
ArtifactId, Benchmark, BenchmarkData, CollectionId, Commit, CommitType, Date, Profile,
4+
};
35
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
46
use chrono::{DateTime, TimeZone, Utc};
57
use hashbrown::HashMap;
68
use rusqlite::params;
79
use rusqlite::OptionalExtension;
810
use std::convert::TryFrom;
911
use std::path::PathBuf;
12+
use std::str::FromStr;
1013
use std::sync::Mutex;
1114
use std::sync::Once;
1215
use std::time::Duration;
@@ -402,7 +405,9 @@ impl Connection for SqliteConnection {
402405
async fn load_index(&mut self) -> Index {
403406
let commits = self
404407
.raw()
405-
.prepare("select id, name, date from artifact where type = 'master' or type = 'try'")
408+
.prepare(
409+
"select id, name, date, type from artifact where type = 'master' or type = 'try'",
410+
)
406411
.unwrap()
407412
.query_map(params![], |row| {
408413
Ok((
@@ -416,6 +421,7 @@ impl Connection for SqliteConnection {
416421
None => Date(Utc.ymd(2001, 01, 01).and_hms(0, 0, 0)),
417422
}
418423
},
424+
r#type: CommitType::from_str(&row.get::<_, String>(3)?).unwrap(),
419425
},
420426
))
421427
})
@@ -696,11 +702,7 @@ impl Connection for SqliteConnection {
696702
let (name, date, ty) = match artifact {
697703
crate::ArtifactId::Commit(commit) => (
698704
commit.sha.to_string(),
699-
if commit.is_try() {
700-
None
701-
} else {
702-
Some(commit.date.0)
703-
},
705+
Some(commit.date.0),
704706
if commit.is_try() { "try" } else { "master" },
705707
),
706708
crate::ArtifactId::Tag(a) => (a.clone(), None, "release"),
@@ -894,6 +896,7 @@ impl Connection for SqliteConnection {
894896
.map(|d| Utc.timestamp(d, 0))
895897
.map(Date)
896898
.unwrap_or_else(|| Date::ymd_hms(2001, 01, 01, 0, 0, 0)),
899+
r#type: CommitType::from_str(&ty).unwrap(),
897900
}),
898901
"release" => ArtifactId::Tag(name),
899902
_ => {
@@ -1091,10 +1094,14 @@ impl Connection for SqliteConnection {
10911094
"master" => Some(ArtifactId::Commit(Commit {
10921095
sha: artifact.to_owned(),
10931096
date: Date(Utc.timestamp(date.expect("master has date"), 0)),
1097+
r#type: CommitType::Master,
10941098
})),
10951099
"try" => Some(ArtifactId::Commit(Commit {
10961100
sha: artifact.to_owned(),
1097-
date: Date::ymd_hms(2000, 1, 1, 0, 0, 0),
1101+
date: date
1102+
.map(|d| Date(Utc.timestamp(d, 0)))
1103+
.unwrap_or_else(|| Date::ymd_hms(2000, 1, 1, 0, 0, 0)),
1104+
r#type: CommitType::Try,
10981105
})),
10991106
"release" => Some(ArtifactId::Tag(artifact.to_owned())),
11001107
_ => panic!("unknown artifact type: {:?}", ty),

site/src/comparison.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use collector::category::Category;
1212
use collector::Bound;
1313
use serde::{Deserialize, Serialize};
1414

15+
use database::CommitType;
1516
use std::cmp::Ordering;
1617
use std::collections::{HashMap, HashSet};
1718
use std::error::Error;
@@ -753,6 +754,7 @@ fn previous_commits(
753754
let new = ArtifactId::Commit(database::Commit {
754755
sha: c.sha.clone(),
755756
date: database::Date(c.time),
757+
r#type: CommitType::Master,
756758
});
757759
from = new.clone();
758760
prevs.push(new);

site/src/load.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use serde::{Deserialize, Serialize};
1212

1313
use crate::db;
1414
use collector::{category::Category, Bound, MasterCommit};
15-
use database::Date;
1615
use database::Pool;
1716
pub use database::{ArtifactId, Benchmark, Commit};
17+
use database::{CommitType, Date};
1818

1919
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
2020
pub enum MissingReason {
@@ -284,6 +284,7 @@ fn calculate_missing_from(
284284
Commit {
285285
sha: c.sha,
286286
date: Date(c.time),
287+
r#type: CommitType::Master,
287288
},
288289
// All recent master commits should have an associated PR
289290
MissingReason::Master {
@@ -322,6 +323,7 @@ fn calculate_missing_from(
322323
Commit {
323324
sha: sha.to_string(),
324325
date: Date::ymd_hms(2001, 01, 01, 0, 0, 0),
326+
r#type: CommitType::Try,
325327
},
326328
MissingReason::Try {
327329
pr,
@@ -524,6 +526,7 @@ mod tests {
524526
Commit {
525527
sha: "b".into(),
526528
date: database::Date(time),
529+
r#type: CommitType::Master,
527530
},
528531
MissingReason::Master {
529532
pr: 1,
@@ -535,6 +538,7 @@ mod tests {
535538
Commit {
536539
sha: "a".into(),
537540
date: database::Date(time),
541+
r#type: CommitType::Master,
538542
},
539543
MissingReason::Master {
540544
pr: 2,
@@ -546,6 +550,7 @@ mod tests {
546550
Commit {
547551
sha: "try-on-a".into(),
548552
date: database::Date(time),
553+
r#type: CommitType::Try,
549554
},
550555
MissingReason::Try {
551556
pr: 3,
@@ -625,6 +630,7 @@ mod tests {
625630
Commit {
626631
sha: "123".into(),
627632
date: database::Date(time),
633+
r#type: CommitType::Master,
628634
},
629635
MissingReason::Master {
630636
pr: 11,
@@ -636,6 +642,7 @@ mod tests {
636642
Commit {
637643
sha: "foo".into(),
638644
date: database::Date(time),
645+
r#type: CommitType::Master,
639646
},
640647
MissingReason::Master {
641648
pr: 77,
@@ -647,6 +654,7 @@ mod tests {
647654
Commit {
648655
sha: "baz".into(),
649656
date: database::Date(time),
657+
r#type: CommitType::Try,
650658
},
651659
MissingReason::Try {
652660
pr: 101,

site/src/request_handlers/self_profile.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::sync::Arc;
44
use std::time::{Duration, Instant};
55

66
use bytes::Buf;
7+
use database::CommitType;
78
use headers::{ContentType, Header};
89
use hyper::StatusCode;
910

@@ -494,6 +495,7 @@ pub async fn handle_self_profile_raw(
494495
ArtifactId::Commit(database::Commit {
495496
sha: body.commit.clone(),
496497
date: database::Date::empty(),
498+
r#type: CommitType::Master,
497499
}),
498500
bench_name,
499501
profile,

0 commit comments

Comments
 (0)