@@ -184,143 +184,5 @@ impl From<PrepareFetch> for Repository {
184
184
}
185
185
}
186
186
187
- mod util {
188
- use super :: Error ;
189
- use crate :: bstr:: BStr ;
190
- use crate :: Repository ;
191
- use git_odb:: Find ;
192
- use git_ref:: transaction:: { LogChange , RefLog } ;
193
-
194
- pub fn write_remote_to_local_config_file (
195
- remote : & mut crate :: Remote < ' _ > ,
196
- remote_name : String ,
197
- ) -> Result < git_config:: File < ' static > , Error > {
198
- let mut metadata = git_config:: file:: Metadata :: from ( git_config:: Source :: Local ) ;
199
- let config_path = remote. repo . git_dir ( ) . join ( "config" ) ;
200
- metadata. path = Some ( config_path. clone ( ) ) ;
201
- let mut config =
202
- git_config:: File :: from_paths_metadata ( Some ( metadata) , Default :: default ( ) ) ?. expect ( "one file to load" ) ;
203
- remote. save_as_to ( remote_name, & mut config) ?;
204
- std:: fs:: write ( config_path, config. to_bstring ( ) ) ?;
205
- Ok ( config)
206
- }
207
-
208
- pub fn replace_changed_local_config_file ( repo : & mut Repository , mut config : git_config:: File < ' static > ) {
209
- let repo_config = git_features:: threading:: OwnShared :: make_mut ( & mut repo. config . resolved ) ;
210
- let ids_to_remove: Vec < _ > = repo_config
211
- . sections_and_ids ( )
212
- . filter_map ( |( s, id) | {
213
- matches ! ( s. meta( ) . source, git_config:: Source :: Local | git_config:: Source :: Api ) . then ( || id)
214
- } )
215
- . collect ( ) ;
216
- for id in ids_to_remove {
217
- repo_config. remove_section_by_id ( id) ;
218
- }
219
- crate :: config:: overrides:: apply ( & mut config, & repo. options . config_overrides , git_config:: Source :: Api )
220
- . expect ( "applied once and can be applied again" ) ;
221
- repo_config. append ( config) ;
222
- repo. reread_values_and_clear_caches ( )
223
- . expect ( "values could be read once and can be read again" ) ;
224
- }
225
-
226
- /// HEAD cannot be written by means of refspec by design, so we have to do it manually here. Also create the pointed-to ref
227
- /// if we have to, as it might not have been naturally included in the ref-specs.
228
- pub fn update_head (
229
- repo : & Repository ,
230
- remote_refs : & [ git_protocol:: fetch:: Ref ] ,
231
- reflog_message : & BStr ,
232
- ) -> Result < ( ) , Error > {
233
- use git_ref:: transaction:: { PreviousValue , RefEdit } ;
234
- use git_ref:: Target ;
235
- use std:: convert:: TryInto ;
236
- let ( head_peeled_id, head_ref) = match remote_refs. iter ( ) . find_map ( |r| match r {
237
- git_protocol:: fetch:: Ref :: Symbolic {
238
- full_ref_name,
239
- target,
240
- object,
241
- } if full_ref_name == "HEAD" => Some ( ( object, Some ( target) ) ) ,
242
- git_protocol:: fetch:: Ref :: Direct { full_ref_name, object } if full_ref_name == "HEAD" => {
243
- Some ( ( object, None ) )
244
- }
245
- _ => None ,
246
- } ) {
247
- Some ( t) => t,
248
- None => return Ok ( ( ) ) ,
249
- } ;
250
-
251
- let name: git_ref:: FullName = "HEAD" . try_into ( ) . expect ( "valid" ) ;
252
- let reflog_message = || LogChange {
253
- mode : RefLog :: AndReference ,
254
- force_create_reflog : false ,
255
- message : reflog_message. to_owned ( ) ,
256
- } ;
257
- match head_ref {
258
- Some ( referent) => {
259
- let referent: git_ref:: FullName = referent. try_into ( ) . map_err ( |err| Error :: InvalidHeadRef {
260
- head_ref_name : referent. to_owned ( ) ,
261
- source : err,
262
- } ) ?;
263
- repo. refs
264
- . transaction ( )
265
- . packed_refs ( git_ref:: file:: transaction:: PackedRefs :: DeletionsAndNonSymbolicUpdates (
266
- Box :: new ( |oid, buf| {
267
- repo. objects
268
- . try_find ( oid, buf)
269
- . map ( |obj| obj. map ( |obj| obj. kind ) )
270
- . map_err ( |err| Box :: new ( err) as Box < dyn std:: error:: Error + Send + Sync + ' static > )
271
- } ) ,
272
- ) )
273
- . prepare (
274
- [
275
- RefEdit {
276
- change : git_ref:: transaction:: Change :: Update {
277
- log : reflog_message ( ) ,
278
- expected : PreviousValue :: Any ,
279
- new : Target :: Peeled ( head_peeled_id. to_owned ( ) ) ,
280
- } ,
281
- name : referent. clone ( ) ,
282
- deref : false ,
283
- } ,
284
- RefEdit {
285
- change : git_ref:: transaction:: Change :: Update {
286
- log : reflog_message ( ) ,
287
- expected : PreviousValue :: Any ,
288
- new : Target :: Symbolic ( referent) ,
289
- } ,
290
- name : name. clone ( ) ,
291
- deref : false ,
292
- } ,
293
- ] ,
294
- git_lock:: acquire:: Fail :: Immediately ,
295
- git_lock:: acquire:: Fail :: Immediately ,
296
- )
297
- . map_err ( crate :: reference:: edit:: Error :: from) ?
298
- . commit ( repo. committer_or_default ( ) )
299
- . map_err ( crate :: reference:: edit:: Error :: from) ?;
300
- let mut log = reflog_message ( ) ;
301
- log. mode = RefLog :: Only ;
302
- repo. edit_reference ( RefEdit {
303
- change : git_ref:: transaction:: Change :: Update {
304
- log,
305
- expected : PreviousValue :: Any ,
306
- new : Target :: Peeled ( head_peeled_id. to_owned ( ) ) ,
307
- } ,
308
- name,
309
- deref : false ,
310
- } ) ?;
311
- }
312
- None => {
313
- repo. edit_reference ( RefEdit {
314
- change : git_ref:: transaction:: Change :: Update {
315
- log : reflog_message ( ) ,
316
- expected : PreviousValue :: Any ,
317
- new : Target :: Peeled ( head_peeled_id. to_owned ( ) ) ,
318
- } ,
319
- name,
320
- deref : false ,
321
- } ) ?;
322
- }
323
- } ;
324
- Ok ( ( ) )
325
- }
326
- }
187
+ #[ cfg( feature = "blocking-network-client" ) ]
188
+ mod util;
0 commit comments