Skip to content

Commit 753b5bd

Browse files
committed
Account for RUST_SRC_URL var at runtime
1 parent ad728da commit 753b5bd

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

TUTORIAL.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ or (to avoid cloning rustc)
1717
RUST_SRC_REPO=/path/to/rust cargo install cargo-bisect-rustc
1818
```
1919

20-
The `RUST_SRC_REPO` should be a path to a git clone of the rust repo. If you
21-
don't specify it, it will look in the current directory for `rust.git` or
22-
check it out automatically if it's not there (only necessary if doing git hash
23-
bisections).
20+
The `RUST_SRC_REPO` should be a path to a git clone of the rust repo.
21+
The current order how `cargo-bisect-rustc` finds Rust repository path is:
22+
* `RUST_SRC_REPO` at runtime.
23+
* `rust.git` in current dir at runtime.
24+
* `RUST_SRC_REPO` that was set at compilation time.
25+
* Clone https://github.com/rust-lang/rust automatically
26+
(only necessary if doing git hash bisections).
2427

2528
First, if you have a nightly version of the compiler already installed
2629
as the default toolchain and you don't pass an end flag, the tool is
@@ -40,11 +43,6 @@ So, there's a bunch of ways to run the tool, the easiest one is to
4043
allow the tool to do the job and just run `cargo bisect-rustc` on the
4144
project and let the tool figure things out.
4245

43-
Note: you can also pass `RUST_SRC_REPO` env var, should be a path to a
44-
git clone of the rust repo. If you don't specify it, it will look in the
45-
current directory for `rust.git` or check it out automatically if it's
46-
not there (only necessary if doing git hash bisections).
47-
4846
## Finding a regression
4947

5048
Create a cargo project that demonstrates the regression. Let's use
@@ -134,7 +132,7 @@ d75458200516f06455d175adc001fd993d674050 bors Sat Jul 28 16:44:21 2018 +0000
134132
```
135133

136134
and we can, for example, pick the last commit on the day before the nightly,
137-
`6323d9a45bdf0ac2a9319a6a558537e0a7e6abd1`, as the start of the range, and the
135+
`6323d9a45bdf0ac2a9319a6a558537e0a7e6abd1`, as the start of the range, and the
138136
last commit on the day of the nightly, `866a713258915e6cbb212d135f751a6a8c9e1c0a`,
139137
as the end of the range.
140138

src/git.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const RUST_SRC_URL: &str = "https://github.com/rust-lang/rust";
44
const RUST_SRC_REPO: Option<&str> = option_env!("RUST_SRC_REPO");
55

6+
use std::env;
67
use std::path::Path;
78

89
use chrono::{TimeZone, Utc};
@@ -32,26 +33,27 @@ fn lookup_rev<'rev>(repo: &'rev Repository, rev: &str) -> Result<Git2Commit<'rev
3233
}
3334

3435
fn get_repo() -> Result<Repository, Error> {
35-
let loc = Path::new("rust.git");
36-
match (RUST_SRC_REPO, loc.exists()) {
37-
(Some(_), _) | (_, true) => {
38-
let path = RUST_SRC_REPO.map(Path::new).unwrap_or(loc);
39-
eprintln!("opening existing repository at {:?}", path);
40-
let repo = Repository::open(path)?;
41-
{
42-
eprintln!("refreshing repository");
43-
let mut remote = repo
44-
.find_remote("origin")
45-
.or_else(|_| repo.remote_anonymous("origin"))?;
46-
remote.fetch(&["master"], None, None)?;
47-
}
48-
Ok(repo)
36+
fn open(repo: &Path) -> Result<Repository, Error> {
37+
eprintln!("opening existing repository at {:?}", repo);
38+
let repo = Repository::open(repo)?;
39+
{
40+
eprintln!("refreshing repository");
41+
let mut remote = repo
42+
.find_remote("origin")
43+
.or_else(|_| repo.remote_anonymous("origin"))?;
44+
remote.fetch(&["master"], None, None)?;
4945
}
50-
(None, false) => {
46+
Ok(repo)
47+
}
48+
49+
let loc = Path::new("rust.git");
50+
match (env::var_os("RUST_SRC_REPO"), RUST_SRC_REPO) {
51+
(Some(repo), _) => open(Path::new(&repo)),
52+
(None, _) if loc.exists() => open(loc),
53+
(None, Some(repo)) => open(Path::new(repo)),
54+
_ => {
5155
eprintln!("cloning rust repository");
52-
Ok(RepoBuilder::new()
53-
.bare(true)
54-
.clone(RUST_SRC_URL, Path::new("rust.git"))?)
56+
Ok(RepoBuilder::new().bare(true).clone(RUST_SRC_URL, loc)?)
5557
}
5658
}
5759
}

0 commit comments

Comments
 (0)