Skip to content

Commit fb41a96

Browse files
authored
Merge pull request #107 from lzutao/dyn
Add support for RUST_SRC_URL var at runtime
2 parents 4d6fc9f + 753b5bd commit fb41a96

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
@@ -25,10 +25,13 @@ or (to avoid cloning rustc)
2525
RUST_SRC_REPO=/path/to/rust cargo install cargo-bisect-rustc
2626
```
2727

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

3336
First, if you have a nightly version of the compiler already installed
3437
as the default toolchain and you don't pass an end flag, the tool is
@@ -48,11 +51,6 @@ So, there's a bunch of ways to run the tool, the easiest one is to
4851
allow the tool to do the job and just run `cargo bisect-rustc` on the
4952
project and let the tool figure things out.
5053

51-
Note: you can also pass `RUST_SRC_REPO` env var, should be a path to a
52-
git clone of the rust repo. If you don't specify it, it will look in the
53-
current directory for `rust.git` or check it out automatically if it's
54-
not there (only necessary if doing git hash bisections).
55-
5654
## Finding a regression
5755

5856
Create a cargo project that demonstrates the regression. Let's use
@@ -142,7 +140,7 @@ d75458200516f06455d175adc001fd993d674050 bors Sat Jul 28 16:44:21 2018 +0000
142140
```
143141

144142
and we can, for example, pick the last commit on the day before the nightly,
145-
`6323d9a45bdf0ac2a9319a6a558537e0a7e6abd1`, as the start of the range, and the
143+
`6323d9a45bdf0ac2a9319a6a558537e0a7e6abd1`, as the start of the range, and the
146144
last commit on the day of the nightly, `866a713258915e6cbb212d135f751a6a8c9e1c0a`,
147145
as the end of the range.
148146

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)