-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfilter_split_soa.py
62 lines (50 loc) · 2.13 KB
/
filter_split_soa.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import sys
from git_fast_filter import Blob, Reset, FileChanges, Commit, FastExportFilter
from git_fast_filter import get_commit_count, get_total_objects
import re
import datetime
if len(sys.argv) != 4:
raise SystemExit("Syntax:\n %s SOURCE_REPO TARGET_REPO soa|non-soa")
source_repo = sys.argv[1]
target_repo = sys.argv[2]
soa_re = re.compile('^tests/org.jboss.tools.bpel.reddeer.*|^tests/org.jboss.tools.bpel.ui.bot.test.*|^tests/org.jboss.tools.bpmn2.itests.*|^tests/org.jboss.tools.drools.*|^tests/org.jboss.tools.esb.ui.bot.test.*|^tests/org.jboss.tools.jbpm.ui.bot.test.*|^tests/org.jboss.tools.modeshape.*|^tests/org.jboss.tools.switchyard.reddeer.*|^tests/org.jboss.tools.switchyard.ui.bot.test.*|^tests/org.jboss.tools.teiid.reddeer.*|^tests/org.jboss.tools.teiid.ui.bot.test.*')
poms_re = re.compile('^pom.xml|^tests/pom.xml')
if sys.argv[3] == 'soa':
soa = 1
elif sys.argv[3] == 'non-soa':
soa = 0
else:
raise SystemExit("Syntax:\n %s SOURCE_REPO TARGET_REPO soa|non-soa")
start = datetime.datetime.now()
total_objects = get_total_objects(source_repo) # blobs + trees
total_commits = get_commit_count(source_repo)
object_count = 0
commit_count = 0
def print_progress():
global object_count, commit_count, total_objects, total_commits
print "\rRewriting commits... %d/%d (%d objects)" \
% (commit_count, total_commits, object_count),
def my_blob_callback(blob):
global object_count
object_count += 1
print_progress()
def my_commit_callback(commit):
global commit_count
commit_count += 1
print_progress()
new_file_changes = []
if soa == 1:
for change in commit.file_changes:
if soa_re.match(change.filename) or poms_re.match(change.filename):
new_file_changes.append(change)
else:
for change in commit.file_changes:
if not soa_re.match(change.filename):
new_file_changes.append(change)
commit.file_changes = new_file_changes
filter = FastExportFilter(blob_callback = my_blob_callback,
commit_callback = my_commit_callback)
filter.run(source_repo, target_repo)
end = datetime.datetime.now()
print "End : " + str(end-start)