Bazaar (Bzr)

Version ControlDistributedPythonCanonicalUbuntuLegacyDVCS

Distributed Version Control System

Bazaar (Bzr)

Overview

Bazaar is a distributed version control system developed by Canonical Ltd., the company behind Ubuntu Linux. Written in Python and first released in 2005, Bazaar was designed to be easy to use while providing powerful distributed version control capabilities. Although development has been minimal since 2012 and the project is considered legacy, Bazaar still has historical significance and is used in some Ubuntu-related projects and legacy systems.

Details

Bazaar follows a distributed model similar to Git and Mercurial, where each working directory contains a complete repository with full history. The system emphasizes simplicity and ease of use, with commands designed to be intuitive for users familiar with centralized systems like Subversion.

Key architectural features include support for multiple workflows (centralized, decentralized, and mixed), lightweight checkouts for centralized-style development, and smart servers for efficient network operations. Bazaar repositories can be hosted via HTTP, SFTP, FTP, or the native bzr+ssh protocol.

The system provides unique features like directory renames tracking, per-file merge algorithms, and the ability to commit to any branch from any working directory. Bazaar's plugin architecture allows for extensive customization and additional functionality.

While Bazaar is no longer actively developed, understanding its concepts can be valuable for maintaining legacy systems or transitioning projects to more modern version control systems. Many of Bazaar's design principles influenced other distributed version control systems.

Advantages and Disadvantages

Advantages

  • User-Friendly Design: Intuitive commands and workflows
  • Multiple Workflow Support: Flexible branching and collaboration models
  • Cross-Platform: Runs on Windows, macOS, and Linux
  • Smart Merging: Advanced merge algorithms and conflict resolution
  • Plugin Architecture: Extensible through Python plugins
  • Directory Tracking: Proper handling of directory renames and moves
  • Rich Metadata: Comprehensive commit and branch information
  • Network Efficiency: Smart protocols for distributed operations

Disadvantages

  • Discontinued Development: No active development since 2012
  • Limited Ecosystem: Minimal tool support and hosting options
  • Performance Issues: Slower than Git for large repositories
  • Small Community: Limited support and documentation updates
  • Python Dependency: Requires Python runtime environment
  • Migration Complexity: Difficult to migrate to other systems
  • Security Concerns: No recent security updates or patches

Reference Pages

Code Examples

Repository Initialization and Basic Operations

# Initialize a new Bazaar repository
bzr init myproject
cd myproject

# Initialize shared repository (for multiple branches)
bzr init-repo myproject-repo
cd myproject-repo
bzr init trunk

# Check repository status
bzr status
bzr st  # Short form

# Add files to version control
bzr add filename.txt
bzr add .  # Add all files recursively

# Commit changes
bzr commit -m "Initial commit"
bzr ci -m "Short form commit"

# View commit history
bzr log
bzr log --short  # Abbreviated format

Branching and Merging

# Create a new branch
bzr branch trunk feature-branch
cd feature-branch

# Alternative: create branch in shared repository
cd myproject-repo
bzr branch trunk feature-branch

# List branches
bzr branches

# Switch to different branch (bound branches)
bzr switch ../trunk

# Merge changes from another branch
bzr merge ../trunk
bzr commit -m "Merge from trunk"

# Show pending merges
bzr status --pending

# Uncommit last revision (undo commit)
bzr uncommit

Working with Remote Repositories

# Clone a remote repository
bzr branch http://bazaar.launchpad.net/~project/project/trunk
bzr branch lp:project  # Launchpad shortcut

# Push changes to remote
bzr push http://example.com/myproject

# Pull changes from remote
bzr pull
bzr pull --overwrite  # Force pull with conflicts

# Create lightweight checkout (centralized workflow)
bzr checkout http://example.com/myproject working-copy
cd working-copy
# Changes are automatically committed to remote

# Create heavyweight checkout (local commits allowed)
bzr checkout --heavyweight http://example.com/myproject local-copy

File Operations and History

# View file differences
bzr diff filename.txt
bzr diff -r 10..15  # Between revisions

# Show file at specific revision
bzr cat -r 10 filename.txt

# View file history
bzr log filename.txt
bzr annotations filename.txt  # Line-by-line authorship

# Remove files
bzr remove filename.txt
bzr rm filename.txt  # Short form

# Rename/move files
bzr move oldname.txt newname.txt
bzr mv olddir newdir

# Revert changes
bzr revert filename.txt
bzr revert  # Revert all changes

Advanced Operations

# Interactive commit (select changes)
bzr commit --interactive

# Shelve changes temporarily
bzr shelve
bzr shelve --list
bzr unshelve

# Tag creation
bzr tag release-1.0
bzr tags  # List tags

# View repository information
bzr info
bzr version-info  # Detailed version information

# Export clean copy (no .bzr directory)
bzr export ../export-directory

# Create patch
bzr diff > changes.patch

# Apply patch
patch -p0 < changes.patch

Conflict Resolution

# When conflicts occur during merge
bzr status  # Shows conflicted files

# View conflict details
bzr conflicts

# Resolve conflicts manually, then mark as resolved
bzr resolve filename.txt

# Use external merge tool
bzr resolve --using vimdiff filename.txt

# Show resolved files
bzr status --resolved

# Complete merge after resolving conflicts
bzr commit -m "Resolve merge conflicts"

Plugin Management

# List installed plugins
bzr plugins

# Install plugin from Bazaar Plugin Registry
bzr branch lp:bzr-plugin-name ~/.bazaar/plugins/plugin-name

# Common useful plugins:
# bzr-git: Git interaction
# bzr-svn: Subversion interaction
# bzr-email: Email notifications
# bzr-rewrite: History rewriting tools

# Configure plugin (example: bzr-email)
bzr config email.from="[email protected]"
bzr config email.smtp_server="smtp.example.com"

Repository Maintenance

# Check repository integrity
bzr check

# Optimize repository storage
bzr pack

# Garbage collection
bzr gc

# Repository statistics
bzr info --verbose

# Backup repository
bzr backup ../backup-location

# Convert repository format (upgrade)
bzr upgrade --format=2a

Working with Launchpad

# Set up Launchpad authentication
bzr launchpad-login your-username

# Create branch on Launchpad
bzr push lp:~username/project/branch-name

# Link local branch to Launchpad
bzr push lp:~username/project/branch-name
bzr bind lp:~username/project/branch-name

# Submit merge proposal
# (Done through Launchpad web interface)

# Get project from Launchpad
bzr branch lp:project-name

Configuration and Customization

# Set user identity
bzr whoami "Your Name <[email protected]>"

# View configuration
bzr config

# Set configuration options
bzr config editor=vim
bzr config log_format=line

# Global configuration file location:
# ~/.bazaar/bazaar.conf (Unix/Linux/macOS)
# %APPDATA%\bazaar\2.0\bazaar.conf (Windows)

# Example configuration file:
[DEFAULT]
email = Your Name <[email protected]>
editor = vim
log_format = short

[ALIASES]
st = status
ci = commit
di = diff

Migration and Integration

# Import from Subversion
bzr import-svn http://svn.example.com/repo/trunk myproject

# Export to Git (using bzr-git plugin)
# First install bzr-git plugin
bzr dpush git+ssh://git.example.com/repo.git

# Import from CVS
bzr import-cvs /path/to/cvs/repo myproject

# Convert to other formats
bzr fast-export --plain > ../git-import.stream
# Then import into Git repository

Hooks and Automation

# Example pre-commit hook
# Save as ~/.bazaar/plugins/pre_commit_check.py

from bzrlib import branch

def pre_commit_hook(local_branch, master_branch, old_revno, old_revid,
                   new_revno, new_revid):
    """Check code quality before commit"""
    import subprocess
    
    # Run tests
    result = subprocess.run(['python', '-m', 'pytest'], 
                          capture_output=True, text=True)
    
    if result.returncode != 0:
        print("Tests failed. Commit aborted.")
        return True  # Abort commit
    
    return False  # Allow commit

# Register hook
branch.Branch.hooks.install_named_hook('pre_commit', pre_commit_hook, 
                                      'Quality check')

Workflow Examples

# Centralized workflow (like Subversion)
bzr checkout http://server/project working-directory
cd working-directory
# Edit files
bzr commit -m "Changes are automatically pushed"

# Feature branch workflow
bzr branch trunk feature-xyz
cd feature-xyz
# Develop feature
bzr commit -m "Implement feature XYZ"
cd ../trunk
bzr merge ../feature-xyz
bzr commit -m "Merge feature XYZ"

# Distributed workflow
bzr branch http://main-repo/trunk local-trunk
cd local-trunk
# Make changes
bzr commit -m "Local changes"
bzr push http://my-repo/trunk  # Push to personal repository
# Submit merge request to main repository

Legacy System Maintenance

# Working with existing Bazaar repositories
bzr branch http://legacy-server/project
cd project

# Update to latest format if needed
bzr upgrade

# Create migration export
bzr fast-export --plain > migration.stream

# For Git migration
git fast-import < migration.stream

# Preserve Bazaar metadata during migration
bzr export --format=tar ../project-archive.tar