@@ -33,10 +33,6 @@ class GitRepositoryScanner {
3333 this ->rules_manager .add_rule (name, match_pattern, match_whitelist_patterns, match_blacklist_patterns);
3434 }
3535
36- void compile_rules () {
37- this ->rules_manager .compile_rules ();
38- }
39-
4036 void add_ignored_file_extension (
4137 std::string file_extension
4238 ) {
@@ -89,23 +85,13 @@ class GitRepositoryScanner {
8985 return ;
9086 }
9187
92- const git_oid * current_commit_id = git_commit_id (current_commit);
93- char current_commit_id_string[41 ] = {0 };
94- git_oid_fmt (current_commit_id_string, current_commit_id);
95-
96- const git_signature * current_commit_author = git_commit_author (current_commit);
97- std::string current_commit_message = git_commit_message (current_commit);
98-
99- git_time_t commit_time = git_commit_time (current_commit);
100-
10188 if (current_commit_parent_count == 1 ) {
10289 git_commit_parent (&parent_commit, current_commit, 0 );
10390 git_commit_tree (¤t_git_tree, current_commit);
10491 git_commit_tree (&parent_git_tree, parent_commit);
10592
10693 git_diff_tree_to_tree (&diff, git_repo, parent_git_tree, current_git_tree, NULL );
10794
108- git_commit_free (current_commit);
10995 git_commit_free (parent_commit);
11096 git_tree_free (current_git_tree);
11197 git_tree_free (parent_git_tree);
@@ -114,7 +100,6 @@ class GitRepositoryScanner {
114100
115101 git_diff_tree_to_tree (&diff, git_repo, NULL , current_git_tree, NULL );
116102
117- git_commit_free (current_commit);
118103 git_tree_free (current_git_tree);
119104 }
120105
@@ -136,25 +121,33 @@ class GitRepositoryScanner {
136121 std::string content ((const char *)git_blob_rawcontent (blob));
137122 auto matches = this ->rules_manager .scan_content (content);
138123 if (matches.has_value ()) {
139- for (auto & match : matches.value ()) {
140- char new_file_oid[41 ] = {0 };
141- git_oid_fmt (new_file_oid, &delta->new_file .id );
124+ this ->results_mutex .lock ();
125+
126+ const git_oid * current_commit_id = git_commit_id (current_commit);
127+ char current_commit_id_string[41 ] = {0 };
128+ git_oid_fmt (current_commit_id_string, current_commit_id);
142129
143- std::string current_commit_author_name = " " ;
144- if (nullptr != current_commit_author->name ) {
145- current_commit_author_name = current_commit_author->name ;
146- }
147- std::string current_commit_author_email = " " ;
148- if (nullptr != current_commit_author->email ) {
149- current_commit_author_email = current_commit_author->email ;
150- }
130+ const git_signature * current_commit_author = git_commit_author (current_commit);
131+ std::string current_commit_message = git_commit_message (current_commit);
151132
152- this ->results_mutex .lock ();
133+ char new_file_oid[41 ] = {0 };
134+ git_oid_fmt (new_file_oid, &delta->new_file .id );
135+
136+ std::string current_commit_author_name = " " ;
137+ if (nullptr != current_commit_author->name ) {
138+ current_commit_author_name = current_commit_author->name ;
139+ }
140+ std::string current_commit_author_email = " " ;
141+ if (nullptr != current_commit_author->email ) {
142+ current_commit_author_email = current_commit_author->email ;
143+ }
153144
154- std::tm * commit_time_tm = std::gmtime (&commit_time);
155- std::ostringstream commit_time_ss;
156- commit_time_ss << std::put_time (commit_time_tm, " %FT%T" );
145+ git_time_t commit_time = git_commit_time (current_commit);
146+ std::tm * commit_time_tm = std::gmtime (&commit_time);
147+ std::ostringstream commit_time_ss;
148+ commit_time_ss << std::put_time (commit_time_tm, " %FT%T" );
157149
150+ for (auto & match : matches.value ()) {
158151 results.push_back (
159152 {
160153 {" commit_id" , std::string (current_commit_id_string)},
@@ -168,14 +161,15 @@ class GitRepositoryScanner {
168161 {" match" , match[" match" ]},
169162 }
170163 );
171-
172- this ->results_mutex .unlock ();
173164 }
165+
166+ this ->results_mutex .unlock ();
174167 }
175168 git_blob_free (blob);
176169 }
177170 }
178171
172+ git_commit_free (current_commit);
179173 git_diff_free (diff);
180174 }
181175
@@ -210,6 +204,8 @@ class GitRepositoryScanner {
210204 tf::Executor executor;
211205 executor.run (taskflow).wait ();
212206
207+ git_repository_free (git_repo);
208+
213209 return results;
214210 }
215211
@@ -264,11 +260,6 @@ PYBIND11_MODULE(pyrepscan, m) {
264260 pybind11::arg (" match_whitelist_patterns" ),
265261 pybind11::arg (" match_blacklist_patterns" )
266262 )
267- .def (
268- " compile_rules" ,
269- &RulesManager::compile_rules,
270- " "
271- )
272263 .def (
273264 " add_ignored_file_extension" ,
274265 &RulesManager::add_ignored_file_extension,
@@ -313,15 +304,10 @@ PYBIND11_MODULE(pyrepscan, m) {
313304 pybind11::arg (" repository_path" ),
314305 pybind11::arg (" branch_glob_pattern" )
315306 )
316- .def (
317- " compile_rules" ,
318- &GitRepositoryScanner::compile_rules,
319- " Compile all the added rules to make them available for a scan.\n Call this function after you finished adding all the rules"
320- )
321307 .def (
322308 " add_rule" ,
323309 &GitRepositoryScanner::add_rule,
324- " Adding a rule to the list of rules.\n After a compile_rules call, no more rules can be added. " ,
310+ " Adding a rule to the list of rules." ,
325311 pybind11::arg (" name" ),
326312 pybind11::arg (" match_pattern" ),
327313 pybind11::arg (" match_whitelist_patterns" ),
0 commit comments