monotone

monotone Mtn Source Tree

Root/examples/display_branches.lua

1-- Lua snippet to display what branches were affected by revisions and certs
2-- that came into the database. It will display each branch name and the
3-- amount of times they each appeared.
4-- I integrate it into my ~/.monotone/monotonerc
5-- /Richard Levitte
6--
7-- Released as public domain
8
9do
10 netsync_branches = {}
11 function _note_netsync_cert_received(rev_id,key,name,value,nonce)
12 if name == "branch" then
13 if netsync_branches[nonce][value] == nil then
14 netsync_branches[nonce][value] = 1
15 else
16 netsync_branches[nonce][value] = netsync_branches[nonce][value] + 1
17 end
18 end
19 end
20
21 netsync_sent_branches = {}
22 function _note_netsync_cert_sent(rev_id,key,name,value,nonce)
23 if name == "branch" then
24 if netsync_sent_branches[nonce][value] == nil then
25 netsync_sent_branches[nonce][value] = 1
26 else
27 netsync_sent_branches[nonce][value] = netsync_sent_branches[nonce][value] + 1
28 end
29 end
30 end
31
32 push_netsync_notifier(
33 {
34 ["start"] =
35 function (nonce)
36 netsync_branches[nonce] = {}
37 netsync_sent_branches[nonce] = {}
38 end,
39 ["revision_received"] =
40 function (new_id,revision,certs,nonce)
41 for _, item in pairs(certs)
42 do
43 _note_netsync_cert_received(new_id,item.key,item.name,item.value,nonce)
44 end
45 end,
46 ["revision_sent"] =
47 function (new_id,revision,certs,nonce)
48 for _, item in pairs(certs)
49 do
50 _note_netsync_cert_sent(new_id,item.key,item.name,item.value,nonce)
51 end
52 end,
53 ["cert_received"] =
54 function (rev_id,key,name,value,nonce)
55 _note_netsync_cert_received(rev_id,key,name,value,nonce)
56 end,
57 ["cert_sent"] =
58 function (rev_id,key,name,value,nonce)
59 _note_netsync_cert_sent(rev_id,key,name,value,nonce)
60 end,
61 ["end"] =
62 function (nonce, status)
63 -- only try to display results if we got
64 -- at least partial contents
65 if status > 211 then
66 return
67 end
68
69 local first = true
70 for item, amount in pairs(netsync_branches[nonce])
71 do
72 if first then
73 io.stderr:write("Received data on branches:\n")
74 first = false
75 end
76 io.stderr:write(" ",item," (",amount,")\n")
77 end
78 netsync_branches[nonce] = nil
79
80 first = true
81 for item, amount in pairs(netsync_sent_branches[nonce])
82 do
83 if first then
84 io.stderr:write("Sent data on branches:\n")
85 first = false
86 end
87 io.stderr:write(" ",item," (",amount,")\n")
88 end
89 netsync_sent_branches[nonce] = nil
90 end
91 })
92end

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status