# # # patch "examples/display_branches.lua" # from [ce3eb936fa49e05177ab31816d300f5a32742651] # to [656dc06747a5e55e1c1300b32bb25f13e140b758] # ============================================================ --- examples/display_branches.lua ce3eb936fa49e05177ab31816d300f5a32742651 +++ examples/display_branches.lua 656dc06747a5e55e1c1300b32bb25f13e140b758 @@ -6,47 +6,53 @@ -- -- Released as public domain -netsync_branches = {} -function note_netsync_start(nonce) - netsync_branches[nonce] = {} -end - -function _note_netsync_cert_received(rev_id,key,name,value,nonce) - if name == "branch" then - if netsync_branches[nonce][value] == nil then - netsync_branches[nonce][value] = 1 - else - netsync_branches[nonce][value] = netsync_branches[nonce][value] + 1 +do + netsync_branches = {} + function _note_netsync_cert_received(rev_id,key,name,value,nonce) + if name == "branch" then + if netsync_branches[nonce][value] == nil then + netsync_branches[nonce][value] = 1 + else + netsync_branches[nonce][value] = netsync_branches[nonce][value] + 1 + end end end -end -function note_netsync_revision_received(new_id,revision,certs,nonce) - for _, item in pairs(certs) - do - _note_netsync_cert_received(new_id,item.key,item.name,item.value,nonce) - end -end + push_netsync_notifier( + { + [start] = + function (nonce) + netsync_branches[nonce] = {} + end, + [revision_received] = + function (new_id,revision,certs,nonce) + for _, item in pairs(certs) + do + _note_netsync_cert_received(new_id,item.key,item.name,item.value,nonce) + end + end, + [cert_received] = + function (rev_id,key,name,value,nonce) + _note_netsync_cert_received(rev_id,key,name,value,nonce) + end, + ["end"] = + function (nonce, status) + -- only try to display results if we got + -- at least partial contents + if status > 211 then + return + end -function note_netsync_cert_received(rev_id,key,name,value,nonce) - _note_netsync_cert_received(rev_id,key,name,value,nonce) + local first = true + for item, amount in pairs(netsync_branches[nonce]) + do + if first then + io.stderr:write("Affected branches:\n") + first = false + end + io.stderr:write(" ",item," (",amount,")\n") + end + netsync_branches[nonce] = nil + end + }) end - -function note_netsync_end(nonce, status) - -- only try to display results if we got - -- at least partial contents - if status > 211 then - return - end - - local first = true - for item, amount in pairs(netsync_branches[nonce]) - do - if first then - io.stderr:write("Affected branches:\n") - first = false - end - io.stderr:write(" ",item," (",amount,")\n") - end - netsync_branches[nonce] = nil -end