1- use crate :: repository:: Repository ;
21use crate :: git_utils:: clone_repository;
3- use crate :: io_utils:: { write_content_to_file, get_language_alias} ;
2+ use crate :: io_utils:: { get_language_alias, write_content_to_file} ;
3+ use crate :: repository:: Repository ;
4+ use std:: path:: PathBuf ;
5+ use std:: sync:: Arc ;
46use tokio:: fs;
57use walkdir:: WalkDir ;
6- use std:: sync:: Arc ;
7- use std:: path:: PathBuf ;
88
99/// Process a single repository: clone and process files
1010pub async fn process_single_repository (
@@ -13,11 +13,19 @@ pub async fn process_single_repository(
1313 merge_files : bool ,
1414 ignore_patterns : Arc < Vec < String > > ,
1515) -> Result < Repository , String > {
16- println ! ( "Preparing to clone {} to {:?}" , repository. url, repository. path) ;
16+ println ! (
17+ "Preparing to clone {} to {:?}" ,
18+ repository. url, repository. path
19+ ) ;
1720 clone_repository ( & repository) . await ?;
18- println ! ( "Successfully cloned {} to {:?}" , repository. name, repository. path) ;
19-
20- let content = process_repository_files ( & repository. path , no_headers, merge_files, & ignore_patterns) . await ?;
21+ println ! (
22+ "Successfully cloned {} to {:?}" ,
23+ repository. name, repository. path
24+ ) ;
25+
26+ let content =
27+ process_repository_files ( & repository. path , no_headers, merge_files, & ignore_patterns)
28+ . await ?;
2129 repository. content = Some ( content) ;
2230
2331 Ok ( repository)
@@ -39,15 +47,18 @@ pub async fn process_repository_files(
3947 let with_headers = !no_headers;
4048
4149 if let Ok ( content) = fs:: read_to_string ( path) . await {
42- let relative_path = path. strip_prefix ( repo_path)
50+ let relative_path = path
51+ . strip_prefix ( repo_path)
4352 . map_err ( |e| format ! ( "Failed to strip prefix: {}" , e) ) ?;
4453 let alias = get_language_alias ( path) ;
4554
4655 if with_headers {
4756 if merge_files {
48- combined_content. push_str ( & format ! ( "### File: {}\n " , relative_path. display( ) ) ) ;
57+ combined_content
58+ . push_str ( & format ! ( "### File: {}\n " , relative_path. display( ) ) ) ;
4959 } else {
50- combined_content. push_str ( & format ! ( "## File: {}\n " , relative_path. display( ) ) ) ;
60+ combined_content
61+ . push_str ( & format ! ( "## File: {}\n " , relative_path. display( ) ) ) ;
5162 }
5263 }
5364 combined_content. push_str ( & format ! ( "```{}\n " , alias) ) ;
@@ -97,23 +108,43 @@ pub async fn handle_results(
97108}
98109
99110/// Check if a file should be processed
100- fn is_valid_file ( path : & std:: path:: Path , repo_path : & std:: path:: Path , ignore_patterns : & [ String ] ) -> bool {
101- if path. components ( ) . any ( |c| c. as_os_str ( ) == ".git" ) { return false ; }
102- if ignore_due_to_pattern ( path, repo_path, ignore_patterns) { return false ; }
103- if !path. is_file ( ) { return false ; }
111+ fn is_valid_file (
112+ path : & std:: path:: Path ,
113+ repo_path : & std:: path:: Path ,
114+ ignore_patterns : & [ String ] ,
115+ ) -> bool {
116+ if path. components ( ) . any ( |c| c. as_os_str ( ) == ".git" ) {
117+ return false ;
118+ }
119+ if ignore_due_to_pattern ( path, repo_path, ignore_patterns) {
120+ return false ;
121+ }
122+ if !path. is_file ( ) {
123+ return false ;
124+ }
104125
105126 if let Some ( ext) = path. extension ( ) . and_then ( |s| s. to_str ( ) )
106- && matches ! ( ext, "png" | "jpg" | "jpeg" | "gif" | "zip" | "tar" | "gz" | "bin" | "o" | "so" | "dll" ) {
127+ && matches ! (
128+ ext,
129+ "png" | "jpg" | "jpeg" | "gif" | "zip" | "tar" | "gz" | "bin" | "o" | "so" | "dll"
130+ )
131+ {
107132 return false ;
108133 }
109134
110135 true
111136}
112137
113- fn ignore_due_to_pattern ( path : & std:: path:: Path , repo_path : & std:: path:: Path , ignore_patterns : & [ String ] ) -> bool {
138+ fn ignore_due_to_pattern (
139+ path : & std:: path:: Path ,
140+ repo_path : & std:: path:: Path ,
141+ ignore_patterns : & [ String ] ,
142+ ) -> bool {
114143 let relative_path_str = match path. strip_prefix ( repo_path) {
115144 Ok ( p) => p. to_string_lossy ( ) . replace ( "\\ " , "/" ) ,
116145 Err ( _) => return false ,
117146 } ;
118- ignore_patterns. iter ( ) . any ( |pattern| relative_path_str. contains ( & pattern. replace ( "\\ " , "/" ) ) )
147+ ignore_patterns
148+ . iter ( )
149+ . any ( |pattern| relative_path_str. contains ( & pattern. replace ( "\\ " , "/" ) ) )
119150}
0 commit comments