1028
1028
:seealso: add_inventory, for the contract.
1030
inv_lines = self._serialise_inventory_to_lines(inv)
1030
inv_lines = self._serializer.write_inventory_to_lines(inv)
1031
1031
return self._inventory_add_lines(revision_id, parents,
1032
1032
inv_lines, check_content=False)
1484
1484
:param using: If True, list only branches using this repository.
1486
1486
if using and not self.is_shared():
1488
return [self.bzrdir.open_branch()]
1489
except errors.NotBranchError:
1487
return self.bzrdir.list_branches()
1491
1488
class Evaluator(object):
1493
1490
def __init__(self):
1502
1499
except errors.NoRepositoryPresent:
1505
return False, (None, repository)
1502
return False, ([], repository)
1506
1503
self.first_call = False
1508
value = (bzrdir.open_branch(), None)
1509
except errors.NotBranchError:
1510
value = (None, None)
1504
value = (bzrdir.list_branches(), None)
1511
1505
return True, value
1514
for branch, repository in bzrdir.BzrDir.find_bzrdirs(
1508
for branches, repository in bzrdir.BzrDir.find_bzrdirs(
1515
1509
self.bzrdir.root_transport, evaluate=Evaluator()):
1516
if branch is not None:
1517
branches.append(branch)
1510
if branches is not None:
1511
ret.extend(branches)
1518
1512
if not using and repository is not None:
1519
branches.extend(repository.find_branches())
1513
ret.extend(repository.find_branches())
1522
1516
@needs_read_lock
1523
1517
def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
1901
1895
rev = self._serializer.read_revision_from_string(text)
1902
1896
yield (revid, rev)
1905
def get_revision_xml(self, revision_id):
1906
# TODO: jam 20070210 This shouldn't be necessary since get_revision
1907
# would have already do it.
1908
# TODO: jam 20070210 Just use _serializer.write_revision_to_string()
1909
# TODO: this can't just be replaced by:
1910
# return self._serializer.write_revision_to_string(
1911
# self.get_revision(revision_id))
1912
# as cStringIO preservers the encoding unlike write_revision_to_string
1913
# or some other call down the path.
1914
rev = self.get_revision(revision_id)
1915
rev_tmp = cStringIO.StringIO()
1916
# the current serializer..
1917
self._serializer.write_revision(rev, rev_tmp)
1919
return rev_tmp.getvalue()
1921
1898
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1922
1899
"""Produce a generator of revision deltas.
2166
2143
selected_keys = set((revid,) for revid in revision_ids)
2167
2144
w = _inv_weave or self.inventories
2168
pb = ui.ui_factory.nested_progress_bar()
2170
return self._find_file_ids_from_xml_inventory_lines(
2171
w.iter_lines_added_or_present_in_keys(
2172
selected_keys, pb=pb),
2145
return self._find_file_ids_from_xml_inventory_lines(
2146
w.iter_lines_added_or_present_in_keys(
2147
selected_keys, pb=None),
2177
2150
def iter_files_bytes(self, desired_files):
2178
2151
"""Iterate through file versions.
2440
2413
result.revision_id, revision_id))
2443
def _serialise_inventory(self, inv):
2444
return self._serializer.write_inventory_to_string(inv)
2446
def _serialise_inventory_to_lines(self, inv):
2447
return self._serializer.write_inventory_to_lines(inv)
2449
2416
def get_serializer_format(self):
2450
2417
return self._serializer.format_num
2516
2483
next_id = parents[0]
2519
def get_revision_inventory(self, revision_id):
2520
"""Return inventory of a past revision."""
2521
# TODO: Unify this with get_inventory()
2522
# bzr 0.0.6 and later imposes the constraint that the inventory_id
2523
# must be the same as its revision, so this is trivial.
2524
if revision_id is None:
2525
# This does not make sense: if there is no revision,
2526
# then it is the current tree inventory surely ?!
2527
# and thus get_root_id() is something that looks at the last
2528
# commit on the branch, and the get_root_id is an inventory check.
2529
raise NotImplementedError
2530
# return Inventory(self.get_root_id())
2532
return self.get_inventory(revision_id)
2534
2485
def is_shared(self):
2535
2486
"""Return True if this repository is flagged as a shared repository."""
2536
2487
raise NotImplementedError(self.is_shared)
2570
2521
return RevisionTree(self, Inventory(root_id=None),
2571
2522
_mod_revision.NULL_REVISION)
2573
inv = self.get_revision_inventory(revision_id)
2524
inv = self.get_inventory(revision_id)
2574
2525
return RevisionTree(self, inv, revision_id)
2576
2527
def revision_trees(self, revision_ids):
3416
3369
:param revision_id: if None all content is copied, if NULL_REVISION no
3417
3370
content is copied.
3418
:param pb: optional progress bar to use for progress reports. If not
3419
provided a default one will be created.
3374
ui.ui_factory.warn_experimental_format_fetch(self)
3422
3375
f = _mod_fetch.RepoFetcher(to_repository=self.target,
3423
3376
from_repository=self.source,
3424
3377
last_revision=revision_id,
3425
3378
fetch_spec=fetch_spec,
3426
pb=pb, find_ghosts=find_ghosts)
3379
find_ghosts=find_ghosts)
3428
3381
def _walk_to_common_revisions(self, revision_ids):
3429
3382
"""Walk out from revision_ids in source to revisions target has.
4010
3963
ui.ui_factory.warn_cross_format_fetch(self.source._format,
4011
3964
self.target._format)
3965
ui.ui_factory.warn_experimental_format_fetch(self)
4012
3966
if (not self.source.supports_rich_root()
4013
3967
and self.target.supports_rich_root()):
4014
3968
self._converting_to_rich_root = True
4089
4043
:param to_convert: The disk object to convert.
4090
4044
:param pb: a progress bar to use for progress information.
4046
pb = ui.ui_factory.nested_progress_bar()
4095
4049
# this is only useful with metadir layouts - separated repo content.
4096
4050
# trigger an assertion if not such
4097
4051
repo._format.get_format_string()
4098
4052
self.repo_dir = repo.bzrdir
4099
self.step('Moving repository to repository.backup')
4053
pb.update('Moving repository to repository.backup')
4100
4054
self.repo_dir.transport.move('repository', 'repository.backup')
4101
4055
backup_transport = self.repo_dir.transport.clone('repository.backup')
4102
4056
repo._format.check_conversion_target(self.target_format)
4103
4057
self.source_repo = repo._format.open(self.repo_dir,
4105
4059
_override_transport=backup_transport)
4106
self.step('Creating new repository')
4060
pb.update('Creating new repository')
4107
4061
converted = self.target_format.initialize(self.repo_dir,
4108
4062
self.source_repo.is_shared())
4109
4063
converted.lock_write()
4111
self.step('Copying content')
4065
pb.update('Copying content')
4112
4066
self.source_repo.copy_content_into(converted)
4114
4068
converted.unlock()
4115
self.step('Deleting old repository content')
4069
pb.update('Deleting old repository content')
4116
4070
self.repo_dir.transport.delete_tree('repository.backup')
4117
4071
ui.ui_factory.note('repository converted')
4119
def step(self, message):
4120
"""Update the pb by a step."""
4122
self.pb.update(message, self.count, self.total)
4125
4075
_unescape_map = {