~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: NamNguyen
  • Date: 2007-08-01 06:14:14 UTC
  • mto: (2789.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2790.
  • Revision ID: namnguyen-20070801061414-u0tzrfgcz6z604lz
``Branch.hooks`` now supports ``pre_commit`` hook.

The hook's signature is

::

  hook(local, master, old_revno, old_revid, new_revno, new_revid,
       deleted_paths, added_paths, future_revision_tree)

``deleted_paths`` and ``added_paths`` are lists of paths. Renamed paths are
recorded in both ``deleted_paths`` and ``added_paths`` (i.e. deleted then
added).

``future_revision_tree`` is obtained from ``CommitBuilder.revision_tree``
to save hooks from getting it from the branch again.

For example, hooks can get a file:

::

  for path in added_paths:
      id = future_revision_tree.path2id(path)
      if future_revision_tree.kind(id) == 'file':
          file = future_revision_tree.get_file(id)
          ...

or export a tree and do ``make check`` or similar

::

  import bzrlib.export
  bzrlib.export.export(future_revision_tree, 'tmp_space')


If the commit is to be rejected, hooks should raise an ``Exception``.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1026
1026
        # is read locked and the target branches write locked. The local
1027
1027
        # branch is the low-latency branch.
1028
1028
        self['post_pull'] = []
 
1029
        # invoked before a commit operation takes place.
 
1030
        # the api signature is
 
1031
        # (local, master, old_revno, old_revid, future_revno, future_revid,
 
1032
        #  deleted_paths, added_paths, future_revision_tree).
 
1033
        # old_revid is NULL_REVISION for the first commit to a branch
 
1034
        # future_revision_tree is an in-memory tree obtained from
 
1035
        # CommitBuilder.revision_tree()
 
1036
        # renamed paths appear in both deleted_paths and added_paths.
 
1037
        self['pre_commit'] = []
1029
1038
        # invoked after a commit operation completes.
1030
1039
        # the api signature is 
1031
1040
        # (local, master, old_revno, old_revid, new_revno, new_revid)