[MERGE][RFC] post_change_branch_tip hook

Andrew Bennetts andrew at canonical.com
Tue Apr 8 04:54:31 BST 2008


It seems this message wasn't seen by bundle buggy for some reason?

-Andrew.

Ian Clatworthy wrote:
> Attached is an initial cut at supporting a new hook,
> post_change_branch_tip. Once this particular hook is supported and
> Andrew Bennetts adds the necessary glue to the Smart Server, I think
> we'll have _the_ server-side hook many teams/tools are looking for and
> not finding yet in Bazaar.
> 
> I *think* this is basically right design wise, i.e. parameters are
> passed to the hook via a Params object so that parameters can be lazily
> instantiated down the track if required. Do we want a branch field added
> to the Params object though? And are the names of the field ok? I've
> picked the (short) names to be consistent with the fields in PushResult
> FWIW. Having said that, I decided to call the class *Params rather than
> *Result because that seemed to make more sense. I'm happy to change that
> though if people think I should.
> 
> The code still need tests and I'd welcome advice from the testing gurus
> as to how best add those. In discussions with Andrew and John in
> Chicago, their feeling was that branch_implementation tests were needed
> so that we'd catch if and when a new branch format accidentally dropped
> support for it (as happened with set_rh). What other tests would
> developers like to see?
> 
> I've also "deprecated" set_rh by removing its description from the
> documentation. It only works with older branch formats and we're not
> planning to fix that because it can't be implemented efficiently.
> 
> Any other thoughts or comments?
> 
> Ian C.

> # Bazaar merge directive format 2 (Bazaar 0.90)
> # revision_id: ian.clatworthy at canonical.com-20080401080826-\
> #   85zjvdb6w6x8ah5d
> # target_branch: http://people.ubuntu.com/~ianc/bzr/ianc-integration
> # testament_sha1: 820e806629c9c613dd62346fda933ac3980e226a
> # timestamp: 2008-04-01 18:28:58 +1000
> # base_revision_id: pqm at pqm.ubuntu.com-20080401055945-3pmuiy0q0301axv6
> # 
> # Begin patch
> === modified file 'NEWS'
> --- NEWS	2008-04-01 04:19:06 +0000
> +++ NEWS	2008-04-01 08:08:26 +0000
> @@ -14,6 +14,10 @@
>  
>     * bzr main script cannot be imported (Benjamin Peterson)
>  
> +   * The ``set_rh`` branch hook is now deprecated. Please migrate
> +     any plugins using this hook to use an alternative, e.g.
> +     ``post_change_branch_tip``. (Ian Clatworthy)
> +
>     * When a plugin cannot be loaded as the file path is not a valid
>       python module name bzr will now strip a ``bzr_`` prefix from the
>       front of the suggested name, as many plugins (e.g. bzr-svn)
> @@ -27,6 +31,10 @@
>      * Added mail-mode GNU Emacs mail package as a mail_client.
>        (Xavier Maillard, Bojan Nikolic)
>  
> +    * New ``post_change_branch_tip`` hook that is called after the
> +      branch tip is moved but while the branch is still write-locked.
> +      See the User Reference for signature details. (Ian Clatworthy)
> +
>    IMPROVEMENTS:
>  
>      * Diff is now more specific about execute-bit changes it describes
> 
> === modified file 'bzrlib/branch.py'
> --- bzrlib/branch.py	2008-03-28 03:54:40 +0000
> +++ bzrlib/branch.py	2008-04-01 08:08:26 +0000
> @@ -1025,12 +1025,43 @@
>          # local is the local branch or None, master is the target branch,
>          # and an empty branch recieves new_revno of 0, new_revid of None.
>          self['post_uncommit'] = []
> +        # Invoked after the tip of a branch changes.
> +        # the api signature is
> +        # (params) where params is a ChangeBranchTipParams object.
> +        self['post_change_branch_tip'] = []
>  
>  
>  # install the default hooks into the Branch class.
>  Branch.hooks = BranchHooks()
>  
>  
> +class ChangeBranchTipParams(object):
> +    """Object holding parameters passed to *_change_branch_tip hooks.
> +    
> +    There are 4 fields that hooks may wish to access:
> +        
> +        * old_revid - revision id before the change
> +        * new_revid - revision id after the change
> +        * old_revno - revision number before the change
> +        * new_revno - revision number after the change
> +        
> +    The revid fields are strings. The revno fields are integers.
> +    """
> +
> +    def __init__(self, old_revid, new_revid, old_revno, new_revno):
> +        """Create a group of ChangeBranchTip parameters.
> +
> +        :param old_revid: Tip revision id before the change.
> +        :param new_revid: Tip revision id after the change.
> +        :param old_revno: Revision number before the change.
> +        :param new_revno: Revision number after the change.
> +        """
> +        self.old_revid = old_revid
> +        self.new_revid = new_revid
> +        self.old_revno = old_revno
> +        self.new_revno = new_revno
> +
> +
>  class BzrBranchFormat4(BranchFormat):
>      """Bzr branch format 4.
>  
> @@ -1383,6 +1414,22 @@
>          for hook in Branch.hooks['set_rh']:
>              hook(self, rev_history)
>  
> +    def _make_branch_tip_hook_params(self, new_revision_id, new_revno=None):
> +        """Construct a Params object for passing to *branch_tip hooks."""
> +        if Branch.hooks['post_change_branch_tip']:
> +            old_revno, old_revison_id = self.last_revision_info()
> +            params = ChangeBranchTipParams(old_revision_id, new_revision_id,
> +                old_revno, new_revno)
> +        else:
> +            return None
> +
> +    def _run_post_change_branch_tip_hooks(self, params):
> +        """Run the post_change_branch_tip hooks."""
> +        if params is None:
> +            return
> +        for hook in Branch.hooks['post_change_branch_tip']:
> +            hook(self, params)
> + 
>      @needs_write_lock
>      def set_last_revision_info(self, revno, revision_id):
>          """Set the last revision of this branch.
> @@ -1395,10 +1442,12 @@
>          configured to check constraints on history, in which case this may not
>          be permitted.
>          """
> +        hook_params = self._make_branch_tip_hook_params(revision_id, revno)
>          revision_id = _mod_revision.ensure_null(revision_id)
>          history = self._lefthand_history(revision_id)
>          assert len(history) == revno, '%d != %d' % (len(history), revno)
>          self.set_revision_history(history)
> +        self._run_post_change_branch_tip_hooks(hook_params)
>  
>      def _gen_revision_history(self):
>          history = self.control_files.get('revision-history').read().split('\n')
> @@ -1834,10 +1883,12 @@
>  
>      @needs_write_lock
>      def set_last_revision_info(self, revno, revision_id):
> +        hook_params = self._make_branch_tip_hook_params(revision_id, revno)
>          revision_id = _mod_revision.ensure_null(revision_id)
>          if self._get_append_revisions_only():
>              self._check_history_violation(revision_id)
>          self._write_last_revision_info(revno, revision_id)
> +        self._run_post_change_branch_tip_hooks(hook_params)
>          self._clear_cached_state()
>  
>      def _check_history_violation(self, revision_id):
> 
> === modified file 'bzrlib/help_topics/en/hooks.txt'
> --- bzrlib/help_topics/en/hooks.txt	2007-12-17 02:00:45 +0000
> +++ bzrlib/help_topics/en/hooks.txt	2008-04-01 08:08:26 +0000
> @@ -76,14 +76,32 @@
>  new_revid) where local is the local branch or None, master is the target
>  branch, and an empty branch receives new_revno of 0, new_revid of None.
>  
> +post_change_branch_tip
> +----------------------
> +
> +Run after a branch tip has been changed but while the branch is still
> +write-locked. Note that push, pull, commit and uncommit all invoke this hook.
> +
> +The hook signature is (params), where params is an object containing
> +the members
> +
> +  old_revno
> +    The revision number (eg 10) of the branch before the push.
> +
> +  old_revid
> +    The revision id (eg joe at foo.com-1234234-aoeua34) before the push.
> +
> +  new_revno
> +    The revision number (eg 12) of the branch after the push.
> +
> +  new_revid
> +    The revision id (eg joe at foo.com-5676566-boa234a) after the push.
> +
>  set_rh
>  ------
>  
> -Run after the branch's revision history has been modified (push, pull, commit
> -and uncommit can all modify the revision history).
> -
> -The hook signature is (branch, revision_history), and the branch will be
> -write-locked.
> +Note: This hook is now deprecated and will be removed in the near future.
> +Please use the ``post_change_branch_tip`` hook instead.
>  
>  See also `Using hooks`_ in the User Guide.
>  
> 
> # Begin bundle
> IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWUIokNMABJL/gHRUEABZ9///
> WiHeiv////BgCf3z7PnNre3rgAEGbm7qaWVsltnWHVa4SUjTVPUDE/VPU8miBvUR6jR6TQwgA0AA
> c0yMhkwQ0YTBGmjRiBpkyMAAQajFNMhPU9SaYQ9TCZpBo0GgGTTAmIAkRIEZJpip+mTImamUfqnl
> N6U2p6jTagybUyHlARSQE1HqekxqbIiaNkm1DQAAAaGQAkiAmgmCTETTTIxNCmn6SBoHqAAZLRFb
> EIa+XEZ7/fAfTVxTq2U6/B4YzBjlu3DxMP0xFZnjhvUuNcPBq4Mxc7LW0Ilmcm1/9sTcYyyg88Cj
> HtwsH99VeDKDR8dLmj776JBNheXlab2LilJeVZPRKqes+XVq6IBHehRGBRiA/vAdZeZOfjrxKCDW
> H8LpTbE2htbfID+6Y80Gl6eSHqqkNVdl1AtcQ5c8OVyosr6K9jpc7i+hUx6OrRobkjN1Hyp30Wvu
> JJ2LnoDDJVV0ii/Fu5Ecj5nota7+wmxRuNDBg75I1a2tjENZAmCMwBIzoKUPESUmzopi9t6iD+mM
> 4QhIZhk2WYscGamGrlVW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QdyH1IY
> CEDvecnp2dhx6Ch53nVnSiDv7iQEmDdxHWy4xXcQTyZA6ZBc2/ibmazJnPrpXQN5h3sXADDMTmoL
> 5eMz3r0depzcIrxdOTcl5yJIZhXzg2HnlEoy/NhOo0R4G2LNdDmHI+8Zkfly89rIgHUGNVG0wSqW
> CMk5ITM2kFE5sReJxFPZaXxeygSecsuI+reZWoKw1KiaEMSZjQakok/mg4WhY4CgyQe5oLwDGzES
> cbYMa5Ggv30CoWNbIh74LmjRlVb8BwD0UzRbEortlt2r693LEX7ii2+S575iiZEjXSWcLuEvsLXO
> isHDomnI2/ESQBaNwA3bfIRFSSwLl2r67zyltIYlmpxQoTbzptQLfYRrNT/8XckU4UJBCKJDTA==




More information about the bazaar mailing list