0

I would like the latest remote revision number to be committed to a file of the remote tree on each push. The following thread answers the question of doing it locally on commit, is there a way to do it remotely on push?

In other words, is there a "start_push"-like analogy/workaround to start_commit?

I'd like to do this in order to allow diverging local trees with their own versioning while keeping separate versioning for the 'central' tree. So, different developers should be able to branch from the central server, then diverge in their local trees by any local commits and push/merge back. All the trees should be versioned automatically and uniquely by a combination of a tree sequence and its revision which is written to a file which is part of the tree. For example, (a developer's xyz local) commit with revision number 127 of tree 'xyz' commits 'xyz.127' into a VERSION file of the tree. However, pushing this revision to the 'central' tree should commit for instance 'central.98' to the central tree (if the last revision in the 'central' tree was 97).

It have it working fine for the local commits but I do not know how to achieve the desired behaviour on the remote push. Note that it is not a problem that the local fork of the revision will be different from the remote one; it is actually desired.

Alternatively, a different setup achieving the same aim (diverging local trees with their own versioning and separate versioning for the 'central' tree) would be very much welcome too!

Community
  • 1
  • 1
jvm
  • 349
  • 1
  • 3
  • 7
  • It seems that nobody can provide a solution. Is bazaar so limited or is my question so stupid/unusual/badly formulated? – jvm Feb 15 '12 at 18:37

1 Answers1

2

You would need to install a plugin on the server that registers for the post-change-branch-tip hook.

Untested example:

from bzrlib.urlutils import local_path_from_url
from bzrlib.osutils import pathjoin

def post_change_branch_tip_hook(params):
    root = local_path_from_url(params.branch.base)
    path = pathjoin(self.root, 'revno.txt')
    f = open(path, 'w')
    try:
        f.write('%s\n' % params.new_revno)
    finally:
        f.close()
AmanicA
  • 4,659
  • 1
  • 34
  • 49
  • The problem is that as far as I know, post-change-branch-tip cannot modify the tree. If there is a way to workaround this, could you please be more specific about how to do it? – jvm Feb 06 '12 at 13:24
  • I don't see a reason why you can't modify a file from here. If you want the file to be committed/version-controlled you will need to take a different approach. I added a untested example to the answer. – AmanicA Feb 06 '12 at 17:27
  • Thanks for the example and sorry for being imprecise: I need the file to be committed indeed. (I used the imprecise formulation 'stored in the tree' before, I have replaced by 'committed to the tree' now.) – jvm Feb 07 '12 at 00:24
  • Actually, to be more precise again, the version number should be changed by pushing rather than (separate subsequent) committing - the version number should only change once on the push. The same process as done locally on commit in the referred thread to be done on the server on push to it. In fact I think all needed would be start_push or another analogy to start_commit... – jvm Feb 07 '12 at 00:48
  • Pushing revisions is not supposed to change commit content because then your local fork of the revision will be different unless you pull the changes back (This is what dpush does, see bzr help dpush). I would think that doing the change on the actual commit is the best place. Is there a strong reason for this happening on push? – AmanicA Feb 08 '12 at 00:46
  • I added the reason and the desired setup to the question - I should have done that when asking already as it is possible that I could change the setup to achieve the same effect in a better way. – jvm Feb 08 '12 at 11:40