~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/multiparent.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

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