Announcing bzr-tiplog

Brian de Alwis briandealwis at gmail.com
Tue Sep 27 14:29:37 UTC 2011


Hi Alexander.  I hope you don't mind, but I'm cc'ing the bzr list as this behaviour comes from some issues with hooks.

> I've started using your plugin and have found that for my existing branches the first commit after plugin has been installed marked as [init] rather than [commit]. Why? Is it intended?
> 
> The same problem with first pull to branch with a history.
> 
> It looks for me as a bug: maybe you want to mark the previous tip revision as [init] when tiplog file is created the first time and new revision you want to mark with real action, do you?

Short answer: it's a tradeoff to deal with some quirks in bzr's hooks when doing a 'bzr init X' vs 'bzr branch Y'.

My first attempt at tiplog simply hooked post_change_branch_tip and wrote out those changes.  But post_change_branch_tip doesn't provide any information about the action causing the change.  So I instead used the various branch hooks instead.  (Except on the server: the branch hooks aren't fired on the smart server, so tiplog can only rely on post_change_branch_tip, and records any change as a push.)  

The branch hooks work pretty well for the most part, except on branch inception: I don't have enough information to differentiate between a 'bzr init' vs 'bzr branch':

  * On 'bzr init', bzr only fires the post_branch_init hook; post_change_branch_tip is not fired.

  * On 'bzr branch X', bzr fires the post_branch_init hook immediately after the branch is created, but before the contents have been pulled in, and so the branch tip is revision 0.  post_change_branch_tip is fired after the contents have been brought in.  There are no other hooks fired.

As there's no way to hook 'command-processing-completed', I don't have enough information to separate these two cases.  So I decided instead to hook post_change_branch_tip and write out an 'init' IF the tiplog didn't exist. 

This handles the 'bzr branch' case, but as you've found, it doesn't quite work for the 'bzr init' case.  Doing a 'bzr commit' triggers two hooks, first a post_change_branch_tip and then a post_commit hook.  The post_change_branch_tip hook, seeing that there is no tiplog, causes the commit to be written out as an 'init'.  The post_commit hook is ignored since the tip hasn't actually changed from the previous log (from the post_change_branch_tip).

On reflection, what I'd like is to have a command-level hooks like 'command_finished'.  This would also help with recording a rebase, as rebase will be recorded as a slew of commits.

In the meantime, perhaps I'll hook the post_branch_init to record some state on the branch that it was init'd, and use that in the post_change_branch_tip instead of relying on the existence of the tiplog.  The first tip change on a 'bzr init' branch will be logged as a 'commit', which is ok, I think.

Brian.


More information about the bazaar mailing list