forked from groeck/chromeos-rebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitdb-next.py
53 lines (47 loc) · 1.74 KB
/
initdb-next.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
# -*- coding: utf-8 -*-"
'''Generate database with commits which are in -next but not in mainline.
'''
from __future__ import print_function
import sqlite3
import os
import subprocess
from config import next_path
from common import workdir, nextdb, createdb, rebase_target_tag
def mktables(c):
# Create tables
c.execute("CREATE TABLE commits (sha text, subject text, in_baseline integer)")
c.execute("CREATE UNIQUE INDEX commit_sha ON commits (sha)")
c.execute("CREATE TABLE files (sha text, filename text)")
c.execute("CREATE INDEX file_sha ON files (sha)")
c.execute("CREATE INDEX file_name ON files (filename)")
def handle(c):
next_pick = rebase_target_tag() + '..'
commits = subprocess.check_output(['git', 'log', '--oneline', '--no-merges',
next_pick])
for commit in commits.splitlines():
if commit != "":
elem = commit.split(" ", 1)
sha = elem[0]
subject = elem[1].rstrip('\n')
subject = subject.decode('latin-1') \
if isinstance(subject, str) else subject
c.execute("INSERT INTO commits(sha, subject, in_baseline) VALUES (?, ?, ?)",
(sha, subject, 0,))
filenames = subprocess.check_output(['git', 'show', '--name-only',
'--format=', sha])
for fn in filenames.splitlines():
if fn != "":
c.execute("INSERT INTO files(sha, filename) VALUES (?, ?)", (sha, fn))
def initdb_next():
# Always re-create the 'next' database.
# Its SHAs are unstable and thus can not be relied on.
createdb(nextdb, mktables)
os.chdir(next_path)
conn = sqlite3.connect(nextdb)
c = conn.cursor()
handle(c)
conn.commit()
conn.close()
os.chdir(workdir)
if __name__ == "__main__":
initdb_next()