-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate.py
executable file
·88 lines (69 loc) · 2.62 KB
/
update.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# -*- coding: utf-8 -*-"
"""Update rebase database with new information from upstream and next database"""
from __future__ import print_function
import sqlite3
import re
from common import rebasedb, upstreamdb, nextdb
subject = re.compile(
'(ANDROID: *|CHROMIUM: *|CHROMEOS: *|UPSTREAM: *|FROMGIT: *|FROMLIST: *|BACKPORT: *)*(.*)'
)
def findsha(uconn, sha, patchid, desc):
"""Try to find matching SHA in provided database.
Return updated SHA, or None if not found.
"""
c = uconn.cursor()
if sha is not None:
c.execute("select sha from commits where sha is '%s'" % sha)
usha = c.fetchone()
if usha:
# print(" Found SHA %s in upstream database" % usha)
return usha[0]
# Now look for patch id if provided
if patchid is not None:
c.execute("select sha from commits where patchid is '%s'" % patchid)
usha = c.fetchone()
if usha:
# print(" Found SHA %s in upstream database based on patch ID" % usha)
return usha[0]
# The SHA is not upstream, or not known at all.
# See if we can find the commit subject.
s = subject.search(desc)
if s:
sdesc = s.group(2).replace("'", "''")
c.execute("select sha from commits where subject is '%s'" % sdesc)
usha = c.fetchone()
if usha:
# print(" Found upstream SHA '%s' based on subject line" % usha)
return usha[0]
return None
def update_commits():
"""Validate 'usha' field in rebase database.
Verify if the upstream SHA actually exists by looking it up in the upstream
database. If it doesn't exist, and if a matching commit is not found either,
remove it.
"""
conn = sqlite3.connect(rebasedb)
uconn = sqlite3.connect(upstreamdb)
nconn = sqlite3.connect(nextdb) if nextdb else None
c = conn.cursor()
c.execute('select sha, usha, patchid, subject from commits')
for (sha, usha, patchid, desc) in c.fetchall():
uusha = findsha(uconn, usha, patchid, desc)
# if it is not in the upstream database, maybe it is in -next.
# Try to pick it up from there.
if uusha is None and nconn:
uusha = findsha(nconn, usha, None, desc)
if not uusha:
uusha = ''
if usha != uusha:
print("SHA '%s': Updating usha '%s' with '%s'" % (sha, usha, uusha))
c.execute("UPDATE commits set usha='%s' where sha='%s'" %
(uusha, sha))
conn.commit()
conn.close()
uconn.close()
if nconn:
nconn.close()
if __name__ == '__main__':
update_commits()