@@ -23,6 +23,7 @@ pub(super) mod function {
2323 dry_run : bool ,
2424 worktree_dir : & Path ,
2525 destination_dir : PathBuf ,
26+ asset_dir : Option < BString > ,
2627 file : & OsStr ,
2728 Options { verbatim } : Options ,
2829 ) -> anyhow:: Result < ( ) > {
@@ -76,7 +77,8 @@ pub(super) mod function {
7677 . blame_path
7778 . expect ( "blame path to be present as `debug_track_path == true`" ) ;
7879
79- let assets = destination_dir. join ( "assets" ) ;
80+ let asset_dir = asset_dir. unwrap_or ( "assets" . into ( ) ) ;
81+ let assets = destination_dir. join ( asset_dir. to_os_str ( ) ?) ;
8082 eprintln ! ( "{prefix} create directory '{assets}'" , assets = assets. display( ) ) ;
8183
8284 if !dry_run {
@@ -107,7 +109,7 @@ pub(super) mod function {
107109 }
108110 }
109111
110- let mut blame_script = BlameScript :: new ( blame_infos, Options { verbatim } ) ;
112+ let mut blame_script = BlameScript :: new ( blame_infos, asset_dir , Options { verbatim } ) ;
111113 blame_script. generate ( ) ?;
112114
113115 let script_file = destination_dir. join ( "create-history.sh" ) ;
@@ -130,9 +132,9 @@ pub(super) mod function {
130132 }
131133
132134 enum BlameScriptOperation {
133- InitRepository ,
135+ InitRepository ( BString ) ,
134136 RemoveFile ( String ) ,
135- CommitFile ( BString , ObjectId ) ,
137+ CommitFile ( BString , BString , ObjectId ) ,
136138 CheckoutTag ( ObjectId ) ,
137139 PrepareMerge ( Vec < ObjectId > ) ,
138140 CreateTag ( ObjectId ) ,
@@ -141,15 +143,15 @@ pub(super) mod function {
141143 impl Display for BlameScriptOperation {
142144 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
143145 match self {
144- BlameScriptOperation :: InitRepository => write ! (
146+ BlameScriptOperation :: InitRepository ( asset_dir ) => write ! (
145147 f,
146148 r"#!/bin/sh
147149
148150set -e
149151
150152git init
151153echo .gitignore >> .gitignore
152- echo assets / >> .gitignore
154+ echo {asset_dir} / >> .gitignore
153155echo create-history.sh >> .gitignore
154156
155157"
@@ -160,16 +162,15 @@ echo create-history.sh >> .gitignore
160162git rm {src}
161163"
162164 ) ,
163- BlameScriptOperation :: CommitFile ( src, commit_id) => {
165+ BlameScriptOperation :: CommitFile ( asset_dir , src, commit_id) => {
164166 writeln ! ( f, r"# make file {src} contain content at commit {commit_id}" ) ?;
165167 if let Some ( pos) = src. rfind_byte ( b'/' ) {
166168 let dirname = src[ ..pos] . as_bstr ( ) ;
167169 writeln ! ( f, "mkdir -p \" {dirname}\" " ) ?;
168170 }
169171 write ! (
170172 f,
171- r"#
172- cp ./assets/{commit_id}.commit ./{src}
173+ r"cp ./{asset_dir}/{commit_id}.commit ./{src}
173174git add {src}
174175git commit -m {commit_id}
175176"
@@ -194,17 +195,19 @@ git commit -m {commit_id}
194195 blame_infos : Vec < BlamePathEntry > ,
195196 seen : BTreeSet < ObjectId > ,
196197 script : Vec < BlameScriptOperation > ,
198+ asset_dir : BString ,
197199 options : Options ,
198200 }
199201
200202 impl BlameScript {
201- fn new ( blame_infos : Vec < BlamePathEntry > , options : Options ) -> Self {
202- let script = vec ! [ BlameScriptOperation :: InitRepository ] ;
203+ fn new ( blame_infos : Vec < BlamePathEntry > , asset_dir : BString , options : Options ) -> Self {
204+ let script = vec ! [ BlameScriptOperation :: InitRepository ( asset_dir . clone ( ) ) ] ;
203205
204206 Self {
205207 blame_infos,
206208 seen : BTreeSet :: default ( ) ,
207209 script,
210+ asset_dir,
208211 options,
209212 }
210213 }
@@ -265,7 +268,8 @@ git commit -m {commit_id}
265268 if let Some ( delete_previous_file_operation) = delete_previous_file_operation {
266269 self . script . push ( delete_previous_file_operation) ;
267270 }
268- self . script . push ( BlameScriptOperation :: CommitFile ( src, commit_id) ) ;
271+ self . script
272+ . push ( BlameScriptOperation :: CommitFile ( self . asset_dir . clone ( ) , src, commit_id) ) ;
269273 } else {
270274 let ( [ first] , rest) = parents. split_at ( 1 ) else {
271275 unreachable ! ( ) ;
@@ -277,7 +281,8 @@ git commit -m {commit_id}
277281 if let Some ( delete_previous_file_operation) = delete_previous_file_operation {
278282 self . script . push ( delete_previous_file_operation) ;
279283 }
280- self . script . push ( BlameScriptOperation :: CommitFile ( src, commit_id) ) ;
284+ self . script
285+ . push ( BlameScriptOperation :: CommitFile ( self . asset_dir . clone ( ) , src, commit_id) ) ;
281286 } else {
282287 self . script . push ( BlameScriptOperation :: PrepareMerge (
283288 rest. iter ( ) . map ( |blame_path_entry| blame_path_entry. commit_id ) . collect ( ) ,
@@ -286,7 +291,8 @@ git commit -m {commit_id}
286291 if let Some ( delete_previous_file_operation) = delete_previous_file_operation {
287292 self . script . push ( delete_previous_file_operation) ;
288293 }
289- self . script . push ( BlameScriptOperation :: CommitFile ( src, commit_id) ) ;
294+ self . script
295+ . push ( BlameScriptOperation :: CommitFile ( self . asset_dir . clone ( ) , src, commit_id) ) ;
290296 }
291297 }
292298
0 commit comments