~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-08 23:10:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070208231037-xzuzlh339rmgfhk6
Add a get_cached_utf8, which will ensure it is really utf8, and cache the strings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /usr/bin/python
2
2
 
3
3
# Copyright (C) 2005 Canonical Ltd
4
 
 
 
4
#
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
7
7
# the Free Software Foundation; either version 2 of the License, or
8
8
# (at your option) any later version.
9
 
 
 
9
#
10
10
# This program is distributed in the hope that it will be useful,
11
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
13
# GNU General Public License for more details.
14
 
 
 
14
#
15
15
# You should have received a copy of the GNU General Public License
16
16
# along with this program; if not, write to the Free Software
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
73
73
import os
74
74
import sha
75
75
import time
 
76
import warnings
76
77
 
 
78
from bzrlib import (
 
79
    progress,
 
80
    )
77
81
from bzrlib.trace import mutter
78
82
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
79
83
        RevisionAlreadyPresent,
84
88
import bzrlib.errors as errors
85
89
from bzrlib.osutils import sha_strings
86
90
import bzrlib.patiencediff
87
 
from bzrlib.symbol_versioning import *
 
91
from bzrlib.symbol_versioning import (deprecated_method,
 
92
        deprecated_function,
 
93
        zero_eight,
 
94
        )
88
95
from bzrlib.tsort import topo_sort
89
96
from bzrlib.versionedfile import VersionedFile, InterVersionedFile
90
97
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
240
247
 
241
248
    def _lookup(self, name):
242
249
        """Convert symbolic version name to index."""
 
250
        self.check_not_reserved_id(name)
243
251
        try:
244
252
            return self._name_map[name]
245
253
        except KeyError:
261
269
 
262
270
    def has_version(self, version_id):
263
271
        """See VersionedFile.has_version."""
264
 
        return self._name_map.has_key(version_id)
 
272
        return (version_id in self._name_map)
265
273
 
266
274
    __contains__ = has_version
267
275
 
635
643
 
636
644
    def annotate(self, version_id):
637
645
        if isinstance(version_id, int):
638
 
            warn('Weave.annotate(int) is deprecated. Please use version names'
 
646
            warnings.warn('Weave.annotate(int) is deprecated. Please use version names'
639
647
                 ' in all circumstances as of 0.8',
640
648
                 DeprecationWarning,
641
649
                 stacklevel=2
660
668
        """_walk has become visit, a supported api."""
661
669
        return self._walk_internal()
662
670
 
663
 
    def iter_lines_added_or_present_in_versions(self, version_ids=None):
 
671
    def iter_lines_added_or_present_in_versions(self, version_ids=None,
 
672
                                                pb=None):
664
673
        """See VersionedFile.iter_lines_added_or_present_in_versions()."""
665
674
        if version_ids is None:
666
675
            version_ids = self.versions()
1112
1121
 
1113
1122
    def _add_lines(self, version_id, parents, lines, parent_texts):
1114
1123
        """Add a version and save the weave."""
 
1124
        self.check_not_reserved_id(version_id)
1115
1125
        result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
1116
1126
                                                   parent_texts)
1117
1127
        self._save()
1128
1138
        sio = StringIO()
1129
1139
        write_weave_v5(self, sio)
1130
1140
        sio.seek(0)
1131
 
        transport.put(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
 
1141
        transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
1132
1142
 
1133
1143
    def create_empty(self, name, transport, filemode=None):
1134
1144
        return WeaveFile(name, transport, filemode, create=True)
1139
1149
        sio = StringIO()
1140
1150
        write_weave_v5(self, sio)
1141
1151
        sio.seek(0)
1142
 
        self._transport.put(self._weave_name + WeaveFile.WEAVE_SUFFIX,
1143
 
                            sio,
1144
 
                            self._filemode)
 
1152
        self._transport.put_file(self._weave_name + WeaveFile.WEAVE_SUFFIX,
 
1153
                                 sio,
 
1154
                                 self._filemode)
1145
1155
 
1146
1156
    @staticmethod
1147
1157
    def get_suffixes():
1239
1249
    from bzrlib.weavefile import read_weave
1240
1250
 
1241
1251
    wf = file(weave_file, 'rb')
1242
 
    w = read_weave(wf, WeaveVersionedFile)
 
1252
    w = read_weave(wf)
1243
1253
    # FIXME: doesn't work on pipes
1244
1254
    weave_size = wf.tell()
1245
1255
 
1419
1429
        raise ValueError('unknown command %r' % cmd)
1420
1430
    
1421
1431
 
1422
 
 
1423
 
def profile_main(argv):
1424
 
    import tempfile, hotshot, hotshot.stats
1425
 
 
1426
 
    prof_f = tempfile.NamedTemporaryFile()
1427
 
 
1428
 
    prof = hotshot.Profile(prof_f.name)
1429
 
 
1430
 
    ret = prof.runcall(main, argv)
1431
 
    prof.close()
1432
 
 
1433
 
    stats = hotshot.stats.load(prof_f.name)
1434
 
    #stats.strip_dirs()
1435
 
    stats.sort_stats('cumulative')
1436
 
    ## XXX: Might like to write to stderr or the trace file instead but
1437
 
    ## print_stats seems hardcoded to stdout
1438
 
    stats.print_stats(20)
1439
 
            
1440
 
    return ret
1441
 
 
1442
 
 
1443
 
def lsprofile_main(argv): 
1444
 
    from bzrlib.lsprof import profile
1445
 
    ret,stats = profile(main, argv)
1446
 
    stats.sort()
1447
 
    stats.pprint()
1448
 
    return ret
1449
 
 
1450
 
 
1451
1432
if __name__ == '__main__':
1452
1433
    import sys
1453
 
    if '--profile' in sys.argv:
1454
 
        args = sys.argv[:]
1455
 
        args.remove('--profile')
1456
 
        sys.exit(profile_main(args))
1457
 
    elif '--lsprof' in sys.argv:
1458
 
        args = sys.argv[:]
1459
 
        args.remove('--lsprof')
1460
 
        sys.exit(lsprofile_main(args))
1461
 
    else:
1462
 
        sys.exit(main(sys.argv))
 
1434
    sys.exit(main(sys.argv))
1463
1435
 
1464
1436
 
1465
1437
class InterWeave(InterVersionedFile):