@@ -6,7 +6,7 @@ pub(super) mod function {
66 use anyhow:: Context ;
77 use gix:: {
88 blame:: BlamePathEntry ,
9- bstr:: { BStr , BString , ByteSlice } ,
9+ bstr:: { BString , ByteSlice } ,
1010 objs:: FindExt ,
1111 ObjectId ,
1212 } ;
@@ -72,14 +72,11 @@ pub(super) mod function {
7272 options,
7373 ) ?;
7474
75- let blame_path = outcome
75+ let blame_infos = outcome
7676 . blame_path
7777 . expect ( "blame path to be present as `debug_track_path == true`" ) ;
7878
79- // TODO
80- // Potentially make `"assets"` configurable (it is in `git_to_sh`).
8179 let assets = destination_dir. join ( "assets" ) ;
82-
8380 eprintln ! ( "{prefix} create directory '{assets}'" , assets = assets. display( ) ) ;
8481
8582 if !dry_run {
@@ -88,17 +85,9 @@ pub(super) mod function {
8885
8986 let mut buf = Vec :: new ( ) ;
9087
91- for blame_path_entry in & blame_path {
92- let src : & BStr = blame_path_entry . source_file_path . as_bstr ( ) ;
88+ eprintln ! ( "{prefix} perform {} asset copy operations" , blame_infos . len ( ) , ) ;
89+ for blame_path_entry in & blame_infos {
9390 let dst = assets. join ( format ! ( "{}.commit" , blame_path_entry. commit_id) ) ;
94-
95- eprintln ! (
96- "{prefix} copy file '{}' at commit {} to '{dst}'" ,
97- src,
98- blame_path_entry. commit_id,
99- dst = dst. display( )
100- ) ;
101-
10291 if !dry_run {
10392 let blob = repo. objects . find_blob ( & blame_path_entry. blob_id , & mut buf) ?. data ;
10493
@@ -113,18 +102,15 @@ pub(super) mod function {
113102 } ) ?;
114103
115104 let blob = crate :: commands:: copy_royal:: remapped ( blob) ;
116-
117105 std:: fs:: write ( dst, blob) ?;
118106 }
119107 }
120108 }
121109
122- let mut blame_script = BlameScript :: new ( blame_path, Options { verbatim } ) ;
123-
110+ let mut blame_script = BlameScript :: new ( blame_infos, Options { verbatim } ) ;
124111 blame_script. generate ( ) ?;
125112
126113 let script_file = destination_dir. join ( "create-history.sh" ) ;
127-
128114 eprintln ! (
129115 "{prefix} write script file at '{script_file}'" ,
130116 script_file = script_file. display( )
@@ -174,16 +160,25 @@ echo create-history.sh >> .gitignore
174160git rm {src}
175161"
176162 ) ,
177- BlameScriptOperation :: CommitFile ( src, commit_id) => write ! (
178- f,
179- r"# make file {src} contain content at commit {commit_id}
180- mkdir -p $(dirname {src})
163+ BlameScriptOperation :: CommitFile ( src, commit_id) => {
164+ write ! (
165+ f,
166+ r"# make file {src} contain content at commit {commit_id}
167+ "
168+ ) ?;
169+ if let Some ( pos) = src. rfind_byte ( b'/' ) {
170+ let dirname = src[ ..pos] . as_bstr ( ) ;
171+ write ! ( f, "mkdir -p \" {dirname}\" \n " ) ?;
172+ }
173+ write ! (
174+ f,
175+ r"#
181176cp ./assets/{commit_id}.commit ./{src}
182- # create commit
183177git add {src}
184178git commit -m {commit_id}
185179"
186- ) ,
180+ )
181+ }
187182 BlameScriptOperation :: CheckoutTag ( commit_id) => writeln ! ( f, "git checkout tag-{commit_id}" ) ,
188183 BlameScriptOperation :: PrepareMerge ( commit_ids) => writeln ! (
189184 f,
@@ -200,18 +195,18 @@ git commit -m {commit_id}
200195 }
201196
202197 struct BlameScript {
203- blame_path : Vec < BlamePathEntry > ,
198+ blame_infos : Vec < BlamePathEntry > ,
204199 seen : BTreeSet < ObjectId > ,
205200 script : Vec < BlameScriptOperation > ,
206201 options : Options ,
207202 }
208203
209204 impl BlameScript {
210- fn new ( blame_path : Vec < BlamePathEntry > , options : Options ) -> Self {
205+ fn new ( blame_infos : Vec < BlamePathEntry > , options : Options ) -> Self {
211206 let script = vec ! [ BlameScriptOperation :: InitRepository ] ;
212207
213208 Self {
214- blame_path ,
209+ blame_infos ,
215210 seen : BTreeSet :: default ( ) ,
216211 script,
217212 options,
@@ -224,9 +219,9 @@ git commit -m {commit_id}
224219 // methods can rely on the assumption that the root comes first, followed by its
225220 // descendants. That way, we can use a simple `for` loop to iterate through
226221 // `self.blame_path` below.
227- self . blame_path . reverse ( ) ;
222+ self . blame_infos . reverse ( ) ;
228223
229- for blame_path_entry in self . blame_path . clone ( ) {
224+ for blame_path_entry in self . blame_infos . clone ( ) {
230225 if !self . seen . contains ( & blame_path_entry. commit_id ) {
231226 self . process_entry ( & blame_path_entry) ?;
232227 }
@@ -309,13 +304,13 @@ git commit -m {commit_id}
309304 // commits where there’s changes against each parent. Each of these changes would
310305 // produce a diff that’s represented in `self.blame_path`.
311306 let mut children: Vec < _ > = self
312- . blame_path
307+ . blame_infos
313308 . iter ( )
314309 . enumerate ( )
315310 . filter ( |( _, x) | x. commit_id == child. commit_id )
316311 . collect ( ) ;
317312
318- children. sort_by_key ( |( _, x) | x. index ) ;
313+ children. sort_by_key ( |( _, x) | x. parent_index ) ;
319314
320315 let parents = children
321316 . iter ( )
@@ -325,7 +320,7 @@ git commit -m {commit_id}
325320
326321 // When we search for a parent we only have to consider entries up to and
327322 // excluding `index` as anything after `index` can only be a child.
328- self . blame_path [ ..( * index) ]
323+ self . blame_infos [ ..( * index) ]
329324 . iter ( )
330325 . rfind ( |& x| {
331326 x. blob_id == parent_blob_id && Some ( & x. source_file_path ) == parent_source_file_path. as_ref ( )
0 commit comments