[MERGE] Config.get_user_section() API
Robert Collins
robertc at robertcollins.net
Tue Feb 5 03:41:08 GMT 2008
On Tue, 2008-02-05 at 12:21 +1000, Ian Clatworthy wrote:
>
>
> Can you give an example please?
Sure.
bzr-gtk on windows.
Anything on authenticated URL's
Anything with passwords and guis of any sort.
Anything on a locked tree.
Anything on windows for that matter.
> I appreciate that you find writing plugins really easy - you know
> Python
> and you know Bazaar's API. For someone who knows neither (like 80% of
> the development community), adding a line or two to a config file is
> an
> order of magnitude easier.
But its /not/ add a line or two to a config file. Its 'write an adapter
from bzr doing X to external thing doing Y'. In the case of 'please run
an external command to check the tree compiles properly' there are a
raft of issues:
- is there a working tree (consider commits on a smart server)
- is the tree locked (prevents external objects modifying tree state,
or even reading it with current dirstate)
- what about concurrency?
And you haven't reduced the complexity at all by moving it to shell,
unless *something else is going on*.
And I think something else is going on - not enough code reuse. Generic
tools imply some complexity. Our hooks are extremely generic, while
preserving needed state for performance and correctness.... Solving
trivial cases within a generic framework is often a case of writing a
trivial adapter - and the adapter which is hiding the complexity can be
reused. For instance, there is /no/ suitable hook for doing precommit
tests on an existing working tree, so I've done one where a new tree is
created on the fly (which ensures that partial commits are 'correctly'
tested):
precommit_check.py
-----
from bzrlib.branch import Branch
from bzrlib.export import export
from bzrlib.osutils import mkdtemp, rmtree
from bzrlib.shellcommand import run_shell_command
def check_external_script(local, master, old_revno, old_revid,
new_revno, new_revid, tree_delta, future_tree):
"""This ensures we have a working tree on disk, then runs a script.
The script is run in a pristine tree. If compilation etc is an issue
consider cc_cache. The pristine tree is created to ensure that
partial commits and unversioned files do not prevent accurate test
results.
"""
config = master.get_branch_config()
script_path = config.get_user_option('precommit_check'):
if not script_path:
return
if local is None:
branch = master
else:
branch = local
tmp_root = mkdtemp(prefix='precommit-test', suffix='.tmp')
try:
tree_path = tmp_root + '/exported_tree'
export(future_tree, tree_path, "dir", None)
run_shell_command(script_path, cwd=tree_path)
finally:
rmtree(tmp_root)
Branch.hooks.install_hook('pre_commit', check_external_script)
# optional but nice follows
Branch.hooks.name_hook(check_external_script, "external_test_script")
------
> Your idea about putting the scripts into a directory is probably
> better
> still. I'll go with that, assuming we're happy to make an exception to
> our rule about "users shouldn't touch anything under .bzr".
I would say .bzr/hooks/branch/precommit.d/ for instance. But also - how
about:
~/.bzr/hooks/branch/precommit.d/
and
/etc/bzr/hooks/branch/precommit.d/
Having the user edit branch.conf is as objectionable as having them put
a file in .bzr, because branch.conf is in .bzr.
-Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20080205/c1939099/attachment.pgp
More information about the bazaar
mailing list