@@ -13,6 +13,7 @@ pub(super) mod function {
1313 use std:: {
1414 collections:: BTreeSet ,
1515 ffi:: OsStr ,
16+ fmt:: Display ,
1617 path:: { Path , PathBuf } ,
1718 } ;
1819
@@ -133,7 +134,7 @@ pub(super) mod function {
133134 let blocks: Vec < _ > = blame_script
134135 . script
135136 . iter ( )
136- . map ( |operation| operation . to_string ( ) )
137+ . map ( std :: string :: ToString :: to_string)
137138 . collect ( ) ;
138139
139140 std:: fs:: write ( script_file, blocks. join ( "" ) ) ?;
@@ -151,10 +152,12 @@ pub(super) mod function {
151152 CreateTag ( ObjectId ) ,
152153 }
153154
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 {
156157 match self {
157- BlameScriptOperation :: InitRepository => r"#!/bin/sh
158+ BlameScriptOperation :: InitRepository => write ! (
159+ f,
160+ r"#!/bin/sh
158161
159162set -e
160163
@@ -164,13 +167,15 @@ echo assets/ >> .gitignore
164167echo create-history.sh >> .gitignore
165168
166169"
167- . into ( ) ,
168- BlameScriptOperation :: RemoveFile ( src) => format ! (
170+ ) ,
171+ BlameScriptOperation :: RemoveFile ( src) => write ! (
172+ f,
169173 r"# delete previous version of file
170174git rm {src}
171175"
172176 ) ,
173- BlameScriptOperation :: CommitFile ( src, commit_id) => format ! (
177+ BlameScriptOperation :: CommitFile ( src, commit_id) => write ! (
178+ f,
174179 r"# make file {src} contain content at commit {commit_id}
175180mkdir -p $(dirname {src})
176181cp ./assets/{commit_id}.commit ./{src}
@@ -179,16 +184,17 @@ git add {src}
179184git commit -m {commit_id}
180185"
181186 ) ,
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" ,
185191 commit_ids
186192 . iter( )
187193 . map( |commit_id| format!( "tag-{commit_id}" ) )
188194 . collect:: <Vec <_>>( )
189195 . join( " " )
190196 ) ,
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 " ) ,
192198 }
193199 }
194200 }
0 commit comments