bug 453046, add mirror hook for pushlog, json export with new pushes hook, r=ted, djc
authorAxel Hecht <l10n@mozilla.com>
Thu, 02 Oct 2008 23:25:08 +0200
changeset 45 58dba74cfa4b
parent 44 1f5164ca184a
child 46 fced04046f58
push id19
push useraxel@mozilla.com
push dateThu, 02 Oct 2008 21:25:19 +0000
reviewersted, djc
bugs453046
bug 453046, add mirror hook for pushlog, json export with new pushes hook, r=ted, djc
pushlog-feed.py
--- a/pushlog-feed.py
+++ b/pushlog-feed.py
@@ -292,13 +292,53 @@ def pushlogHTML(web, req, tmpl):
                 rev=0,
                 entries=lambda **x: changelist(limit=0,**x),
                 latestentry=lambda **x: changelist(limit=1,**x),
                 startdate=startdate,
                 enddate=enddate,
                 query=dates,
                 archives=web.archivelist("tip"))
 
+def pushes_worker(basepath, startID=0, endID=None):
+    stmt = 'SELECT id, user, date, rev, node from pushlog INNER JOIN changesets ON id = pushid WHERE id > ? %s ORDER BY id ASC, rev ASC'
+
+    args = (startID,)
+    if endID is not None:
+        stmt = stmt % 'and id <= ?'
+        args = (startID, endID)
+    else:
+        stmt = stmt % ""
+    if os.path.basename(basepath) != '.hg':
+        basepath = os.path.join(basepath, '.hg')
+    conn = sqlite.connect(os.path.join(basepath, 'pushlog2.db'))
+    pushes = {}
+    for id, user, date, rev, node in conn.execute(stmt, args):
+        if id in pushes:
+            pushes[id]['changesets'].append(node)
+        else:
+            pushes[id] = {'user': user,
+                          'date': date,
+                          'changesets': [node]
+                          }
+    return pushes
+
+def pushes(web, req, tmpl):
+    repopath = web.repo.path
+    startID = 'startID' in req.form and req.form['startID'][0] or 0
+    endID = 'endID' in req.form and req.form['endID'][0] or None
+    data = pushes_worker(repopath, startID, endID)
+    return tmpl('pushes', data=data)
+
+def printpushlog(ui, repo, *args):
+    from hgwebjson import HGJSONEncoder
+    e = HGJSONEncoder()
+    startID = len(args) and args[0] or 0
+    endID = len(args) > 1 and args[1] or None
+    print e.encode(pushes_worker(repo.path, startID, endID))
+
 
 addcommand(pushlogFeed, 'pushlog')
 addwebcommand(pushlogHTML, 'pushloghtml')
+addwebcommand(pushes, 'pushes')
 
-cmdtable = {}
+cmdtable = {
+    'printpushlog': (printpushlog, [], "hg printpushlog [startID [endID]]"),
+}