/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/multiparent.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
from bzrlib.lazy_import import lazy_import
18
20
 
19
21
lazy_import(globals(), """
20
22
import errno
 
23
import gzip
21
24
import itertools
22
25
import os
23
26
from StringIO import StringIO
24
27
 
25
28
from bzrlib import (
 
29
    bencode,
26
30
    errors,
27
31
    patiencediff,
28
 
    trace,
29
32
    ui,
30
33
    )
31
 
from bzrlib import bencode
32
34
""")
33
 
from bzrlib.tuned_gzip import GzipFile
34
35
 
35
36
 
36
37
def topo_iter_keys(vf, keys=None):
76
77
class MultiParent(object):
77
78
    """A multi-parent diff"""
78
79
 
 
80
    __slots__ = ['hunks']
 
81
 
79
82
    def __init__(self, hunks=None):
80
83
        if hunks is not None:
81
84
            self.hunks = hunks
258
261
class NewText(object):
259
262
    """The contents of text that is introduced by this text"""
260
263
 
 
264
    __slots__ = ['lines']
 
265
 
261
266
    def __init__(self, lines):
262
267
        self.lines = lines
263
268
 
279
284
class ParentText(object):
280
285
    """A reference to text present in a parent text"""
281
286
 
 
287
    __slots__ = ['parent', 'parent_pos', 'child_pos', 'num_lines']
 
288
 
282
289
    def __init__(self, parent, parent_pos, child_pos, num_lines):
283
290
        self.parent = parent
284
291
        self.parent_pos = parent_pos
285
292
        self.child_pos = child_pos
286
293
        self.num_lines = num_lines
287
294
 
 
295
    def _as_dict(self):
 
296
        return dict(parent=self.parent, parent_pos=self.parent_pos,
 
297
                    child_pos=self.child_pos, num_lines=self.num_lines)
 
298
 
288
299
    def __repr__(self):
289
 
        return 'ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'\
290
 
            ' %(num_lines)r)' % self.__dict__
 
300
        return ('ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'
 
301
                ' %(num_lines)r)' % self._as_dict())
291
302
 
292
303
    def __eq__(self, other):
293
304
        if self.__class__ is not other.__class__:
294
305
            return False
295
 
        return (self.__dict__ == other.__dict__)
 
306
        return self._as_dict() == other._as_dict()
296
307
 
297
308
    def to_patch(self):
298
 
        yield 'c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'\
299
 
            % self.__dict__
 
309
        yield ('c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
 
310
               % self._as_dict())
300
311
 
301
312
 
302
313
class BaseVersionedFile(object):
412
423
                            if not (lines == self.get_line_list([revision])[0]):
413
424
                                raise AssertionError()
414
425
                            self.clear_cache()
415
 
                    pb.update('Importing revisions',
 
426
                    pb.update(gettext('Importing revisions'),
416
427
                              (total - len(revisions)) + len(added), total)
417
428
                revisions = [r for r in revisions if r not in added]
418
429
        finally:
551
562
            sio = StringIO(infile.read(count))
552
563
        finally:
553
564
            infile.close()
554
 
        zip_file = GzipFile(None, mode='rb', fileobj=sio)
 
565
        zip_file = gzip.GzipFile(None, mode='rb', fileobj=sio)
555
566
        try:
556
567
            file_version_id = zip_file.readline()
557
 
            return MultiParent.from_patch(zip_file.read())
 
568
            content = zip_file.read()
 
569
            return MultiParent.from_patch(content)
558
570
        finally:
559
571
            zip_file.close()
560
572
 
566
578
                                    # before any write returns 0
567
579
            start = outfile.tell()
568
580
            try:
569
 
                zipfile = GzipFile(None, mode='ab', fileobj=outfile)
 
581
                zipfile = gzip.GzipFile(None, mode='ab', fileobj=outfile)
570
582
                zipfile.writelines(itertools.chain(
571
583
                    ['version %s\n' % version_id], diff.to_patch()))
572
584
            finally:
663
675
 
664
676
def gzip_string(lines):
665
677
    sio = StringIO()
666
 
    data_file = GzipFile(None, mode='wb', fileobj=sio)
 
678
    data_file = gzip.GzipFile(None, mode='wb', fileobj=sio)
667
679
    data_file.writelines(lines)
668
680
    data_file.close()
669
681
    return sio.getvalue()