1
# Copyright (C) 2005-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
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
22
revision as _mod_revision,
25
from bzrlib.tests.scenarios import load_tests_apply_scenarios
26
from bzrlib.tests.per_repository_vf import (
27
TestCaseWithRepository,
28
all_repository_vf_format_scenarios,
32
load_tests = load_tests_apply_scenarios
35
class FileIdInvolvedWGhosts(TestCaseWithRepository):
37
scenarios = all_repository_vf_format_scenarios()
39
def create_branch_with_ghost_text(self):
40
builder = self.make_branch_builder('ghost')
41
builder.build_snapshot('A-id', None, [
42
('add', ('', 'root-id', 'directory', None)),
43
('add', ('a', 'a-file-id', 'file', 'some content\n'))])
44
b = builder.get_branch()
45
old_rt = b.repository.revision_tree('A-id')
46
new_inv = inventory.mutable_inventory_from_tree(old_rt)
47
new_inv.revision_id = 'B-id'
48
new_inv['a-file-id'].revision = 'ghost-id'
49
new_rev = _mod_revision.Revision('B-id',
50
timestamp=time.time(),
52
message='Committing against a ghost',
53
committer='Joe Foo <joe@foo.com>',
55
parent_ids=('A-id', 'ghost-id'),
58
self.addCleanup(b.unlock)
59
b.repository.start_write_group()
60
b.repository.add_revision('B-id', new_rev, new_inv)
61
self.disable_commit_write_group_paranoia(b.repository)
62
b.repository.commit_write_group()
65
def disable_commit_write_group_paranoia(self, repo):
66
if isinstance(repo, remote.RemoteRepository):
67
# We can't easily disable the checks in a remote repo.
68
repo.abort_write_group()
69
raise tests.TestSkipped(
70
"repository format does not support storing revisions with "
72
pack_coll = getattr(repo, '_pack_collection', None)
73
if pack_coll is not None:
74
# Monkey-patch the pack collection instance to allow storing
75
# incomplete revisions.
76
pack_coll._check_new_inventories = lambda: []
78
def test_file_ids_include_ghosts(self):
79
b = self.create_branch_with_ghost_text()
82
{'a-file-id':set(['ghost-id'])},
83
repo.fileids_altered_by_revision_ids(['B-id']))
85
def test_file_ids_uses_fallbacks(self):
86
builder = self.make_branch_builder('source',
87
format=self.bzrdir_format)
88
repo = builder.get_branch().repository
89
if not repo._format.supports_external_lookups:
90
raise tests.TestNotApplicable('format does not support stacking')
91
builder.start_series()
92
builder.build_snapshot('A-id', None, [
93
('add', ('', 'root-id', 'directory', None)),
94
('add', ('file', 'file-id', 'file', 'contents\n'))])
95
builder.build_snapshot('B-id', ['A-id'], [
96
('modify', ('file-id', 'new-content\n'))])
97
builder.build_snapshot('C-id', ['B-id'], [
98
('modify', ('file-id', 'yet more content\n'))])
99
builder.finish_series()
100
source_b = builder.get_branch()
102
self.addCleanup(source_b.unlock)
103
base = self.make_branch('base')
104
base.pull(source_b, stop_revision='B-id')
105
stacked = self.make_branch('stacked')
106
stacked.set_stacked_on_url('../base')
107
stacked.pull(source_b, stop_revision='C-id')
110
self.addCleanup(stacked.unlock)
111
repo = stacked.repository
112
keys = {'file-id': set(['A-id'])}
113
if stacked.repository.supports_rich_root():
114
keys['root-id'] = set(['A-id'])
115
self.assertEqual(keys, repo.fileids_altered_by_revision_ids(['A-id']))