forked from groeck/chromeos-rebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
70 lines (58 loc) · 1.92 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
# -*- coding: utf-8 -*-"
import sqlite3
import os
import re
from config import rebasedb
from common import upstreamdb, nextdb
subject = re.compile("(ANDROID: *|CHROMIUM: *|CHROMEOS: *|UPSTREAM: *|FROMGIT: *|FROMLIST: *|BACKPORT: *)*(.*)")
def findsha(uconn, sha, desc):
'''
Try to find matching SHA in provided database.
Return updated SHA, or None if not found.
'''
c = uconn.cursor()
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 sha
# 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'" % 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, subject from commits where usha != ''")
for (sha, usha, desc) in c.fetchall():
uusha = findsha(uconn, usha, 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, desc)
if usha != uusha:
if not uusha:
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()
update_commits()