Mercurial > hg
comparison hgext/blackbox.py @ 18673:f27598902007
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.
author | Durham Goode <durham@fb.com> |
---|---|
date | Sat, 09 Feb 2013 09:09:46 -0800 |
parents | 18242716a014 |
children | f816aa377e0d |
comparison
equal
deleted
inserted
replaced
18672:b2b4ddc55caa | 18673:f27598902007 |
---|---|
73 # the blackbox setup for it. | 73 # the blackbox setup for it. |
74 if not repo.local(): | 74 if not repo.local(): |
75 return | 75 return |
76 | 76 |
77 ui.setrepo(repo) | 77 ui.setrepo(repo) |
78 | |
79 @command('^blackbox', | |
80 [('l', 'limit', 10, _('the number of events to show')), | |
81 ], | |
82 _('hg blackbox [OPTION]...')) | |
83 def blackbox(ui, repo, *revs, **opts): | |
84 '''view the recent repository events | |
85 ''' | |
86 | |
87 if not os.path.exists(repo.join('blackbox.log')): | |
88 return | |
89 | |
90 limit = opts.get('limit') | |
91 blackbox = repo.opener('blackbox.log', 'r') | |
92 lines = blackbox.read().split('\n') | |
93 | |
94 count = 0 | |
95 output = [] | |
96 for line in reversed(lines): | |
97 if count >= limit: | |
98 break | |
99 | |
100 # count the commands by matching lines like: 2013/01/23 19:13:36 root> | |
101 if re.match('^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} .*> .*', line): | |
102 count += 1 | |
103 output.append(line) | |
104 | |
105 ui.status('\n'.join(reversed(output))) |