1
# Copyright (C) 2007-2011 Canonical Ltd
1
# Copyright (C) 2007 Canonical Ltd
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
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
17
from __future__ import absolute_import
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
17
from bzrlib.lazy_import import lazy_import
21
19
lazy_import(globals(), """
26
23
from StringIO import StringIO
28
25
from bzrlib import (
31
from bzrlib.util import bencode
33
from bzrlib.tuned_gzip import GzipFile
37
36
def topo_iter_keys(vf, keys=None):
284
279
class ParentText(object):
285
280
"""A reference to text present in a parent text"""
287
__slots__ = ['parent', 'parent_pos', 'child_pos', 'num_lines']
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
296
return dict(parent=self.parent, parent_pos=self.parent_pos,
297
child_pos=self.child_pos, num_lines=self.num_lines)
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__
303
292
def __eq__(self, other):
304
if self.__class__ is not other.__class__:
293
if self.__class__ != other.__class__:
306
return self._as_dict() == other._as_dict()
295
return (self.__dict__ == other.__dict__)
308
297
def to_patch(self):
309
yield ('c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
298
yield 'c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'\
313
302
class BaseVersionedFile(object):
327
316
return version in self._parents
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:
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]
562
551
sio = StringIO(infile.read(count))
565
zip_file = gzip.GzipFile(None, mode='rb', fileobj=sio)
554
zip_file = GzipFile(None, mode='rb', fileobj=sio)
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())
578
566
# before any write returns 0
579
567
start = outfile.tell()
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()))
676
664
def gzip_string(lines):
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()