monotone-devel
[Top][All Lists]
Advanced

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

[Monotone-devel] Lua based "mtn base" for convenient sub-branch manageme


From: Ralf S. Engelschall
Subject: [Monotone-devel] Lua based "mtn base" for convenient sub-branch management
Date: Mon, 29 Oct 2007 20:26:25 +0100
User-agent: Mutt/1.5.16 OpenPKG/CURRENT (2007-06-09)

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.

BACKGROUND:

My stuff stays on hierarchical Monotone branches following the scheme:
<project>.<component>[.<component>[...]][.TMP.<branch>[.<sub-branch>[...]]]

Examples are OSSP.ase.src (source of the "ase" software component in the
"OSSP" project) or OSSP.ase.src.TMP.keys.shop (the temporary/development
"shop" sub-branch of the "keys" branch of branch "OSSP.ase.src". In
this scheme while I work on OSSP.ase.src.TMP.keys.shop I regularily
want to merge in the latest revisions from OSSP.ase.src.TMP.keys and
on this branch in turn the latest revisions from OSSP.ase.src, etc. I
also regularily have to view the "mtn diff" between the current branch
and its base branch (e.g. "mtn diff -r h:OSSP.ase.src.TMP.keys -r
h:OSSP.ase.src.TMP.keys.shop", etc).

PROBLEM:

For this I regularily have to perform:

 $ mtn propagate OSSP.ase.src OSSP.ase.src.TMP.keys
 $ mtn propagate OSSP.ase.src.TMP.keys OSSP.ase.src.TMP.keys.shop

The problem is that I've three workspaces (one for OSSP.ase.src, one
for OSSP.ase.src.TMP.keys and one for OSSP.ase.src.TMP.keys.shop) and
hence I've to be careful about what branch is propagated to where.
Mainly, I've to closely follow the hierarchy or I too easily (at least
logically) garble up my setup.

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:

   # upgrade current branch and workspace with
   # the latest revisions on the base branch
   $ mtn base upgrade

   # show difference between current branch (actually the workspace
   # based on the current branch) and the base branch.
   $ mtn base diff

Voila! I both no longer have to remember and type the hierarchical names
of the branches and especially no longer "mtn propagate" any revisions
onto the wrong branches. Yes, I know, not very sophisticated stuff, but
simple and sufficient for my daily problem. And especially seamlessly
"integrated" into the Monotone UI. At least in case you are faced with
a similar sub-branching "problem", perhaps this is something for you,
too...

Yours,
                                       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 " ..
    "in the \".mtn-base\" file in the workspace 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 and base base
    local rc, branch_this = mtn_automate("get_option", "branch")
    if branch_this ~= nil then
        branch_this = string.match(branch_this, "^%s*(%S+)%s*$")
    end
    if branch_this == nil then
        io.stderr:write("mtn: base: ERROR: failed to determine current 
branch\n")
        return
    end
    local branch_base = read_contents_of_file(".mtn-base", "r")
    if branch_base ~= nil then
        branch_base = string.match(branch_base, "^%s*(%S+)%s*$")
    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]