~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Brad Crittenden
  • Date: 2007-02-26 20:56:10 UTC
  • mfrom: (2300 +trunk)
  • mto: (2293.1.5 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 2311.
  • Revision ID: brad.crittenden@canonical.com-20070226205610-44oatbxrjjz3ajwy
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
378
378
        """Given a revision id, return its revno"""
379
379
        if revision_id is None:
380
380
            return 0
 
381
        revision_id = osutils.safe_revision_id(revision_id)
381
382
        history = self.revision_history()
382
383
        try:
383
384
            return history.index(revision_id) + 1
580
581
        """
581
582
        new_history = self.revision_history()
582
583
        if revision_id is not None:
 
584
            revision_id = osutils.safe_revision_id(revision_id)
583
585
            try:
584
586
                new_history = new_history[:new_history.index(revision_id) + 1]
585
587
            except ValueError:
1245
1247
    @needs_write_lock
1246
1248
    def append_revision(self, *revision_ids):
1247
1249
        """See Branch.append_revision."""
 
1250
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1248
1251
        for revision_id in revision_ids:
1249
1252
            _mod_revision.check_not_reserved_id(revision_id)
1250
1253
            mutter("add {%s} to revision-history" % revision_id)
1257
1260
 
1258
1261
        This performs the actual writing to disk.
1259
1262
        It is intended to be called by BzrBranch5.set_revision_history."""
1260
 
        self.control_files.put_utf8(
 
1263
        self.control_files.put_bytes(
1261
1264
            'revision-history', '\n'.join(history))
1262
1265
 
1263
1266
    @needs_write_lock
1264
1267
    def set_revision_history(self, rev_history):
1265
1268
        """See Branch.set_revision_history."""
 
1269
        rev_history = [osutils.safe_revision_id(r) for r in rev_history]
1266
1270
        self._write_revision_history(rev_history)
1267
1271
        transaction = self.get_transaction()
1268
1272
        history = transaction.map.find_revision_history()
1282
1286
 
1283
1287
    @needs_write_lock
1284
1288
    def set_last_revision_info(self, revno, revision_id):
 
1289
        revision_id = osutils.safe_revision_id(revision_id)
1285
1290
        history = self._lefthand_history(revision_id)
1286
1291
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1287
1292
        self.set_revision_history(history)
1288
1293
 
1289
1294
    def _gen_revision_history(self):
1290
 
        decode_utf8 = cache_utf8.decode
1291
 
        history = [decode_utf8(l.rstrip('\r\n')) for l in
 
1295
        get_cached_utf8 = cache_utf8.get_cached_utf8
 
1296
        history = [get_cached_utf8(l.rstrip('\r\n')) for l in
1292
1297
                self.control_files.get('revision-history').readlines()]
1293
1298
        return history
1294
1299
 
1338
1343
        :param other_branch: The other branch that DivergedBranches should
1339
1344
            raise with respect to.
1340
1345
        """
 
1346
        revision_id = osutils.safe_revision_id(revision_id)
1341
1347
        self.set_revision_history(self._lefthand_history(revision_id,
1342
1348
            last_rev, other_branch))
1343
1349
 
1351
1357
                if stop_revision is None:
1352
1358
                    # if there are no commits, we're done.
1353
1359
                    return
 
1360
            else:
 
1361
                stop_revision = osutils.safe_revision_id(stop_revision)
1354
1362
            # whats the current last revision, before we fetch [and change it
1355
1363
            # possibly]
1356
1364
            last_rev = self.last_revision()
1500
1508
                    raise bzrlib.errors.InvalidURL(url,
1501
1509
                        "Urls must be 7-bit ascii, "
1502
1510
                        "use bzrlib.urlutils.escape")
1503
 
                    
1504
1511
            url = urlutils.relative_url(self.base, url)
1505
1512
        self._set_parent_location(url)
1506
1513
 
1509
1516
            self.control_files._transport.delete('parent')
1510
1517
        else:
1511
1518
            assert isinstance(url, str)
1512
 
            self.control_files.put('parent', StringIO(url + '\n'))
 
1519
            self.control_files.put_bytes('parent', url + '\n')
1513
1520
 
1514
1521
    @deprecated_function(zero_nine)
1515
1522
    def tree_config(self):
1692
1699
 
1693
1700
    @needs_read_lock
1694
1701
    def last_revision_info(self):
1695
 
        revision_string = self.control_files.get_utf8('last-revision').read()
 
1702
        revision_string = self.control_files.get('last-revision').read()
1696
1703
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
 
1704
        revision_id = cache_utf8.get_cached_utf8(revision_id)
1697
1705
        revno = int(revno)
1698
1706
        return revno, revision_id
1699
1707
 
1716
1724
        if revision_id is None:
1717
1725
            revision_id = 'null:'
1718
1726
        out_string = '%d %s\n' % (revno, revision_id)
1719
 
        self.control_files.put_utf8('last-revision', out_string)
 
1727
        self.control_files.put_bytes('last-revision', out_string)
1720
1728
 
1721
1729
    @needs_write_lock
1722
1730
    def set_last_revision_info(self, revno, revision_id):
 
1731
        revision_id = osutils.safe_revision_id(revision_id)
1723
1732
        if self._get_append_revisions_only():
1724
1733
            self._check_history_violation(revision_id)
1725
1734
        self._write_last_revision_info(revno, revision_id)
1761
1770
 
1762
1771
    @needs_write_lock
1763
1772
    def append_revision(self, *revision_ids):
 
1773
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1764
1774
        if len(revision_ids) == 0:
1765
1775
            return
1766
1776
        prev_revno, prev_revision = self.last_revision_info()