add a tipsonly query parameter for pushlog output to see only tip revisions
authorTed Mielczarek <ted.mielczarek@gmail.com>
Tue, 29 Jul 2008 18:01:19 -0400
changeset 34 c5106c94d59d1482798e43a593867d10c8c31c3a
parent 33 7fbe834c1b97d7f1bf22ce358fad80a472c7808b
child 35 7b1f803a8b016f09aa37e566087fd0c3498afe3c
push id11
push usertmielczarek@mozilla.com
push dateTue, 29 Jul 2008 22:01:32 +0000
add a tipsonly query parameter for pushlog output to see only tip revisions
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -30,35 +30,44 @@ def addcommand(f, name):
     hgwebprotocol.__all__.append(name)
 
 def addwebcommand(f, name):
     setattr(hgwebcommands, name, f)
     hgwebcommands.__all__.append(name)
 
 ATOM_MIMETYPE = 'application/atom+xml'
 
-def getpushlogentries(conn, start, count):
+def getpushlogentries(conn, start, count, tipsonly):
     """Get entries from the push log. Select |count| pushes starting at offset
     |start|, in reverse chronological order, and then return all changes
     pushed in these pushes. Returns a list of tuples of
-    (pushid, user, date, node)."""
+    (pushid, user, date, node). If |tipsonly| is True, return only the tip
+    changeset from each push."""
     entries = []
     res = conn.execute("SELECT id, user, date FROM pushlog ORDER BY date DESC LIMIT ? OFFSET ?", (count,start))
     for (id,user,date) in res:
-        res2 = conn.execute("SELECT node FROM changesets WHERE pushid = ? ORDER BY rev DESC", (id,))
+        limit = ""
+        if tipsonly:
+            limit = " LIMIT 1"
+        res2 = conn.execute("SELECT node FROM changesets WHERE pushid = ? ORDER BY rev DESC" + limit, (id,))
         for node, in res2:
             entries.append((id,user,date,node))
     return entries
 
-def getpushlogentriesbydate(conn, startdate, enddate):
-    """Get entries in the push log in a date range."""
+def getpushlogentriesbydate(conn, startdate, enddate, tipsonly):
+    """Get entries in the push log in a date range. If |tipsonly| is True,
+    return only the tip changeset from each push."""
     entries = []
     res = conn.execute("SELECT id, user, date, node FROM pushlog LEFT JOIN changesets ON id = pushid WHERE date > ? AND date < ? ORDER BY date DESC, rev DESC", (startdate, enddate))
+    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)
@@ -82,27 +91,29 @@ def pushlogSetup(web, req):
     pushdb = os.path.join(web.repo.path, "pushlog2.db")
     conn = sqlite.connect(pushdb)
 
     if 'node' in req.form:
         page = int(req.form['node'][0])
     else:
         page = 1
 
+    tipsonly = False
+    if 'tipsonly' in req.form and req.form['tipsonly'][0] == '1':
+        tipsonly = True
     dates = []
     if 'startdate' in req.form and 'enddate' in req.form:
         startdate = doParseDate(req.form['startdate'][0])
         enddate = doParseDate(req.form['enddate'][0])
-        print "startdate, enddate: %d, %d" % (startdate, enddate)
         dates = [{'startdate':localdate(startdate), 'enddate':localdate(enddate)}]
         page = 1
         total = 1
-        e = getpushlogentriesbydate(conn, startdate, enddate)
+        e = getpushlogentriesbydate(conn, startdate, enddate, tipsonly)
     else:
-        e = getpushlogentries(conn, (page - 1) * PUSHES_PER_PAGE, 10)
+        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:
         proto = 'http'
         default_port = "80"