[RFC/PATCH] Writing hooks doc

John Arbash Meinel john at arbash-meinel.com
Wed Jul 23 03:04:33 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
| Hi,
|
| This patch isn't complete, but I thought I should send what I had and
get some
| early feedback.  It adds some text to the User Guide to explain in
more detail
| how to write a useful hook.
|
| I used my experience with writing the example GNOME
pre_change_branch_tip hooks
| as a guide.
|
| Things I'm not fully satisfied with:
|
|  * all the XXXs :)
|  * particularly the XXX about terminology: “hook” vs. “hook function”
|  * I'm not sure if the User Guide is the best place for this doc, but
the admin
|    guide is just a stub at the moment.
|  * the “Getting the contents of a file at some revision” section is pretty
|    messy.  I think ideally we'd just have a simpler API rather than a doc
|    explaining how to deal with a complicated one that is easy to get
wrong.
|
| So this isn't really ready for merging, but I wanted to get some feedback.
|
| -Andrew.
|
|

By the way, I would recommend:

+    def check_maintainers_file(params):
+        # Check MAINTAINERS file has a "Userid:" line.
+        repo = params.branch.repository
+        new_inventory = repo.get_inventory(params.new_revid)
+        file_id = new_inventory.path2id('MAINTAINERS')
+        if file_id is None:
+            raise errors.TipChangeRejected(
+                "Projects must have a MAINTAINERS file.")
+        file_bytes_iter = repo.iter_files_bytes(
+            [(file_id, new_inventory[file_id].revision, None)])
+        file_bytes = ''.join(bytes for (ignored, bytes) in file_bytes_iter)
+        for line in file_bytes.splitlines():
+            if line.startswith('Userid:'):
+                return
+        raise errors.TipChangeRejected("A valid MAINTAINERS file is
required.")


repo = params.branch.repository
new_tree = repo.revision_tree(params.new_revid)
file_id = new_tree.path2id('MAINTAINERS')
if file_id is None:
...
file_bytes = new_tree.get_file_text(file_id)

alternatively

file_lines = new_tree.get_file_lines(file_id)

since that seems to be what your erally want.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiGkbEACgkQJdeBCYSNAAMJZACfVEyTuWk4qcpMByzbZA9dLWe4
JsMAn3ieGUX5ipwLDWKQ7uwqwSRbrzb8
=j6ey
-----END PGP SIGNATURE-----



More information about the bazaar mailing list