/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-24 10:45:08 UTC
  • mfrom: (2236 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2242.
  • Revision ID: bialix@ukr.net-20070124104508-mwiux3wozhk8939k
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
439
439
        # not present in one of those inventories is unnecessary but not 
440
440
        # harmful because we are filtering by the revision id marker in the
441
441
        # inventory lines : we only select file ids altered in one of those  
442
 
        unescape_revid_cache = {}
443
 
        unescape_fileid_cache = {}
444
 
 
445
442
        # revisions. We don't need to see all lines in the inventory because
446
443
        # only those added in an inventory in rev X can contain a revision=X
447
444
        # line.
 
445
        unescape_revid_cache = {}
 
446
        unescape_fileid_cache = {}
 
447
 
 
448
        # jam 20061218 In a big fetch, this handles hundreds of thousands
 
449
        # of lines, so it has had a lot of inlining and optimizing done.
 
450
        # Sorry that it is a little bit messy.
 
451
        # Move several functions to be local variables, since this is a long
 
452
        # running loop.
 
453
        search = self._file_ids_altered_regex.search
 
454
        unescape = _unescape_xml
 
455
        setdefault = result.setdefault
448
456
        pb = ui.ui_factory.nested_progress_bar()
449
457
        try:
450
458
            for line in w.iter_lines_added_or_present_in_versions(
451
 
                selected_revision_ids, pb=pb):
452
 
                match = self._file_ids_altered_regex.search(line)
 
459
                                        selected_revision_ids, pb=pb):
 
460
                match = search(line)
453
461
                if match is None:
454
462
                    continue
 
463
                # One call to match.group() returning multiple items is quite a
 
464
                # bit faster than 2 calls to match.group() each returning 1
455
465
                file_id, revision_id = match.group('file_id', 'revision_id')
456
 
                revision_id = _unescape_xml_cached(revision_id,
457
 
                                                   unescape_revid_cache)
 
466
 
 
467
                # Inlining the cache lookups helps a lot when you make 170,000
 
468
                # lines and 350k ids, versus 8.4 unique ids.
 
469
                # Using a cache helps in 2 ways:
 
470
                #   1) Avoids unnecessary decoding calls
 
471
                #   2) Re-uses cached strings, which helps in future set and
 
472
                #      equality checks.
 
473
                # (2) is enough that removing encoding entirely along with
 
474
                # the cache (so we are using plain strings) results in no
 
475
                # performance improvement.
 
476
                try:
 
477
                    revision_id = unescape_revid_cache[revision_id]
 
478
                except KeyError:
 
479
                    unescaped = unescape(revision_id)
 
480
                    unescape_revid_cache[revision_id] = unescaped
 
481
                    revision_id = unescaped
 
482
 
458
483
                if revision_id in selected_revision_ids:
459
 
                    file_id = _unescape_xml_cached(file_id,
460
 
                                                   unescape_fileid_cache)
461
 
                    result.setdefault(file_id, set()).add(revision_id)
 
484
                    try:
 
485
                        file_id = unescape_fileid_cache[file_id]
 
486
                    except KeyError:
 
487
                        unescaped = unescape(file_id)
 
488
                        unescape_fileid_cache[file_id] = unescaped
 
489
                        file_id = unescaped
 
490
                    setdefault(file_id, set()).add(revision_id)
462
491
        finally:
463
492
            pb.finished()
464
493
        return result
1249
1278
        klass._formats[format.get_format_string()] = format
1250
1279
 
1251
1280
    @classmethod
 
1281
    @deprecated_method(symbol_versioning.zero_fourteen)
1252
1282
    def set_default_format(klass, format):
 
1283
        klass._set_default_format(format)
 
1284
 
 
1285
    @classmethod
 
1286
    def _set_default_format(klass, format):
1253
1287
        klass._default_format = format
1254
1288
 
1255
1289
    @classmethod
1771
1805
# formats which have no format string are not discoverable
1772
1806
# and not independently creatable, so are not registered.
1773
1807
RepositoryFormat.register_format(RepositoryFormat7())
 
1808
# KEEP in sync with bzrdir.format_registry default
1774
1809
_default_format = RepositoryFormatKnit1()
1775
1810
RepositoryFormat.register_format(_default_format)
1776
1811
RepositoryFormat.register_format(RepositoryFormatKnit2())
1777
 
RepositoryFormat.set_default_format(_default_format)
 
1812
RepositoryFormat._set_default_format(_default_format)
1778
1813
_legacy_formats = [RepositoryFormat4(),
1779
1814
                   RepositoryFormat5(),
1780
1815
                   RepositoryFormat6()]
2573
2608
    if _unescape_re is None:
2574
2609
        _unescape_re = re.compile('\&([^;]*);')
2575
2610
    return _unescape_re.sub(_unescaper, data)
2576
 
 
2577
 
 
2578
 
def _unescape_xml_cached(data, cache):
2579
 
    try:
2580
 
        return cache[data]
2581
 
    except KeyError:
2582
 
        unescaped = _unescape_xml(data)
2583
 
        cache[data] = unescaped
2584
 
        return unescaped