monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] Lua based "mtn base" for convenient sub-branch mana


From: Ralf S. Engelschall
Subject: Re: [Monotone-devel] Lua based "mtn base" for convenient sub-branch management
Date: Tue, 30 Oct 2007 09:12:40 +0100
User-agent: Mutt/1.5.16 OpenPKG/CURRENT (2007-06-09)

On Tue, Oct 30, 2007, William Uther wrote:

> On 30/10/2007, at 6:26 AM, Ralf S. Engelschall wrote:
>
>> Perhaps it is interesting also to someone else here, so please let
>> me share a small Lua-based extensional Monotone command here for the
>> record, which I'm currently using and which can be reused out-of-the-box
>> with 0.37 by others, too.
>
> [snip]
>
>> SOLUTION:
>>
>> In order to free my brain from having to remember all this stuff, I
>> now placed a ".mtn-base" file onto OSSP.ase.src.TMP.keys containing
>> the name of its base branch "OSSP.ase.src" and and a ".mtn-base"
>> file onto OSSP.ase.src.TMP.keys.shop containing the name of its
>> base branch "OSSP.ase.src.TMP.keys". Then I hacked up a small "mtn
>> base" command (implementation see below -- just paste into your
>> ~/.monotone/monotonerc) which allows me to conveniently use:
>
> [snip]
>
> Is there a reason you used a .mtn-base file rather than an attribute on the
> root dir?

Hmmm.... no real reason. I just had already two other custom .mtn-xxx
files (one the .mtn-message we recently discussed), so I used a file
for the "base" information here, too. But you're right, even more
elegant could be the use of an attribute on the root directory. OTOH an
attribute is more or less always committed while a file I can let stay
around without committing easily. So, I guess I want to support both
approaches ;-) I've changed the code to now support both (code appended
below). Thanks for the feedback.

                                       Ralf S. Engelschall
                                       address@hidden
                                       www.engelschall.com

--  extra command: "mtn base {upgrade|diff}"
register_command(
    "base", "upgrade|diff",
    "Upgrades or compares current branch against base branch",
    "Upgrade current branch from base branch or compares current " ..
    "branch against base branch. The base branch has to be stored " ..
    "either in the \"mtn:base\" attribute of the root directory " ..
    "or in a \".mtn-base\" file in the root directory.",
    "command_base"
)
function command_base(op)
    --  sanity check command line
    if op == nil then
        io.stderr:write("mtn: base: ERROR: no operation specified\n")
        return
    end
    if op ~= "upgrade" and op ~= "diff" then
        io.stderr:write("mtn: base: ERROR: either \"upgrade\" or \"diff\" 
operation has to be specified\n")
        return
    end

    --  determine current branch of workspace
    local branch_this = nil
    local rc, txt = mtn_automate("get_option", "branch")
    if txt ~= nil then
        branch_this = string.match(txt, "^%s*(%S+)%s*$")
    end
    if branch_this == nil then
        io.stderr:write("mtn: base: ERROR: failed to determine current 
branch\n")
        return
    end

    --  determine base branch of workspace
    local branch_base = nil
    local rc, txt = mtn_automate("get_attributes", ".")
    if txt ~= nil then
        branch_base = string.match(txt, "attr%s+\"mtn:base\"%s+\"([^\"]+)\"")
    end
    if branch_base == nil then
        local txt = read_contents_of_file(".mtn-base", "r")
        if txt ~= nil then
            branch_base = string.match(txt, "^%s*(%S+)%s*$")
        end
    end
    if branch_base == nil then
        io.stderr:write("mtn: base: ERROR: failed to determine base branch\n")
        return
    end

    --  dispatch according to operation
    if op == "upgrade" then
        --  upgrade current branch by merging in revisions of base branch
        local rc = execute("mtn", "propagate", branch_base, branch_this)
        if rc ~= 0 then
            io.stderr:write("mtn: revision: ERROR: failed to execute \"mtn 
propagate\"\n")
            return
        end
        rc = execute("mtn", "update")
        if rc ~= 0 then
            io.stderr:write("mtn: revision: ERROR: failed to execute \"mtn 
update\"\n")
            return
        end
    elseif op == "diff" then
        --  upgrade current branch by merging in revisions of base branch
        local rc = execute("mtn", "diff", "-r", "h:" .. branch_base, "-r", "h:" 
.. branch_this)
        if rc ~= 0 then
            io.stderr:write("mtn: revision: ERROR: failed to execute \"mtn 
diff\"\n")
            return
        end
    end
    return
end





reply via email to

[Prev in Thread] Current Thread [Next in Thread]