Skip to content

Commit 1cdbb65

Browse files
author
Gal Ben David
committed
- from_timestamp parameter has now a default value of 0 which means scan
all the commits
1 parent acf43c7 commit 1cdbb65

File tree

3 files changed

+14
-79
lines changed

3 files changed

+14
-79
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='PyRepScan',
8-
version='0.5.1',
8+
version='0.5.2',
99
author='Gal Ben David',
1010
author_email='[email protected]',
1111
url='https://github.com/intsights/PyRepScan',

src/git_repository_scanner.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,20 @@ class GitRepositoryScanner {
5959
git_revwalk_sorting(repo_revwalk, GIT_SORT_TIME);
6060
git_revwalk_push_glob(repo_revwalk, branch_glob_pattern.c_str());
6161

62-
git_commit * current_commit = nullptr;
63-
while (git_revwalk_next(&oid, repo_revwalk) == 0) {
64-
git_commit_lookup(&current_commit, git_repo, &oid);
65-
git_time_t commit_time = git_commit_time(current_commit);
66-
if (commit_time >= from_timestamp) {
62+
if (from_timestamp == 0) {
63+
while (git_revwalk_next(&oid, repo_revwalk) == 0) {
6764
oids.push_back(oid);
6865
}
69-
git_commit_free(current_commit);
66+
} else {
67+
git_commit * current_commit = nullptr;
68+
while (git_revwalk_next(&oid, repo_revwalk) == 0) {
69+
git_commit_lookup(&current_commit, git_repo, &oid);
70+
git_time_t commit_time = git_commit_time(current_commit);
71+
if (commit_time >= from_timestamp) {
72+
oids.push_back(oid);
73+
}
74+
git_commit_free(current_commit);
75+
}
7076
}
7177

7278
git_revwalk_free(repo_revwalk);
@@ -322,7 +328,7 @@ PYBIND11_MODULE(pyrepscan, m) {
322328
"Scan a repository for secrets",
323329
pybind11::arg("repository_path"),
324330
pybind11::arg("branch_glob_pattern"),
325-
pybind11::arg("from_timestamp")
331+
pybind11::arg("from_timestamp") = 0
326332
)
327333
.def(
328334
"add_rule",

tests/test_pyrepscan.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ def test_scan_regular(
477477
results = grs.scan(
478478
repository_path=self.tmpdir.name,
479479
branch_glob_pattern='*master',
480-
from_timestamp=0,
481480
)
482481
for result in results:
483482
result.pop('commit_id')
@@ -520,7 +519,6 @@ def test_scan_regular(
520519
results = grs.scan(
521520
repository_path=self.tmpdir.name,
522521
branch_glob_pattern='*',
523-
from_timestamp=0,
524522
)
525523
for result in results:
526524
result.pop('commit_id')
@@ -660,72 +658,3 @@ def test_scan_from_timestamp(
660658
list1=results,
661659
list2=[],
662660
)
663-
664-
def test_scan_encoding(
665-
self,
666-
):
667-
grs = pyrepscan.GitRepositoryScanner()
668-
grs.add_rule(
669-
name='First Rule',
670-
match_pattern=r'''(content)''',
671-
match_whitelist_patterns=[],
672-
match_blacklist_patterns=[],
673-
)
674-
675-
grs.add_ignored_file_extension('py')
676-
grs.add_ignored_file_path('test_')
677-
678-
results = grs.scan(
679-
repository_path=self.tmpdir.name,
680-
branch_glob_pattern='*',
681-
from_timestamp=int(
682-
datetime.datetime(
683-
year=2004,
684-
month=1,
685-
day=1,
686-
hour=0,
687-
minute=0,
688-
second=0,
689-
tzinfo=datetime.timezone.utc,
690-
).timestamp()
691-
),
692-
)
693-
for result in results:
694-
result.pop('commit_id')
695-
self.assertCountEqual(
696-
first=results,
697-
second=[
698-
{
699-
'author_email': '[email protected]',
700-
'author_name': 'Author Name',
701-
'commit_message': 'edited file in non_merged_branch',
702-
'commit_time': '2004-01-01T00:00:00',
703-
'file_oid': '057032a2108721ad1de6a9240fd1a8f45bc3f2ef',
704-
'file_path': 'file.txt',
705-
'match': 'content',
706-
'rule_name': 'First Rule'
707-
},
708-
],
709-
)
710-
711-
results = grs.scan(
712-
repository_path=self.tmpdir.name,
713-
branch_glob_pattern='*',
714-
from_timestamp=int(
715-
datetime.datetime(
716-
year=2004,
717-
month=1,
718-
day=1,
719-
hour=0,
720-
minute=0,
721-
second=1,
722-
tzinfo=datetime.timezone.utc,
723-
).timestamp()
724-
),
725-
)
726-
for result in results:
727-
result.pop('commit_id')
728-
self.assertListEqual(
729-
list1=results,
730-
list2=[],
731-
)

0 commit comments

Comments
 (0)