@@ -45,11 +45,6 @@ struct GitHubGitRefObject {
4545 sha : String ,
4646}
4747
48- enum GitCuratedRepoSyncError {
49- GitUnavailable ( String ) ,
50- SyncFailed ( String ) ,
51- }
52-
5348pub ( crate ) fn curated_plugins_repo_path ( codex_home : & Path ) -> PathBuf {
5449 codex_home. join ( CURATED_PLUGINS_RELATIVE_DIR )
5550}
@@ -69,22 +64,18 @@ fn sync_openai_plugins_repo_with_transport_overrides(
6964) -> Result < String , String > {
7065 match sync_openai_plugins_repo_via_git ( codex_home, git_binary) {
7166 Ok ( remote_sha) => Ok ( remote_sha) ,
72- Err ( GitCuratedRepoSyncError :: GitUnavailable ( err) ) => {
67+ Err ( err) => {
7368 warn ! (
7469 error = %err,
7570 git_binary,
76- "git unavailable for curated plugin sync; falling back to GitHub HTTP"
71+ "git sync failed for curated plugin sync; falling back to GitHub HTTP"
7772 ) ;
7873 sync_openai_plugins_repo_via_http ( codex_home, api_base_url)
7974 }
80- Err ( GitCuratedRepoSyncError :: SyncFailed ( err) ) => Err ( err) ,
8175 }
8276}
8377
84- fn sync_openai_plugins_repo_via_git (
85- codex_home : & Path ,
86- git_binary : & str ,
87- ) -> Result < String , GitCuratedRepoSyncError > {
78+ fn sync_openai_plugins_repo_via_git ( codex_home : & Path , git_binary : & str ) -> Result < String , String > {
8879 let repo_path = curated_plugins_repo_path ( codex_home) ;
8980 let sha_path = codex_home. join ( CURATED_PLUGINS_SHA_FILE ) ;
9081 let remote_sha = git_ls_remote_head_sha ( git_binary) ?;
@@ -94,8 +85,7 @@ fn sync_openai_plugins_repo_via_git(
9485 return Ok ( remote_sha) ;
9586 }
9687
97- let cloned_repo_path = prepare_curated_repo_parent_and_temp_dir ( & repo_path)
98- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
88+ let cloned_repo_path = prepare_curated_repo_parent_and_temp_dir ( & repo_path) ?;
9989 let clone_output = run_git_command_with_timeout (
10090 Command :: new ( git_binary)
10191 . env ( "GIT_OPTIONAL_LOCKS" , "0" )
@@ -107,22 +97,18 @@ fn sync_openai_plugins_repo_via_git(
10797 "git clone curated plugins repo" ,
10898 CURATED_PLUGINS_GIT_TIMEOUT ,
10999 ) ?;
110- ensure_git_success ( & clone_output, "git clone curated plugins repo" )
111- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
100+ ensure_git_success ( & clone_output, "git clone curated plugins repo" ) ?;
112101
113102 let cloned_sha = git_head_sha ( & cloned_repo_path, git_binary) ?;
114103 if cloned_sha != remote_sha {
115- return Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
104+ return Err ( format ! (
116105 "curated plugins clone HEAD mismatch: expected {remote_sha}, got {cloned_sha}"
117- ) ) ) ;
106+ ) ) ;
118107 }
119108
120- ensure_marketplace_manifest_exists ( & cloned_repo_path)
121- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
122- activate_curated_repo ( & repo_path, & cloned_repo_path)
123- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
124- write_curated_plugins_sha ( & sha_path, & remote_sha)
125- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
109+ ensure_marketplace_manifest_exists ( & cloned_repo_path) ?;
110+ activate_curated_repo ( & repo_path, & cloned_repo_path) ?;
111+ write_curated_plugins_sha ( & sha_path, & remote_sha) ?;
126112 Ok ( remote_sha)
127113}
128114
@@ -363,7 +349,7 @@ fn read_local_git_or_sha_file(
363349 read_sha_file ( sha_path)
364350}
365351
366- fn git_ls_remote_head_sha ( git_binary : & str ) -> Result < String , GitCuratedRepoSyncError > {
352+ fn git_ls_remote_head_sha ( git_binary : & str ) -> Result < String , String > {
367353 let output = run_git_command_with_timeout (
368354 Command :: new ( git_binary)
369355 . env ( "GIT_OPTIONAL_LOCKS" , "0" )
@@ -373,55 +359,45 @@ fn git_ls_remote_head_sha(git_binary: &str) -> Result<String, GitCuratedRepoSync
373359 "git ls-remote curated plugins repo" ,
374360 CURATED_PLUGINS_GIT_TIMEOUT ,
375361 ) ?;
376- ensure_git_success ( & output, "git ls-remote curated plugins repo" )
377- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
362+ ensure_git_success ( & output, "git ls-remote curated plugins repo" ) ?;
378363
379364 let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
380365 let Some ( first_line) = stdout. lines ( ) . next ( ) else {
381- return Err ( GitCuratedRepoSyncError :: SyncFailed (
382- "git ls-remote returned empty output for curated plugins repo" . to_string ( ) ,
383- ) ) ;
366+ return Err ( "git ls-remote returned empty output for curated plugins repo" . to_string ( ) ) ;
384367 } ;
385368 let Some ( ( sha, _) ) = first_line. split_once ( '\t' ) else {
386- return Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
369+ return Err ( format ! (
387370 "unexpected git ls-remote output for curated plugins repo: {first_line}"
388- ) ) ) ;
371+ ) ) ;
389372 } ;
390373 if sha. is_empty ( ) {
391- return Err ( GitCuratedRepoSyncError :: SyncFailed (
392- "git ls-remote returned empty sha for curated plugins repo" . to_string ( ) ,
393- ) ) ;
374+ return Err ( "git ls-remote returned empty sha for curated plugins repo" . to_string ( ) ) ;
394375 }
395376 Ok ( sha. to_string ( ) )
396377}
397378
398- fn git_head_sha ( repo_path : & Path , git_binary : & str ) -> Result < String , GitCuratedRepoSyncError > {
379+ fn git_head_sha ( repo_path : & Path , git_binary : & str ) -> Result < String , String > {
399380 let output = Command :: new ( git_binary)
400381 . env ( "GIT_OPTIONAL_LOCKS" , "0" )
401382 . arg ( "-C" )
402383 . arg ( repo_path)
403384 . arg ( "rev-parse" )
404385 . arg ( "HEAD" )
405386 . output ( )
406- . map_err ( |err| match err. kind ( ) {
407- std:: io:: ErrorKind :: NotFound => GitCuratedRepoSyncError :: GitUnavailable ( format ! (
408- "failed to run git rev-parse HEAD in {}: {err}" ,
409- repo_path. display( )
410- ) ) ,
411- _ => GitCuratedRepoSyncError :: SyncFailed ( format ! (
387+ . map_err ( |err| {
388+ format ! (
412389 "failed to run git rev-parse HEAD in {}: {err}" ,
413390 repo_path. display( )
414- ) ) ,
391+ )
415392 } ) ?;
416- ensure_git_success ( & output, "git rev-parse HEAD" )
417- . map_err ( GitCuratedRepoSyncError :: SyncFailed ) ?;
393+ ensure_git_success ( & output, "git rev-parse HEAD" ) ?;
418394
419395 let sha = String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) ;
420396 if sha. is_empty ( ) {
421- return Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
397+ return Err ( format ! (
422398 "git rev-parse HEAD returned empty output in {}" ,
423399 repo_path. display( )
424- ) ) ) ;
400+ ) ) ;
425401 }
426402 Ok ( sha)
427403}
@@ -430,71 +406,49 @@ fn run_git_command_with_timeout(
430406 command : & mut Command ,
431407 context : & str ,
432408 timeout : Duration ,
433- ) -> Result < Output , GitCuratedRepoSyncError > {
409+ ) -> Result < Output , String > {
434410 let mut child = command
435411 . stdin ( Stdio :: null ( ) )
436412 . stdout ( Stdio :: piped ( ) )
437413 . stderr ( Stdio :: piped ( ) )
438414 . spawn ( )
439- . map_err ( |err| match err. kind ( ) {
440- std:: io:: ErrorKind :: NotFound => {
441- GitCuratedRepoSyncError :: GitUnavailable ( format ! ( "failed to run {context}: {err}" ) )
442- }
443- _ => GitCuratedRepoSyncError :: SyncFailed ( format ! ( "failed to run {context}: {err}" ) ) ,
444- } ) ?;
415+ . map_err ( |err| format ! ( "failed to run {context}: {err}" ) ) ?;
445416
446417 let start = std:: time:: Instant :: now ( ) ;
447418 loop {
448419 match child. try_wait ( ) {
449420 Ok ( Some ( _) ) => {
450- return child. wait_with_output ( ) . map_err ( |err| {
451- GitCuratedRepoSyncError :: SyncFailed ( format ! (
452- "failed to wait for {context}: {err}"
453- ) )
454- } ) ;
421+ return child
422+ . wait_with_output ( )
423+ . map_err ( |err| format ! ( "failed to wait for {context}: {err}" ) ) ;
455424 }
456425 Ok ( None ) => { }
457- Err ( err) => {
458- return Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
459- "failed to poll {context}: {err}"
460- ) ) ) ;
461- }
426+ Err ( err) => return Err ( format ! ( "failed to poll {context}: {err}" ) ) ,
462427 }
463428
464429 if start. elapsed ( ) >= timeout {
465430 match child. try_wait ( ) {
466431 Ok ( Some ( _) ) => {
467- return child. wait_with_output ( ) . map_err ( |err| {
468- GitCuratedRepoSyncError :: SyncFailed ( format ! (
469- "failed to wait for {context}: {err}"
470- ) )
471- } ) ;
432+ return child
433+ . wait_with_output ( )
434+ . map_err ( |err| format ! ( "failed to wait for {context}: {err}" ) ) ;
472435 }
473436 Ok ( None ) => { }
474- Err ( err) => {
475- return Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
476- "failed to poll {context}: {err}"
477- ) ) ) ;
478- }
437+ Err ( err) => return Err ( format ! ( "failed to poll {context}: {err}" ) ) ,
479438 }
480439
481440 let _ = child. kill ( ) ;
482- let output = child. wait_with_output ( ) . map_err ( |err| {
483- GitCuratedRepoSyncError :: SyncFailed ( format ! (
484- "failed to wait for {context} after timeout: {err}"
485- ) )
486- } ) ?;
441+ let output = child
442+ . wait_with_output ( )
443+ . map_err ( |err| format ! ( "failed to wait for {context} after timeout: {err}" ) ) ?;
487444 let stderr = String :: from_utf8_lossy ( & output. stderr ) . trim ( ) . to_string ( ) ;
488445 return if stderr. is_empty ( ) {
489- Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
490- "{context} timed out after {}s" ,
491- timeout. as_secs( )
492- ) ) )
446+ Err ( format ! ( "{context} timed out after {}s" , timeout. as_secs( ) ) )
493447 } else {
494- Err ( GitCuratedRepoSyncError :: SyncFailed ( format ! (
448+ Err ( format ! (
495449 "{context} timed out after {}s: {stderr}" ,
496450 timeout. as_secs( )
497- ) ) )
451+ ) )
498452 } ;
499453 }
500454
0 commit comments