@@ -21,9 +21,7 @@ pub fn make_feature() -> Vec<(String, OptionValueFunction)> {
21
21
22
22
#[ cfg( test) ]
23
23
pub fn remote_from_config ( _: & Option < & GitConfig > ) -> Option < GitRemoteRepo > {
24
- Some ( GitRemoteRepo :: GitHub {
25
- slug : "dandavison/delta" . to_string ( ) ,
26
- } )
24
+ GitRemoteRepo :: for_testing ( )
27
25
}
28
26
29
27
#[ cfg( not( test) ) ]
@@ -41,6 +39,7 @@ lazy_static! {
41
39
pub fn format_commit_line_with_osc8_commit_hyperlink < ' a > (
42
40
line : & ' a str ,
43
41
config : & Config ,
42
+ cached_repo : & Option < GitRemoteRepo > ,
44
43
) -> Cow < ' a , str > {
45
44
// Given matches in a line, m = matches[0] and pos = 0: store line[pos..m.start()] first, then
46
45
// store the T(line[m.start()..m.end()]) match transformation, then set pos = m.end().
@@ -80,7 +79,7 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>(
80
79
. with_input ( line, & first_match, & mut matches) ;
81
80
return Cow :: from ( result) ;
82
81
}
83
- } else if let Some ( repo) = remote_from_config ( & config . git_config ( ) ) {
82
+ } else if let Some ( repo) = cached_repo {
84
83
let mut matches = COMMIT_HASH_REGEX . find_iter ( line) ;
85
84
if let Some ( first_match) = matches. next ( ) {
86
85
let result = HyperlinkCommits ( |commit_hash| repo. format_commit_url ( commit_hash) )
@@ -144,35 +143,36 @@ pub mod tests {
144
143
145
144
#[ test]
146
145
fn test_formatted_hyperlinks ( ) {
146
+ let remote = GitRemoteRepo :: for_testing ( ) ;
147
147
let config = make_config_from_args ( & [ "--hyperlinks-commit-link-format" , "HERE:{commit}" ] ) ;
148
-
149
148
let line = "001234abcdf" ;
150
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
149
+
150
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote) ;
151
151
assert_eq ! (
152
152
result,
153
153
"\u{1b} ]8;;HERE:001234abcdf\u{1b} \\ 001234abcdf\u{1b} ]8;;\u{1b} \\ " ,
154
154
) ;
155
155
156
156
let line = "a2272718f0b398e48652ace17fca85c1962b3fc22" ; // length: 41 > 40
157
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
157
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
158
158
assert_eq ! ( result, "a2272718f0b398e48652ace17fca85c1962b3fc22" , ) ;
159
159
160
160
let line = "a2272718f0+b398e48652ace17f,ca85c1962b3fc2" ;
161
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
161
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
162
162
assert_eq ! ( result, "\u{1b} ]8;;HERE:a2272718f0\u{1b} \\ a2272718f0\u{1b} ]8;;\u{1b} \\ +\u{1b} ]8;;\
163
163
HERE:b398e48652ace17f\u{1b} \\ b398e48652ace17f\u{1b} ]8;;\u{1b} \\ ,\u{1b} ]8;;HERE:ca85c1962b3fc2\
164
164
\u{1b} \\ ca85c1962b3fc2\u{1b} ]8;;\u{1b} \\ ") ;
165
165
166
166
let line = "This 01234abcdf Hash" ;
167
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
167
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
168
168
assert_eq ! (
169
169
result,
170
170
"This \u{1b} ]8;;HERE:01234abcdf\u{1b} \\ 01234abcdf\u{1b} ]8;;\u{1b} \\ Hash" ,
171
171
) ;
172
172
173
173
let line =
174
174
"Another 01234abcdf hash but also this one: dc623b084ad2dd14fe5d90189cacad5d49bfbfd3!" ;
175
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
175
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
176
176
assert_eq ! (
177
177
result,
178
178
"Another \u{1b} ]8;;HERE:01234abcdf\u{1b} \\ 01234abcdf\u{1b} ]8;;\u{1b} \\ hash but \
@@ -181,7 +181,7 @@ pub mod tests {
181
181
) ;
182
182
183
183
let line = "01234abcdf 03043baf30 12abcdef0 12345678" ;
184
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
184
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
185
185
assert_eq ! (
186
186
result,
187
187
"\u{1b} ]8;;HERE:01234abcdf\u{1b} \\ 01234abcdf\u{1b} ]8;;\u{1b} \\ \u{1b} ]8;;\
@@ -194,9 +194,10 @@ pub mod tests {
194
194
fn test_hyperlinks_to_repo ( ) {
195
195
let mut config = make_config_from_args ( & [ "--hyperlinks" ] ) ;
196
196
config. git_config = GitConfig :: for_testing ( ) ;
197
+ let remote = GitRemoteRepo :: for_testing ( ) ;
197
198
198
199
let line = "This a589ff9debaefdd delta commit" ;
199
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
200
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
200
201
assert_eq ! (
201
202
result,
202
203
"This \u{1b} ]8;;https://github.com/dandavison/delta/commit/a589ff9debaefdd\u{1b} \
@@ -205,7 +206,7 @@ pub mod tests {
205
206
206
207
let line =
207
208
"Another a589ff9debaefdd hash but also this one: c5696757c0827349a87daa95415656!" ;
208
- let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config) ;
209
+ let result = format_commit_line_with_osc8_commit_hyperlink ( line, & config, & remote ) ;
209
210
assert_eq ! (
210
211
result,
211
212
"Another \u{1b} ]8;;https://github.com/dandavison/delta/commit/a589ff9debaefdd\
0 commit comments