.monotone/monotonerc Snippets

This page is intended to house various snippets of lua code for use in your ~/.monotone/monotonerc to provide useful commands, automatically select keys, etc.

Useful Commands

pluck-log

Monotone provides a 'pluck' command that allows cherry-picking a single revision or a range of revisions from one branch to apply to another. While a useful feature, the default commit message generated by 'pluck' is essentially useless. Sadrul wrote this pluck-log snippet to overcome the limitations of the original pluck command.

--[[
    Pluck a revision with the log and authors filled in for the next commit log.

    @author: Sadrul Habib Chowdhury (updated for mtn 0.43 by John Bailey
             and for mtn 0.45 by Daniel Atallah and Elliott Sales de Andrade)
--]]

-- pluck-log command
function pluck_log(...)
    local revs = {...}
    local result
    local topsrcdir
    local logfile
    local log

    -- mtn_automate() returns a pair of a boolean and a string; we don't really
    -- care about the boolean here, but we need to do something with it.
    result, topsrcdir = mtn_automate("get_workspace_root")
    topsrcdir = string.gsub(topsrcdir, "\n", "")
    logfile = io.open(topsrcdir .. "/_MTN/log", "r")
    log = ""

    if logfile then
        log = logfile:read("*all")
        logfile:close()
    end

    table.foreach(revs,
        function (index, rev)
            r, sel = mtn_automate("select", rev)

            if r == false then return end

            for rev in sel:gmatch("%S+") do
                local author,changelog
                r, certs = mtn_automate("certs", rev)

                certs:gsub("%s*key %[(.-)%]\n%s*signature \"(.-)\"\n%s*name \"(.-)\"\n%s*value \"(.-)\"\n%s*trust \"(.-)\"",
                        function(key, sig, name, value, trust)
                            if name == "changelog" then
                                changelog = value
                            elseif name == "author" then
                                author = value
                            end
                        end
                    )
                log = log .. "*** Plucked rev " .. rev .. " (" .. author .. "):\n" .. changelog .. "\n"
                execute("mtn", "pluck", "-r", rev)
            end
        end
    )

    logfile = io.open(topsrcdir .. "/_MTN/log", "w")
    logfile:write(log)
    logfile:close()
end

register_command("pluck-log", "REVISION1 [REVISION2 [...]]", "Pluck a revision with a good log",
        "This plucks a list of revisions, each individually, and adds the changelog of each revision for the next commit log." ..
        "\nEXAMPLE:\tmtn pluck-log h:im.pidgin.pidgin deadbeef\n",
        "pluck_log")

Key Selection

If you work on multiple projects using Monotone, you may have multiple private keys that you have to select among when working on these projects. These snippets help reduce the frequency with which you need to manually specify a key.

Select for Commits

This snippet was written by Gary Kramlich to manage multiple keys, and it takes advantage of a standard monotone lua hook. I have changed branch prefixes and key id's for the purpose of illustration.

function get_branch_key (branch)
    d = { ["im.pidgin"]="keyID@pidgin.im",
          ["org.guifications"]="keyID@guifications.org",
          ["im.vulture"]="keyID@vulture.im"
    }

    for k, v in pairs(d) do
        if string.find(branch, k) then
            return v
        end
    end
end

Select for Netsync

Netsync is the protocol monotone uses to transfer certificates between a client and a server. Whenever you use mtn sync, mtn pull, or mtn push, you are using netsync. John Bailey took Gary's get_branch_key snippet above and beat it into shape for another standard monotone lua hook.

function get_netsync_key(server, include, exclude)
    d = { ["mtn.pidgin.im"]="keyID@pidgin.im",
          ["mtn.vulture.im"]="keyID@vulture.im"
    }

    for k, v in pairs(d) do
        if string.find(server, k) then
            return v
        end
    end
end
Last modified 6 years ago Last modified on 06/04/11 08:56:58
All information, including names and email addresses, entered onto this website or sent to mailing lists affiliated with this website will be public. Do not post confidential information, especially passwords!