@@ -6,7 +6,7 @@ pub(super) mod function {
6
6
use anyhow:: Context ;
7
7
use gix:: {
8
8
blame:: BlamePathEntry ,
9
- bstr:: { BStr , BString , ByteSlice } ,
9
+ bstr:: { BString , ByteSlice } ,
10
10
objs:: FindExt ,
11
11
ObjectId ,
12
12
} ;
@@ -72,14 +72,11 @@ pub(super) mod function {
72
72
options,
73
73
) ?;
74
74
75
- let blame_path = outcome
75
+ let blame_infos = outcome
76
76
. blame_path
77
77
. expect ( "blame path to be present as `debug_track_path == true`" ) ;
78
78
79
- // TODO
80
- // Potentially make `"assets"` configurable (it is in `git_to_sh`).
81
79
let assets = destination_dir. join ( "assets" ) ;
82
-
83
80
eprintln ! ( "{prefix} create directory '{assets}'" , assets = assets. display( ) ) ;
84
81
85
82
if !dry_run {
@@ -88,17 +85,9 @@ pub(super) mod function {
88
85
89
86
let mut buf = Vec :: new ( ) ;
90
87
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 {
93
90
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
-
102
91
if !dry_run {
103
92
let blob = repo. objects . find_blob ( & blame_path_entry. blob_id , & mut buf) ?. data ;
104
93
@@ -113,18 +102,15 @@ pub(super) mod function {
113
102
} ) ?;
114
103
115
104
let blob = crate :: commands:: copy_royal:: remapped ( blob) ;
116
-
117
105
std:: fs:: write ( dst, blob) ?;
118
106
}
119
107
}
120
108
}
121
109
122
- let mut blame_script = BlameScript :: new ( blame_path, Options { verbatim } ) ;
123
-
110
+ let mut blame_script = BlameScript :: new ( blame_infos, Options { verbatim } ) ;
124
111
blame_script. generate ( ) ?;
125
112
126
113
let script_file = destination_dir. join ( "create-history.sh" ) ;
127
-
128
114
eprintln ! (
129
115
"{prefix} write script file at '{script_file}'" ,
130
116
script_file = script_file. display( )
@@ -174,16 +160,25 @@ echo create-history.sh >> .gitignore
174
160
git rm {src}
175
161
"
176
162
) ,
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"#
181
176
cp ./assets/{commit_id}.commit ./{src}
182
- # create commit
183
177
git add {src}
184
178
git commit -m {commit_id}
185
179
"
186
- ) ,
180
+ )
181
+ }
187
182
BlameScriptOperation :: CheckoutTag ( commit_id) => writeln ! ( f, "git checkout tag-{commit_id}" ) ,
188
183
BlameScriptOperation :: PrepareMerge ( commit_ids) => writeln ! (
189
184
f,
@@ -200,18 +195,18 @@ git commit -m {commit_id}
200
195
}
201
196
202
197
struct BlameScript {
203
- blame_path : Vec < BlamePathEntry > ,
198
+ blame_infos : Vec < BlamePathEntry > ,
204
199
seen : BTreeSet < ObjectId > ,
205
200
script : Vec < BlameScriptOperation > ,
206
201
options : Options ,
207
202
}
208
203
209
204
impl BlameScript {
210
- fn new ( blame_path : Vec < BlamePathEntry > , options : Options ) -> Self {
205
+ fn new ( blame_infos : Vec < BlamePathEntry > , options : Options ) -> Self {
211
206
let script = vec ! [ BlameScriptOperation :: InitRepository ] ;
212
207
213
208
Self {
214
- blame_path ,
209
+ blame_infos ,
215
210
seen : BTreeSet :: default ( ) ,
216
211
script,
217
212
options,
@@ -224,9 +219,9 @@ git commit -m {commit_id}
224
219
// methods can rely on the assumption that the root comes first, followed by its
225
220
// descendants. That way, we can use a simple `for` loop to iterate through
226
221
// `self.blame_path` below.
227
- self . blame_path . reverse ( ) ;
222
+ self . blame_infos . reverse ( ) ;
228
223
229
- for blame_path_entry in self . blame_path . clone ( ) {
224
+ for blame_path_entry in self . blame_infos . clone ( ) {
230
225
if !self . seen . contains ( & blame_path_entry. commit_id ) {
231
226
self . process_entry ( & blame_path_entry) ?;
232
227
}
@@ -309,13 +304,13 @@ git commit -m {commit_id}
309
304
// commits where there’s changes against each parent. Each of these changes would
310
305
// produce a diff that’s represented in `self.blame_path`.
311
306
let mut children: Vec < _ > = self
312
- . blame_path
307
+ . blame_infos
313
308
. iter ( )
314
309
. enumerate ( )
315
310
. filter ( |( _, x) | x. commit_id == child. commit_id )
316
311
. collect ( ) ;
317
312
318
- children. sort_by_key ( |( _, x) | x. index ) ;
313
+ children. sort_by_key ( |( _, x) | x. parent_index ) ;
319
314
320
315
let parents = children
321
316
. iter ( )
@@ -325,7 +320,7 @@ git commit -m {commit_id}
325
320
326
321
// When we search for a parent we only have to consider entries up to and
327
322
// excluding `index` as anything after `index` can only be a child.
328
- self . blame_path [ ..( * index) ]
323
+ self . blame_infos [ ..( * index) ]
329
324
. iter ( )
330
325
. rfind ( |& x| {
331
326
x. blob_id == parent_blob_id && Some ( & x. source_file_path ) == parent_source_file_path. as_ref ( )
0 commit comments