@@ -482,127 +482,3 @@ export const replace_commit_symbol = async (params: {
482482 }
483483 return { instruction : result_instruction , commit_definitions }
484484}
485-
486- const build_context_at_commit_xml = (
487- files_content : { path : string ; content : string } [ ]
488- ) : string => {
489- if ( files_content . length == 0 ) {
490- return '<archive/>'
491- }
492-
493- let files_xml = ''
494- for ( const file of files_content ) {
495- files_xml += `<file path="${ file . path . replace ( / \\ / g, '/' ) } ">\n<![CDATA[\n${
496- file . content
497- } \n]]>\n</file>\n`
498- }
499-
500- return `\n<archive>\n${ files_xml } </archive>\n`
501- }
502-
503- export const replace_context_at_commit_symbol = async ( params : {
504- instruction : string
505- workspace_provider : WorkspaceProvider
506- } ) : Promise < string > => {
507- const regex =
508- / # C o n t e x t A t C o m m i t \( ( [ ^ : ] + ) : ( [ a - f A - F 0 - 9 ] + ) \s * (?: " ( (?: [ ^ " \\ ] | \\ .) * ) " ) ? \) / g
509-
510- let result_instruction = params . instruction
511- const matches = [ ...result_instruction . matchAll ( regex ) ]
512-
513- const workspace_folders = vscode . workspace . workspaceFolders
514- if ( ! workspace_folders ) {
515- return result_instruction . replace ( regex , '' )
516- }
517-
518- for ( const match of matches ) {
519- const full_match = match [ 0 ]
520- const folder_name = match [ 1 ]
521- const commit_hash = match [ 2 ]
522-
523- const target_folder = workspace_folders . find (
524- ( folder ) => folder . name == folder_name
525- )
526-
527- if ( ! target_folder ) {
528- vscode . window . showErrorMessage (
529- dictionary . error_message . WORKSPACE_FOLDER_NOT_FOUND ( folder_name )
530- )
531- result_instruction = result_instruction . replace ( full_match , '' )
532- continue
533- }
534-
535- const checked_files = params . workspace_provider . get_checked_files ( )
536- const files_in_repo = checked_files . filter ( ( file ) =>
537- file . startsWith ( target_folder . uri . fsPath )
538- )
539-
540- if ( files_in_repo . length == 0 ) {
541- vscode . window . showInformationMessage (
542- dictionary . information_message . NO_CHECKED_FILES_IN_REPO_FOR_COMMIT (
543- folder_name ,
544- commit_hash . substring ( 0 , 7 )
545- )
546- )
547- }
548-
549- const files_content : { path : string ; content : string } [ ] = [ ]
550-
551- for ( const file_path of files_in_repo ) {
552- const relative_path = path . relative ( target_folder . uri . fsPath , file_path )
553-
554- let content_at_commit : string | null = null
555- try {
556- content_at_commit = execSync (
557- `git show ${ commit_hash } :"./${ relative_path . replace ( / \\ / g, '/' ) } "` ,
558- {
559- cwd : target_folder . uri . fsPath ,
560- encoding : 'utf-8' ,
561- stdio : [ 'pipe' , 'pipe' , 'ignore' ] // ignore stderr
562- }
563- )
564- } catch ( error ) {
565- // File might not have existed at that commit
566- }
567-
568- let current_content : string | null = null
569- try {
570- current_content = fs . readFileSync ( file_path , 'utf-8' )
571- } catch ( error ) {
572- // File might not exist in workspace (e.g., deleted)
573- }
574-
575- if ( content_at_commit === current_content ) {
576- continue // File is unchanged, ignore it
577- }
578-
579- if ( content_at_commit !== null ) {
580- // If we are here, file has changed (modified, new, or deleted)
581- // Add its historical content to the archive.
582- const display_path =
583- params . workspace_provider . get_workspace_roots ( ) . length > 1
584- ? `${ folder_name } /${ relative_path . replace ( / \\ / g, '/' ) } `
585- : relative_path . replace ( / \\ / g, '/' )
586-
587- files_content . push ( { path : display_path , content : content_at_commit } )
588- }
589- }
590-
591- if ( files_in_repo . length > 0 && files_content . length == 0 ) {
592- vscode . window . showInformationMessage (
593- dictionary . information_message . ALL_CHECKED_FILES_UNCAHNGED_SINCE_COMMIT (
594- folder_name ,
595- commit_hash . substring ( 0 , 7 )
596- )
597- )
598- }
599-
600- const replacement_text = build_context_at_commit_xml ( files_content )
601- result_instruction = result_instruction . replace (
602- full_match ,
603- replacement_text
604- )
605- }
606-
607- return result_instruction
608- }
0 commit comments