~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-10-17 11:41:07 UTC
  • mfrom: (1442.1.60)
  • Revision ID: robertc@robertcollins.net-20051017114107-f5586285d825c105
Merge in first part of GPG support.

This adds check_signatures config support, triams back the transport api
to be leaner and easier to hook in suffixes - non primary streams in the store
associated with the fileid that primary data is stored in, a gpg module which
will encapsulate all signing and checking operations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
from bzrlib.store.compressed_text import CompressedTextStore
44
44
from bzrlib.store.text import TextStore
45
45
from bzrlib.store.weave import WeaveStore
 
46
from bzrlib.testament import Testament
46
47
import bzrlib.transactions as transactions
47
48
from bzrlib.transport import Transport, get_transport
48
49
import bzrlib.xml5
242
243
            self.weave_store = get_weave('weaves', prefixed=True)
243
244
            self.revision_store = get_store('revision-store', compressed=False,
244
245
                                            prefixed=True)
 
246
        self.revision_store.register_suffix('sig')
245
247
        self._transaction = None
246
248
 
247
249
    def __str__(self):
721
723
        This does not necessarily imply the revision is merge
722
724
        or on the mainline."""
723
725
        return (revision_id is None
724
 
                or revision_id in self.revision_store)
 
726
                or self.revision_store.has_id(revision_id))
725
727
 
726
728
    def get_revision_xml_file(self, revision_id):
727
729
        """Return XML file object for revision object."""
731
733
        self.lock_read()
732
734
        try:
733
735
            try:
734
 
                return self.revision_store[revision_id]
 
736
                return self.revision_store.get(revision_id)
735
737
            except (IndexError, KeyError):
736
738
                raise bzrlib.errors.NoSuchRevision(self, revision_id)
737
739
        finally:
983
985
                         from_branch=other,
984
986
                         revision=pullable_revs[-1])
985
987
            self.append_revision(*pullable_revs)
986
 
    
987
988
 
988
989
    def commit(self, *args, **kw):
989
990
        from bzrlib.commit import Commit
1022
1023
            inv = self.get_revision_inventory(revision_id)
1023
1024
            return RevisionTree(self.weave_store, inv, revision_id)
1024
1025
 
1025
 
 
1026
1026
    def working_tree(self):
1027
1027
        """Return a `Tree` for the working copy."""
1028
1028
        from bzrlib.workingtree import WorkingTree
1289
1289
        if revno < 1 or revno > self.revno():
1290
1290
            raise InvalidRevisionNumber(revno)
1291
1291
        
1292
 
        
1293
 
        
 
1292
    def sign_revision(self, revision_id, gpg_strategy):
 
1293
        self.lock_write()
 
1294
        try:
 
1295
            plaintext = Testament.from_revision(self, revision_id).as_short_text()
 
1296
            self.revision_store.add(StringIO(gpg_strategy.sign(plaintext)), 
 
1297
                                    revision_id, "sig")
 
1298
        finally:
 
1299
            self.unlock()
1294
1300
 
1295
1301
 
1296
1302
class ScratchBranch(_Branch):
1300
1306
    >>> isdir(b.base)
1301
1307
    True
1302
1308
    >>> bd = b.base
1303
 
    >>> b.destroy()
 
1309
    >>> b._transport.__del__()
1304
1310
    >>> isdir(bd)
1305
1311
    False
1306
1312
    """
1307
 
    def __init__(self, files=[], dirs=[], base=None):
 
1313
 
 
1314
    def __init__(self, files=[], dirs=[], transport=None):
1308
1315
        """Make a test branch.
1309
1316
 
1310
1317
        This creates a temporary directory and runs init-tree in it.
1311
1318
 
1312
1319
        If any files are listed, they are created in the working copy.
1313
1320
        """
1314
 
        from tempfile import mkdtemp
1315
 
        init = False
1316
 
        if base is None:
1317
 
            base = mkdtemp()
1318
 
            init = True
1319
 
        if isinstance(base, basestring):
1320
 
            base = get_transport(base)
1321
 
        _Branch.__init__(self, base, init=init)
 
1321
        if transport is None:
 
1322
            transport = bzrlib.transport.local.ScratchTransport()
 
1323
            super(ScratchBranch, self).__init__(transport, init=True)
 
1324
        else:
 
1325
            super(ScratchBranch, self).__init__(transport)
 
1326
 
1322
1327
        for d in dirs:
1323
1328
            self._transport.mkdir(d)
1324
1329
            
1344
1349
        base = mkdtemp()
1345
1350
        os.rmdir(base)
1346
1351
        copytree(self.base, base, symlinks=True)
1347
 
        return ScratchBranch(base=base)
1348
 
 
1349
 
    def __del__(self):
1350
 
        self.destroy()
1351
 
 
1352
 
    def destroy(self):
1353
 
        """Destroy the test branch, removing the scratch directory."""
1354
 
        from shutil import rmtree
1355
 
        try:
1356
 
            if self.base:
1357
 
                mutter("delete ScratchBranch %s" % self.base)
1358
 
                rmtree(self.base)
1359
 
        except OSError, e:
1360
 
            # Work around for shutil.rmtree failing on Windows when
1361
 
            # readonly files are encountered
1362
 
            mutter("hit exception in destroying ScratchBranch: %s" % e)
1363
 
            for root, dirs, files in os.walk(self.base, topdown=False):
1364
 
                for name in files:
1365
 
                    os.chmod(os.path.join(root, name), 0700)
1366
 
            rmtree(self.base)
1367
 
        self._transport = None
1368
 
 
 
1352
        return ScratchBranch(
 
1353
            transport=bzrlib.transport.local.ScratchTransport(base))
1369
1354
    
1370
1355
 
1371
1356
######################################################################