[Python-checkins] r85147 - in tracker/instances/python-dev: detectors/patches.py html/file.item.html lib/identify_patch.py schema.py
martin.v.loewis
python-checkins at python.org
Fri Oct 1 22:55:51 CEST 2010
Author: martin.v.loewis
Date: Fri Oct 1 22:55:51 2010
New Revision: 85147
Log:
Add branch identification to files.
Modified:
tracker/instances/python-dev/detectors/patches.py
tracker/instances/python-dev/html/file.item.html
tracker/instances/python-dev/lib/identify_patch.py
tracker/instances/python-dev/schema.py
Modified: tracker/instances/python-dev/detectors/patches.py
==============================================================================
--- tracker/instances/python-dev/detectors/patches.py (original)
+++ tracker/instances/python-dev/detectors/patches.py Fri Oct 1 22:55:51 2010
@@ -4,6 +4,7 @@
# the "patch" keyword should get set automatically.
import posixpath
+import identify_patch
patchtypes = ('.diff', '.patch')
sourcetypes = ('.diff', '.patch', '.py')
@@ -40,7 +41,19 @@
if patchid not in newvalues['keywords']:
newvalues['keywords'].append(patchid)
+def patches_branch(db, cl, nodeid, oldvalues):
+ # there shouldn't be old values
+ assert not oldvalues
+ if not ispatch(cl.get(nodeid, 'name'), patchtypes):
+ return
+ revno, branch = identify_patch.identify(db, cl.get(nodeid, 'content'))
+ if revno:
+ cl.set(nodeid, revision=str(revno))
+ if branch:
+ cl.set(nodeid, branch=branch)
+
def init(db):
db.file.audit('create', patches_text_plain)
+ db.file.react('create', patches_branch)
db.issue.audit('create', patches_keyword)
db.issue.audit('set', patches_keyword)
Modified: tracker/instances/python-dev/html/file.item.html
==============================================================================
--- tracker/instances/python-dev/html/file.item.html (original)
+++ tracker/instances/python-dev/html/file.item.html Fri Oct 1 22:55:51 2010
@@ -34,6 +34,12 @@
for security reasons, it's not permitted to set content type to <i>text/html</i>.</td>
</tr>
<tr>
+ <th>Tracker Branch</th><td tal:content="structure context/branch/field"/>
+ </tr>
+ <tr>
+ <th>Tracker Revision</th><td tal:content="structure context/revision/field"/>
+ </tr>
+ <tr>
<th i18n:translate="">SpamBayes Score</th>
<td tal:content="structure context/spambayes_score/plain"></td>
</tr>
Modified: tracker/instances/python-dev/lib/identify_patch.py
==============================================================================
--- tracker/instances/python-dev/lib/identify_patch.py (original)
+++ tracker/instances/python-dev/lib/identify_patch.py Fri Oct 1 22:55:51 2010
@@ -1,7 +1,17 @@
-import subprocess
+import subprocess, re
from xml.etree import ElementTree
+def identify(db, patch):
+ """Return revision number and branch of a patch;
+ either value may become None."""
+ m = re.search('---.* ([0-9]+)', patch)
+ if not m:
+ return None, None
+ rev = int(m.group(1))
+ return rev, find_branch(db, rev)
+
def find_branch(db, rev):
+ """Return the branch name for a given revision, or None."""
c = db.cursor
c.execute('select branch from svnbranch where rev=%s', (rev,))
branch = c.fetchone()
@@ -11,6 +21,8 @@
return fill_revs(db, lookfor=rev)
def fill_revs(db, lookfor=None):
+ """Initialize/update svnbranch table. If lookfor is given,
+ return its branch, or None if that cannot be determined."""
result = None
c = db.cursor
c.execute('select max(rev) from svnbranch')
@@ -19,6 +31,9 @@
start = 1
else:
start = start+1
+ if lookfor and lookfor < start:
+ # revision is not in database
+ return None
p = subprocess.Popen(['svn', 'log', '-r%s:HEAD' % start, '--xml', '-v',
'http://svn.python.org/projects'],
stdout = subprocess.PIPE,
Modified: tracker/instances/python-dev/schema.py
==============================================================================
--- tracker/instances/python-dev/schema.py (original)
+++ tracker/instances/python-dev/schema.py Fri Oct 1 22:55:51 2010
@@ -130,10 +130,16 @@
spambayes_misclassified=Boolean(),)
file = FileClass(db, "file",
- name=String(),
- description=String(indexme='yes'),
- spambayes_score=Number(),
- spambayes_misclassified=Boolean(),)
+ name=String(),
+ description=String(indexme='yes'),
+ spambayes_score=Number(),
+ spambayes_misclassified=Boolean(),
+ # filled out if this is a patch
+ revision=String(),
+ branch=String(),
+ # filled out if a corresponding Rietveld
+ # patchset exists for the issue
+ patchset=String(),)
# IssueClass automatically gets these properties in addition to the Class ones:
# title = String()
More information about the Python-checkins
mailing list