Sunday, October 10, 2010

Using BZR

BZR supports a number of different workflows. The most common one is "Centralized", which allows you to use BZR just like CVS or SVN. You just type "bzr commit" (save changes) and "bzr update" (get changes).

However, BZR has the advantage of being a distributed system and thus gives you the option of branching, working remotely (and still having version control), and then merging your changes back to the main trunk.

You can do this in a few easy steps:
  1. Make a copy of your code, by making a new "branch" of the code. Example:
    (On LOCAL)
    bzr branch WAMbot WAMbotAdriansBranch
    
    In future, you can keep this branch up to date by using "bzr pull" from the branch.
  2. Copy the branch to your target (eg: a robot / embedded PC or usb-stick). If you copy from the USB stick to the target you will need an extra step to go back.
  3. Work with the source code on the target. After you have made changes just type "bzr commit" (on the target). This will commit to your local branch.

    Now you have the advantage of being able to revert any changes that you make while working away, without needing a connection to the main server.
  4. If you copied from the USB stick, and you want to save the changes back to it, type (at the target): "bzr push LOCATION" (Where LOCATION is the USB disk drive). Example:
    (On TARGET)
    bzr push "e:/WAMbotAdriansBranch"
    
    from the bzr directory on the robot.
  5. Now merge with your local repository, from your own bzr directory type:
    bzr merge LOCATION (Where LOCATION is the USB disk drive, or shared folder) Example:
    (On LOCAL)
    bzr merge X:\WAMbotBranch
    
  6. Now you can commit them to the central server! (Just use bzr commit like always)
This saves you from having to keep track of your source code and merge things manually. Some more helpful BZR tips:
  • bzr update (get the latest code from the server)
  • bzr commit (save your code to the server)
  • bzr add (add some files to repo)
  • bzr whoami (get/set who you are)
  • bzr revno (get current revision number)
  • bzr diff -r REVISION (eg: 1000) filename (tells you the differences in a file since a specified revision)

    There are a number of revision flags:
    • bzr diff -r last:5 (compare with 5 revision ago)
    • bzr diff -r date:yesterday (compare with yesterdays revision)
    • bzr diff -r date:YYYY-MM-DD (compare with a dated revision)
  • bzr commit --local (commit to your own local repository, so you can easily undo changes. Note: you may need to bind/unbind, so branching as described above is probably better)
  • bzr revert (undo your changes)
  • bzr log (show commit comments)
  • bzr log -r REVISION.. (show all comments since given revision. Example: "bzr log -r1000..")
BZR also has a number of plugins, including one to run a command before a commit.

No comments: