Skip to content

Commit 28761d6

Browse files
committed
sync-db: add function to extract date of first add to the git repository (#126)
1 parent 480cec5 commit 28761d6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/sync_db.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,22 @@ def _get_sha1_hash(game, romfile):
5252
except Exception:
5353
return ""
5454

55-
55+
def get_file_addition_date(file_path, repo_dir):
56+
try:
57+
result = subprocess.run(
58+
['git', 'log', '--diff-filter=A', '--follow', '--format=%ad', '--date=iso-strict', '--', file_path],
59+
cwd=repo_dir,
60+
stdout=subprocess.PIPE,
61+
stderr=subprocess.PIPE,
62+
text=True,
63+
check=True
64+
)
65+
dates = result.stdout.strip().splitlines()
66+
return dates[-1] if dates else None
67+
except subprocess.CalledProcessError as e:
68+
print(f"Error: {e.stderr}")
69+
return None
70+
5671
def run():
5772
inserted = 0
5873
updated = 0

0 commit comments

Comments
 (0)