-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgithashtime.py
44 lines (30 loc) · 1009 Bytes
/
githashtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
from __future__ import print_function
import git
import os
from sourcetrie import get_rd_file, SourceTrie
import sys
def git_hash_time(hash, folders):
changes = set()
changes_file = get_rd_file('changes.txt')
if os.path.exists(changes_file):
with open(changes_file, 'r') as f:
changes = set([line.strip() for line in f.readlines()])
mtime = git.log('-1', hash, '--pretty=format:%ct')
if mtime == '':
return
mtime = int(mtime)
for folder in folders:
folder = folder.strip()
source_folder = '%s/src/main/java' % folder
if not os.path.isdir(source_folder):
source_folder = '%s/docroot/WEB-INF/src' % folder
if not os.path.isdir(source_folder):
source_folder = '%s/src' % folder
if not os.path.isdir(source_folder):
continue
for file in git.ls_files(source_folder).split('\n'):
if file not in changes and os.path.isfile(file):
os.utime(file, (mtime, mtime))
if __name__ == '__main__':
git_hash_time(sys.argv[1], sys.stdin.readlines())