1
+ use std:: io:: Write ;
1
2
use std:: ops:: Not ;
2
3
use std:: path:: PathBuf ;
3
- use std:: { env, net, process} ;
4
- use std:: io:: Write ;
5
4
use std:: time:: Duration ;
6
- use anyhow:: { anyhow, bail, Context } ;
7
- use xshell:: { cmd, Shell } ;
5
+ use std:: { env, net, process} ;
6
+
7
+ use anyhow:: { Context , anyhow, bail} ;
8
+ use xshell:: { Shell , cmd} ;
8
9
9
10
/// Used for rustc syncs.
10
11
const JOSH_FILTER : & str = ":/src/doc/rustc-dev-guide" ;
@@ -15,10 +16,13 @@ pub enum RustcPullError {
15
16
/// No changes are available to be pulled.
16
17
NothingToPull ,
17
18
/// A rustc-pull has failed, probably a git operation error has occurred.
18
- PullFailed ( anyhow:: Error )
19
+ PullFailed ( anyhow:: Error ) ,
19
20
}
20
21
21
- impl < E > From < E > for RustcPullError where E : Into < anyhow:: Error > {
22
+ impl < E > From < E > for RustcPullError
23
+ where
24
+ E : Into < anyhow:: Error > ,
25
+ {
22
26
fn from ( error : E ) -> Self {
23
27
Self :: PullFailed ( error. into ( ) )
24
28
}
@@ -32,9 +36,7 @@ pub struct GitSync {
32
36
/// (https://github.com/rust-lang/miri/blob/6a68a79f38064c3bc30617cca4bdbfb2c336b140/miri-script/src/commands.rs#L236).
33
37
impl GitSync {
34
38
pub fn from_current_dir ( ) -> anyhow:: Result < Self > {
35
- Ok ( Self {
36
- dir : std:: env:: current_dir ( ) ?
37
- } )
39
+ Ok ( Self { dir : std:: env:: current_dir ( ) ? } )
38
40
}
39
41
40
42
pub fn rustc_pull ( & self , commit : Option < String > ) -> Result < ( ) , RustcPullError > {
@@ -51,7 +53,10 @@ impl GitSync {
51
53
} ) ?;
52
54
// Make sure the repo is clean.
53
55
if cmd ! ( sh, "git status --untracked-files=no --porcelain" ) . read ( ) ?. is_empty ( ) . not ( ) {
54
- return Err ( anyhow:: anyhow!( "working directory must be clean before performing rustc pull" ) . into ( ) ) ;
56
+ return Err ( anyhow:: anyhow!(
57
+ "working directory must be clean before performing rustc pull"
58
+ )
59
+ . into ( ) ) ;
55
60
}
56
61
// Make sure josh is running.
57
62
let josh = Self :: start_josh ( ) ?;
@@ -94,26 +99,33 @@ impl GitSync {
94
99
} ;
95
100
let num_roots_before = num_roots ( ) ?;
96
101
97
- let sha = cmd ! ( sh, "git rev-parse HEAD" ) . output ( ) . context ( "FAILED to get current commit" ) ?. stdout ;
102
+ let sha =
103
+ cmd ! ( sh, "git rev-parse HEAD" ) . output ( ) . context ( "FAILED to get current commit" ) ?. stdout ;
98
104
99
105
// Merge the fetched commit.
100
106
const MERGE_COMMIT_MESSAGE : & str = "Merge from rustc" ;
101
107
cmd ! ( sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}" )
102
108
. run ( )
103
109
. context ( "FAILED to merge new commits, something went wrong" ) ?;
104
110
105
- let current_sha = cmd ! ( sh, "git rev-parse HEAD" ) . output ( ) . context ( "FAILED to get current commit" ) ?. stdout ;
111
+ let current_sha =
112
+ cmd ! ( sh, "git rev-parse HEAD" ) . output ( ) . context ( "FAILED to get current commit" ) ?. stdout ;
106
113
if current_sha == sha {
107
114
cmd ! ( sh, "git reset --hard HEAD^" )
108
115
. run ( )
109
116
. expect ( "FAILED to clean up after creating the preparation commit" ) ;
110
- eprintln ! ( "No merge was performed, no changes to pull were found. Rolled back the preparation commit." ) ;
117
+ eprintln ! (
118
+ "No merge was performed, no changes to pull were found. Rolled back the preparation commit."
119
+ ) ;
111
120
return Err ( RustcPullError :: NothingToPull ) ;
112
121
}
113
122
114
123
// Check that the number of roots did not increase.
115
124
if num_roots ( ) ? != num_roots_before {
116
- return Err ( anyhow:: anyhow!( "Josh created a new root commit. This is probably not the history you want." ) . into ( ) ) ;
125
+ return Err ( anyhow:: anyhow!(
126
+ "Josh created a new root commit. This is probably not the history you want."
127
+ )
128
+ . into ( ) ) ;
117
129
}
118
130
119
131
drop ( josh) ;
0 commit comments