~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-02-12 09:40:15 UTC
  • mto: (1534.1.22 integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060212094015-0fba37745716a3d9
Implement -r limit for checkout command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1277
1277
    This format modified the hash cache from the format 1 hash cache.
1278
1278
    """
1279
1279
 
1280
 
    def initialize(self, a_bzrdir):
 
1280
    def initialize(self, a_bzrdir, revision_id=None):
1281
1281
        """See WorkingTreeFormat.initialize()."""
1282
1282
        if not isinstance(a_bzrdir.transport, LocalTransport):
1283
1283
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1284
1284
        branch = a_bzrdir.open_branch()
 
1285
        if revision_id is not None:
 
1286
            branch.lock_write()
 
1287
            try:
 
1288
                revision_history = branch.revision_history()
 
1289
                try:
 
1290
                    position = revision_history.index(revision_id)
 
1291
                except ValueError:
 
1292
                    raise errors.NoSuchRevision(branch, revision_id)
 
1293
                branch.set_revision_history(revision_history[:position + 1])
 
1294
            finally:
 
1295
                branch.unlock()
1285
1296
        revision = branch.last_revision()
1286
1297
        basis_tree = branch.repository.revision_tree(revision)
1287
1298
        inv = basis_tree.inventory
1329
1340
        """See WorkingTreeFormat.get_format_string()."""
1330
1341
        return "Bazaar-NG Working Tree format 3"
1331
1342
 
1332
 
    def initialize(self, a_bzrdir):
1333
 
        """See WorkingTreeFormat.initialize()."""
 
1343
    def initialize(self, a_bzrdir, revision_id=None):
 
1344
        """See WorkingTreeFormat.initialize().
 
1345
        
 
1346
        revision_id allows creating a working tree at a differnet
 
1347
        revision than the branch is at.
 
1348
        """
1334
1349
        if not isinstance(a_bzrdir.transport, LocalTransport):
1335
1350
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1336
1351
        transport = a_bzrdir.get_workingtree_transport(self)
1337
1352
        control_files = LockableFiles(transport, 'lock')
1338
1353
        control_files.put_utf8('format', self.get_format_string())
1339
1354
        branch = a_bzrdir.open_branch()
1340
 
        revision = branch.last_revision()
1341
 
        basis_tree = branch.repository.revision_tree(revision)
1342
 
        inv = basis_tree.inventory
 
1355
        if revision_id is None:
 
1356
            revision_id = branch.last_revision()
 
1357
        new_basis_tree = branch.repository.revision_tree(revision_id)
 
1358
        inv = new_basis_tree.inventory
1343
1359
        wt = WorkingTree3(a_bzrdir.root_transport.base,
1344
1360
                         branch,
1345
1361
                         inv,
1348
1364
                         _bzrdir=a_bzrdir)
1349
1365
        wt._write_inventory(inv)
1350
1366
        wt.set_root_id(inv.root.file_id)
1351
 
        wt.set_last_revision(revision)
 
1367
        wt.set_last_revision(revision_id)
1352
1368
        wt.set_pending_merges([])
1353
1369
        wt.revert([])
1354
1370
        return wt