Trac is being migrated to new services! Issues can be found in our new YouTrack instance and WIKI pages can be found on our website.

Changes between Initial Version and Version 1 of MonotoneRcSnippets


Ignore:
Timestamp:
Oct 17, 2009, 10:55:47 PM (14 years ago)
Author:
John Bailey
Comment:

Add some useful lua snippets.

Legend:

Unmodified
Added
Removed
Modified
  • MonotoneRcSnippets

    v1 v1  
     1= .monotone/monotonerc Snippets =
     2
     3This page is intended to house various snippets of lua code for use in your `~/.monotone/monotonerc` to provide useful commands, automatically select keys, etc.
     4
     5== Useful Commands ==
     6
     7=== pluck-log ===
     8Monotone 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.
     9
     10{{{
     11--[[
     12    Pluck a revision with the log and authors filled in for the next commit log.
     13
     14    @author: Sadrul Habib Chowdhury (updated for mtn 0.43 by John Bailey)
     15--]]
     16
     17-- pluck-log command
     18function pluck_log(...)
     19    local revs = {...}
     20    local result
     21    local topsrcdir
     22    local logfile
     23    local log
     24
     25    -- mtn_automate() returns a pair of a boolean and a string; we don't really
     26    -- care about the boolean here, but we need to do something with it.
     27    result, topsrcdir = mtn_automate("get_workspace_root")
     28    topsrcdir = string.gsub(topsrcdir, "\n", "")
     29    logfile = io.open(topsrcdir .. "/_MTN/log", "r")
     30    log = ""
     31
     32    if logfile then
     33        log = logfile:read("*all")
     34        logfile:close()
     35    end
     36
     37    table.foreach(revs,
     38        function (index, rev)
     39            r, sel = mtn_automate("select", rev)
     40
     41            if r == false then return end
     42
     43            for rev in sel:gmatch("%S+") do
     44                r, certs = mtn_automate("certs", rev)
     45
     46                certs:gsub("%s+key \"(.-)\"\n%s*signature \"(.-)\"\n%s*name \"(.-)\"\n%s*value \"(.-)\"\n%s*trust \"(.-)\"",
     47                        function(key, sig, name, value, trust)
     48                            if name == "changelog" then
     49                                log = log .. "*** Plucked rev " .. rev .. " (" .. key .. "):\n" .. value .. "\n"
     50                            end
     51                        end
     52                    )
     53                execute("mtn", "pluck", "-r", rev)
     54            end
     55        end
     56    )
     57
     58    logfile = io.open(topsrcdir .. "/_MTN/log", "w")
     59    logfile:write(log)
     60    logfile:close()
     61end
     62
     63register_command("pluck-log", "REVISION1 [REVISION2 [...]]", "Pluck a revision with a good log",
     64        "This plucks a list of revisions, each individually, and adds the changelog of each revision for the next commit log." ..
     65        "\nEXAMPLE:\tmtn pluck-log h:im.pidgin.pidgin deadbeef\n",
     66        "pluck_log")
     67}}}
     68
     69== Key Selection ==
     70If 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.
     71
     72=== Select for Commits ===
     73This 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.
     74
     75{{{
     76function get_branch_key (branch)
     77    d = { ["im.pidgin"]="keyID@pidgin.im",
     78          ["org.guifications"]="keyID@guifications.org",
     79          ["im.vulture"]="keyID@vulture.im"
     80    }
     81
     82    for k, v in pairs(d) do
     83        if string.find(branch, k) then
     84            return v
     85        end
     86    end
     87end
     88}}}
     89
     90=== Select for Netsync ===
     91Netsync 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.
     92
     93{{{
     94function get_netsync_key(server, include, exclude)
     95    d = { ["mtn.pidgin.im"]="keyID@pidgin.im",
     96          ["mtn.vulture.im"]="keyID@vulture.im"
     97    }
     98
     99    for k, v in pairs(d) do
     100        if string.find(server, k) then
     101            return v
     102        end
     103    end
     104end
     105}}}
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!