@@ -13,6 +13,7 @@ pub(super) mod function {
13
13
use std:: {
14
14
collections:: BTreeSet ,
15
15
ffi:: OsStr ,
16
+ fmt:: Display ,
16
17
path:: { Path , PathBuf } ,
17
18
} ;
18
19
@@ -133,7 +134,7 @@ pub(super) mod function {
133
134
let blocks: Vec < _ > = blame_script
134
135
. script
135
136
. iter ( )
136
- . map ( |operation| operation . to_string ( ) )
137
+ . map ( std :: string :: ToString :: to_string)
137
138
. collect ( ) ;
138
139
139
140
std:: fs:: write ( script_file, blocks. join ( "" ) ) ?;
@@ -151,10 +152,12 @@ pub(super) mod function {
151
152
CreateTag ( ObjectId ) ,
152
153
}
153
154
154
- impl BlameScriptOperation {
155
- fn to_string ( & self ) -> String {
155
+ impl Display for BlameScriptOperation {
156
+ fn fmt ( & self , f : & mut std :: fmt :: Formatter < ' _ > ) -> std :: fmt :: Result {
156
157
match self {
157
- BlameScriptOperation :: InitRepository => r"#!/bin/sh
158
+ BlameScriptOperation :: InitRepository => write ! (
159
+ f,
160
+ r"#!/bin/sh
158
161
159
162
set -e
160
163
@@ -164,13 +167,15 @@ echo assets/ >> .gitignore
164
167
echo create-history.sh >> .gitignore
165
168
166
169
"
167
- . into ( ) ,
168
- BlameScriptOperation :: RemoveFile ( src) => format ! (
170
+ ) ,
171
+ BlameScriptOperation :: RemoveFile ( src) => write ! (
172
+ f,
169
173
r"# delete previous version of file
170
174
git rm {src}
171
175
"
172
176
) ,
173
- BlameScriptOperation :: CommitFile ( src, commit_id) => format ! (
177
+ BlameScriptOperation :: CommitFile ( src, commit_id) => write ! (
178
+ f,
174
179
r"# make file {src} contain content at commit {commit_id}
175
180
mkdir -p $(dirname {src})
176
181
cp ./assets/{commit_id}.commit ./{src}
@@ -179,16 +184,17 @@ git add {src}
179
184
git commit -m {commit_id}
180
185
"
181
186
) ,
182
- BlameScriptOperation :: CheckoutTag ( commit_id) => format ! ( "git checkout tag-{}\n " , commit_id) ,
183
- BlameScriptOperation :: PrepareMerge ( commit_ids) => format ! (
184
- "git merge --no-commit {} || true\n " ,
187
+ BlameScriptOperation :: CheckoutTag ( commit_id) => writeln ! ( f, "git checkout tag-{commit_id}" ) ,
188
+ BlameScriptOperation :: PrepareMerge ( commit_ids) => writeln ! (
189
+ f,
190
+ "git merge --no-commit {} || true" ,
185
191
commit_ids
186
192
. iter( )
187
193
. map( |commit_id| format!( "tag-{commit_id}" ) )
188
194
. collect:: <Vec <_>>( )
189
195
. join( " " )
190
196
) ,
191
- BlameScriptOperation :: CreateTag ( commit_id) => format ! ( "git tag tag-{commit_id}\n \n " ) ,
197
+ BlameScriptOperation :: CreateTag ( commit_id) => write ! ( f , "git tag tag-{commit_id}\n \n " ) ,
192
198
}
193
199
}
194
200
}
0 commit comments