monotone-devel
[Top][All Lists]
Advanced

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

Re: [Monotone-devel] responses to some IRC discussion of 'automate'


From: Thomas Keller
Subject: Re: [Monotone-devel] responses to some IRC discussion of 'automate'
Date: Mon, 07 Aug 2006 10:21:24 +0200
User-agent: Thunderbird 1.5.0.2 (X11/20060501)

Nathaniel Smith wrote:
SELECT ra1.child
FROM revision_ancestry ra1
LEFT JOIN revision_ancestry ra2 ON ra1.child=ra2.parent
INNER JOIN revision_certs rc ON ra1.child=rc.id AND rc.name="branch" AND rc.value LIKE "net.venge.monotone"
WHERE ra2.parent IS NULL
GROUP BY ra1.child

Okay, I've spent a few minutes staring at this, and I give up :-).
Can you break down what it does in English?

Okay, here we go:

a) we left join the revision_anchestry table with itself to find any child revision which is not parent revision of another record (thus ra2.parent IS NULL); simple speak we find all leaves b) then we inner join with the certs table to ensure that we only get those leaves which have a particular branch cert attached, thus are heads of that branch

Speed is a reason.  But why do you think this could be slower?
Monotone can't use any smarter of an algorithm then the one you
outline here -- it would run the code that 'automate branches' runs,
then do a loop over that and run the code that 'automate heads' runs X
times, etc.

Thats right, but one could think about optimizations here, which would
only be possible in mtn itself. If the heads of multiple branches should
be found, one could do that with one single SQL statement and later group the result accordingly, while separate the results from each other. With the above SQL, this would look like the following:

SELECT rc.value, ra1.child
FROM revision_ancestry ra1
LEFT JOIN revision_ancestry ra2 ON ra1.child=ra2.parent
INNER JOIN revision_certs rc ON ra1.child=rc.id AND rc.name="branch"
AND rc.value LIKE "first.branch" OR rc.value LIKE "second.branch" OR ...
WHERE ra2.parent IS NULL
GROUP BY ra1.child
ORDER BY rc.value ASC

This would return

first.branch  | 123abc...
first.branch  | 456def...
second.branch | ...

You can of course do that the "hard" way, but then you'd indeed make for every single branch one query for its head revisions. Retrieving the other certs on the appropriate revision would then still need another query, of course. This can hardly be done in one.

There are only two advantages I see:
  -- You save a _little_ bit of time not having to parse multiple
     automate command requests.  But this is almost nothing.
  -- The API for users is a little bit simpler... but the API for my
     proposal is not at all complicated either.  In python, it would
     look like:
>
def get_lots_of_head_info(mtn):
    branches = mtn.branches()
    heads = {}
    for branch in branches:
        heads[branch] = mtn.heads(branch)
    certs_for_head = {}
    for head_set in heads.itervalues():
        for head in head_set:
            certs_for_head[head] = mtn.certs(head)
    return heads, certs_for_head

Easy to read and straightforward, and could actually be made even
shorter with some judicious use of list or generator comprehensions,
e.g.
    heads = dict((branch, mtn.heads(branch)) for branch in mtn.branches())
already gives you all branches and all heads, in one line, about as
efficiently as anything can :-).

Well, its nice to see that its that easy to do in Python, but its not that easy in other languages. The amount of verbosity which is needed e.g. in C++ with Qt is quite big, and because of Qt's "superior" signal and slot handling one would need to couple the querying of each set with each other, and this is very messy. I won't give you an example here, but ask somebody else with Qt experience and he'll tell you the same thing. Of course you might say now "Qt was your choice", well, right, Qt was my choice, because its fast, consistent and otherwise very easy to code for different platforms, but retrieving tiny bits of information from different sources and/or different handlers even (and each mtn automate command would need to get its own handler) is a major headache.

Thomas.

--
- "I know that I don't know." (Sokrates)
Guitone, a frontend for monotone: http://guitone.berlios.de
Music lyrics and more: http://musicmademe.com




reply via email to

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