[PATCH 5 of 6 V2] blackbox: adds a 'blackbox' command for viewing recent logs

Durham Goode durham at fb.com
Tue Feb 12 17:12:57 CST 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1360429786 28800
#      Sat Feb 09 09:09:46 2013 -0800
# Node ID 4e7e236ebc7dad934c79fb2ee7665a78ffd712e5
# Parent  73e79367c0519b8552b5a4d6ccfdccf9a4db926a
blackbox: adds a 'blackbox' command for viewing recent logs

Adds a 'hg blackbox' command for viewing the latest entries in the blackbox log.
By default it shows the last 10 entries, but -l allows the user to specify.

diff --git a/hgext/blackbox.py b/hgext/blackbox.py
--- a/hgext/blackbox.py
+++ b/hgext/blackbox.py
@@ -68,3 +68,31 @@
         return
 
     ui.setrepo(repo)
+
+ at command('^blackbox',
+    [('l', 'limit', 10, _('the number of events to show')),
+    ],
+    _('hg blackbox [OPTION]...'))
+def blackbox(ui, repo, *revs, **opts):
+    '''view the recent repository events
+    '''
+
+    if not os.path.exists(repo.join('blackbox.log')):
+        return
+
+    limit = opts.get('limit')
+    blackbox = repo.opener('blackbox.log', 'r')
+    lines = blackbox.read().split('\n')
+
+    count = 0
+    output = []
+    for line in reversed(lines):
+        if count >= limit:
+            break
+
+        # count the commands by matching lines like: 2013/01/23 19:13:36 root>
+        if re.match('^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} .*> .*', line):
+            count += 1
+        output.append(line)
+
+    ui.status('\n'.join(reversed(output)))


More information about the Mercurial-devel mailing list