allow querying for changes between two changesets
authorTed Mielczarek <ted.mielczarek@gmail.com>
Tue, 29 Jul 2008 21:15:18 -0400
changeset 37 accff725eb903365de08e6bee1bf6db0ad649e69
parent 36 44a4db71c3e967fa3352777ded673bf370924244
child 38 e4fa26d9ea14031fee573a6868e8a4b7d01c2eea
push id14
push usertmielczarek@mozilla.com
push dateWed, 30 Jul 2008 01:15:25 +0000
allow querying for changes between two changesets
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -60,16 +60,46 @@ def getpushlogentriesbydate(conn, startd
     lastid = None
     for (id, user, date, node) in res:
         if tipsonly and id == lastid:
             continue
         entries.append((id,user,date,node))
         lastid = id
     return entries
 
+def getpushlogentriesbychangeset(conn, fromchange, tochange, tipsonly):
+    """Get entries in the push log between two changesets. Return changesets
+    pushed after |fromchange|, up to and including |tochange|.
+    If |tipsonly| is True, return only the tip changeset from each push."""
+    entries = []
+    # find the changeset before the first changeset
+    fromchange += "%"
+    e = conn.execute("SELECT pushid FROM changesets WHERE node LIKE ?", (fromchange,)).fetchone()
+    if e is None:
+        return []
+    fromid = e[0]
+    # find the last changeset
+    tochange += "%"
+    e = conn.execute("SELECT pushid FROM changesets WHERE node LIKE ?", (tochange,)).fetchone()
+    if e is None:
+        return []
+    toid = e[0]
+    if fromid >= toid:
+        return []
+    # now get all the changesets from right after fromchange, up to and
+    # including tochange
+    res = conn.execute("SELECT id, user, date, node FROM pushlog LEFT JOIN changesets ON id = pushid WHERE id > ? AND id <= ? ORDER BY date DESC, rev DESC", (fromid, toid))
+    lastid = None
+    for (id, user, date, node) in res:
+        if tipsonly and id == lastid:
+            continue
+        entries.append((id,user,date,node))
+        lastid = id
+    return entries
+
 def gettotalpushlogentries(conn):
     """Return the total number of pushes logged in the pushlog."""
     return conn.execute("SELECT COUNT(*) FROM pushlog").fetchone()[0]
 
 def localdate(ts):
     t = time.localtime(ts)
     offset = time.timezone
     if t[8] == 1:
@@ -102,16 +132,22 @@ def pushlogSetup(web, req):
     dates = []
     if 'startdate' in req.form and 'enddate' in req.form:
         startdate = doParseDate(req.form['startdate'][0])
         enddate = doParseDate(req.form['enddate'][0])
         dates = [{'startdate':localdate(startdate), 'enddate':localdate(enddate)}]
         page = 1
         total = 1
         e = getpushlogentriesbydate(conn, startdate, enddate, tipsonly)
+    elif 'fromchange' in req.form and 'tochange' in req.form:
+        fromchange = req.form['fromchange'][0]
+        tochange = req.form['tochange'][0]
+        page = 1
+        total = 1
+        e = getpushlogentriesbychangeset(conn, fromchange, tochange, tipsonly)
     else:
         e = getpushlogentries(conn, (page - 1) * PUSHES_PER_PAGE, 10, tipsonly)
         total = gettotalpushlogentries(conn)
     proto = req.env.get('wsgi.url_scheme')
     if proto == 'https':
         proto = 'https'
         default_port = "443"
     else: