Module: display_branches.lua
Author: RichardLevitte
Included in monotone: no
Compatible with monotone version 0.41 and on
Description
This is a toy lua hook for monotone that displays what branches were affected by a monotone netsync operation and how many revisions or certs were transfered in each branch. For example, it might look like this:
$ mtn pull mtn: connecting to mtn://monotone.ca/monotone mtn: include pattern net.venge.monotone* mtn: exclude pattern mtn: finding items to synchronize: mtn: certificates | keys | revisions mtn: 43551 | 55 | 14326 mtn: bytes in | bytes out | certs in | revs in mtn: 3.7 k | 3.5 k | 2/2 | 0/0 mtn: successful exchange with mtn://monotone.ca/monotone Received data on branches: net.venge.monotone.monotone-0.99 (2)
$ mtn push mtn: connecting to mtn://monotone.ca/monotone-web mtn: include pattern * mtn: exclude pattern mtn: finding items to synchronize: mtn: certificates | keys | revisions mtn: 2600 | 20 | 858 mtn: bytes in | bytes out | certs in | revs in mtn: 4.3 k | 9.4 k | 4/4 | 1/1 mtn: successful exchange with mtn://monotone.ca/monotone-web Sent data on branches: net.venge.monotone.web.ikiwiki (1)
Source
-- Lua snippet to display what branches were affected by revisions and certs
-- that came into the database. I integrate it into my ~/.monotone/monotonerc
-- /Richard Levitte
--
-- Released as public domain
do
netsync_branches = {}
function RL_note_netsync_cert_received(direction,rev_id,key,name,value,nonce)
if name == "branch" then
if netsync_branches[direction][nonce][value] == nil then
netsync_branches[direction][nonce][value] = 1
else
netsync_branches[direction][nonce][value] =
netsync_branches[direction][nonce][value] + 1
end
end
end
notifier = {
["start"] =
function(session_id,...)
netsync_branches["received"] = {}
netsync_branches["sent"] = {}
netsync_branches["received"][session_id] = {}
netsync_branches["sent"][session_id] = {}
return "continue",nil
end,
["revision_received"] =
function(new_id,revision,certs,session_id)
for , item in pairs(certs) do
RL_note_netsync_cert_received("received",
new_id,
item.key,
item.name,
item.value,
session_id)
end
return "continue",nil
end,
["revision_sent"] =
function(new_id,revision,certs,session_id)
for , item in pairs(certs) do
RL_note_netsync_cert_received("sent",
new_id,
item.key,
item.name,
item.value,
session_id)
end
return "continue",nil
end,
["cert_received"] =
function(rev_id,key,name,value,session_id)
RL_note_netsync_cert_received("received",
rev_id,
key,name,value,
session_id)
return "continue",nil
end,
["cert_sent"] =
function(rev_id,key,name,value,session_id)
RL_note_netsync_cert_received("sent",
rev_id,
key,name,value,
session_id)
return "continue",nil
end,
["end"] =
function(session_id,status)
-- only try to display results if we got
-- at least partial contents
if status > 211 then
return "continue",nil
end
<span class="hl kwa">local</span> first <span class="hl opt">=</span> <span class="hl kwa">true</span>
<span class="hl kwa">for</span> item<span class="hl opt">,</span> amount <span class="hl kwa">in</span> <span class="hl kwd">pairs</span><span class="hl opt">(</span>netsync_branches<span class="hl opt">[</span><span class="hl str">"received"</span><span class="hl opt">][</span>session_id<span class="hl opt">])</span>
<span class="hl kwa">do</span>
<span class="hl kwa">if</span> first <span class="hl kwa">then</span>
io<span class="hl opt">.</span>stderr<span class="hl opt">:</span><span class="hl kwb">write</span><span class="hl opt">(</span><span class="hl str">"Received data on branches:</span><span class="hl esc">\n</span><span class="hl str">"</span><span class="hl opt">)</span>
first <span class="hl opt">=</span> <span class="hl kwa">false</span>
<span class="hl kwa">end</span>
io<span class="hl opt">.</span>stderr<span class="hl opt">:</span><span class="hl kwb">write</span><span class="hl opt">(</span><span class="hl str">" "</span><span class="hl opt">,</span>item<span class="hl opt">,</span><span class="hl str">" ("</span><span class="hl opt">,</span>amount<span class="hl opt">,</span><span class="hl str">")</span><span class="hl esc">\n</span><span class="hl str">"</span><span class="hl opt">)</span>
<span class="hl kwa">end</span>
netsync_branches<span class="hl opt">[</span><span class="hl str">"received"</span><span class="hl opt">][</span>session_id<span class="hl opt">] =</span> <span class="hl kwa">nil</span>
first <span class="hl opt">=</span> <span class="hl kwa">true</span>
<span class="hl kwa">for</span> item<span class="hl opt">,</span> amount <span class="hl kwa">in</span> <span class="hl kwd">pairs</span><span class="hl opt">(</span>netsync_branches<span class="hl opt">[</span><span class="hl str">"sent"</span><span class="hl opt">][</span>session_id<span class="hl opt">])</span>
<span class="hl kwa">do</span>
<span class="hl kwa">if</span> first <span class="hl kwa">then</span>
io<span class="hl opt">.</span>stderr<span class="hl opt">:</span><span class="hl kwb">write</span><span class="hl opt">(</span><span class="hl str">"Sent data on branches:</span><span class="hl esc">\n</span><span class="hl str">"</span><span class="hl opt">)</span>
first <span class="hl opt">=</span> <span class="hl kwa">false</span>
<span class="hl kwa">end</span>
io<span class="hl opt">.</span>stderr<span class="hl opt">:</span><span class="hl kwb">write</span><span class="hl opt">(</span><span class="hl str">" "</span><span class="hl opt">,</span>item<span class="hl opt">,</span><span class="hl str">" ("</span><span class="hl opt">,</span>amount<span class="hl opt">,</span><span class="hl str">")</span><span class="hl esc">\n</span><span class="hl str">"</span><span class="hl opt">)</span>
<span class="hl kwa">end</span>
netsync_branches<span class="hl opt">[</span><span class="hl str">"sent"</span><span class="hl opt">][</span>session_id<span class="hl opt">] =</span> <span class="hl kwa">nil</span>
<span class="hl kwa">return</span> <span class="hl str">"continue"</span><span class="hl opt">,</span><span class="hl kwa">nil</span>
<span class="hl kwa">end</span>
}
local v,m = push_hook_functions(notifier)
if not v then
error(m)
elseif m then
io.stderr:write("Warning: ",m,"\n")
end
end
Installation
Just download the source (display_branches.lua
) and include it from
your monotonerc
with the
include
command