915
1016
wt.branch, log.GnuChangelogLogFormatter,
916
1017
show_log_kwargs=dict(verbose=True))
918
class TestGetViewRevisions(tests.TestCaseWithTransport, TestLogMixin):
920
def _get_view_revisions(self, *args, **kwargs):
921
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
922
log.get_view_revisions, *args, **kwargs)
924
def make_tree_with_commits(self):
925
"""Create a tree with well-known revision ids"""
926
wt = self.make_branch_and_tree('tree1')
927
self.wt_commit(wt, 'commit one', rev_id='1')
928
self.wt_commit(wt, 'commit two', rev_id='2')
929
self.wt_commit(wt, 'commit three', rev_id='3')
930
mainline_revs = [None, '1', '2', '3']
931
rev_nos = {'1': 1, '2': 2, '3': 3}
932
return mainline_revs, rev_nos, wt
934
def make_tree_with_merges(self):
935
"""Create a tree with well-known revision ids and a merge"""
936
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
937
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
938
self.wt_commit(tree2, 'four-a', rev_id='4a')
939
wt.merge_from_branch(tree2.branch)
940
self.wt_commit(wt, 'four-b', rev_id='4b')
941
mainline_revs.append('4b')
944
return mainline_revs, rev_nos, wt
946
def make_branch_with_many_merges(self):
947
"""Create a tree with well-known revision ids"""
948
builder = self.make_branch_builder('tree1')
949
builder.start_series()
950
builder.build_snapshot('1', None, [
951
('add', ('', 'TREE_ROOT', 'directory', '')),
952
('add', ('f', 'f-id', 'file', '1\n'))])
953
builder.build_snapshot('2', ['1'], [])
954
builder.build_snapshot('3a', ['2'], [
955
('modify', ('f-id', '1\n2\n3a\n'))])
956
builder.build_snapshot('3b', ['2', '3a'], [
957
('modify', ('f-id', '1\n2\n3a\n'))])
958
builder.build_snapshot('3c', ['2', '3b'], [
959
('modify', ('f-id', '1\n2\n3a\n'))])
960
builder.build_snapshot('4a', ['3b'], [])
961
builder.build_snapshot('4b', ['3c', '4a'], [])
962
builder.finish_series()
976
mainline_revs = [None, '1', '2', '3c', '4b']
977
rev_nos = {'1':1, '2':2, '3c': 3, '4b':4}
978
full_rev_nos_for_reference = {
981
'3a': '2.1.1', #first commit tree 3
982
'3b': '2.2.1', # first commit tree 2
983
'3c': '3', #merges 3b to main
984
'4a': '2.2.2', # second commit tree 2
985
'4b': '4', # merges 4a to main
987
return mainline_revs, rev_nos, builder.get_branch()
989
def test_get_view_revisions_forward(self):
990
"""Test the get_view_revisions method"""
991
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
993
self.addCleanup(wt.unlock)
994
revisions = list(self._get_view_revisions(
995
mainline_revs, rev_nos, wt.branch, 'forward'))
996
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
998
revisions2 = list(self._get_view_revisions(
999
mainline_revs, rev_nos, wt.branch, 'forward',
1000
include_merges=False))
1001
self.assertEqual(revisions, revisions2)
1003
def test_get_view_revisions_reverse(self):
1004
"""Test the get_view_revisions with reverse"""
1005
mainline_revs, rev_nos, wt = self.make_tree_with_commits()
1007
self.addCleanup(wt.unlock)
1008
revisions = list(self._get_view_revisions(
1009
mainline_revs, rev_nos, wt.branch, 'reverse'))
1010
self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
1012
revisions2 = list(self._get_view_revisions(
1013
mainline_revs, rev_nos, wt.branch, 'reverse',
1014
include_merges=False))
1015
self.assertEqual(revisions, revisions2)
1017
def test_get_view_revisions_merge(self):
1018
"""Test get_view_revisions when there are merges"""
1019
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1021
self.addCleanup(wt.unlock)
1022
revisions = list(self._get_view_revisions(
1023
mainline_revs, rev_nos, wt.branch, 'forward'))
1024
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1025
('4b', '4', 0), ('4a', '3.1.1', 1)],
1027
revisions = list(self._get_view_revisions(
1028
mainline_revs, rev_nos, wt.branch, 'forward',
1029
include_merges=False))
1030
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
1034
def test_get_view_revisions_merge_reverse(self):
1035
"""Test get_view_revisions in reverse when there are merges"""
1036
mainline_revs, rev_nos, wt = self.make_tree_with_merges()
1038
self.addCleanup(wt.unlock)
1039
revisions = list(self._get_view_revisions(
1040
mainline_revs, rev_nos, wt.branch, 'reverse'))
1041
self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
1042
('3', '3', 0), ('2', '2', 0), ('1', '1', 0)],
1044
revisions = list(self._get_view_revisions(
1045
mainline_revs, rev_nos, wt.branch, 'reverse',
1046
include_merges=False))
1047
self.assertEqual([('4b', '4', 0), ('3', '3', 0), ('2', '2', 0),
1051
def test_get_view_revisions_merge2(self):
1052
"""Test get_view_revisions when there are merges"""
1053
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1055
self.addCleanup(b.unlock)
1056
revisions = list(self._get_view_revisions(
1057
mainline_revs, rev_nos, b, 'forward'))
1058
expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1059
('3b', '2.2.1', 1), ('3a', '2.1.1', 2), ('4b', '4', 0),
1061
self.assertEqual(expected, revisions)
1062
revisions = list(self._get_view_revisions(
1063
mainline_revs, rev_nos, b, 'forward',
1064
include_merges=False))
1065
self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
1069
def test_file_id_for_range(self):
1070
mainline_revs, rev_nos, b = self.make_branch_with_many_merges()
1072
self.addCleanup(b.unlock)
1074
def rev_from_rev_id(revid, branch):
1075
revspec = revisionspec.RevisionSpec.from_string('revid:%s' % revid)
1076
return revspec.in_history(branch)
1078
def view_revs(start_rev, end_rev, file_id, direction):
1079
revs = self.applyDeprecated(
1080
symbol_versioning.deprecated_in((2, 2, 0)),
1081
log.calculate_view_revisions,
1083
start_rev, # start_revision
1084
end_rev, # end_revision
1085
direction, # direction
1086
file_id, # specific_fileid
1087
True, # generate_merge_revisions
1091
rev_3a = rev_from_rev_id('3a', b)
1092
rev_4b = rev_from_rev_id('4b', b)
1093
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1094
('3a', '2.1.1', 2)],
1095
view_revs(rev_3a, rev_4b, 'f-id', 'reverse'))
1096
# Note: 3c still appears before 3a here because of depth-based sorting
1097
self.assertEqual([('3c', '3', 0), ('3b', '2.2.1', 1),
1098
('3a', '2.1.1', 2)],
1099
view_revs(rev_3a, rev_4b, 'f-id', 'forward'))
1102
class TestGetRevisionsTouchingFileID(tests.TestCaseWithTransport):
1104
def get_view_revisions(self, *args):
1105
return self.applyDeprecated(symbol_versioning.deprecated_in((2, 2, 0)),
1106
log.get_view_revisions, *args)
1108
def create_tree_with_single_merge(self):
1109
"""Create a branch with a moderate layout.
1111
The revision graph looks like:
1119
In this graph, A introduced files f1 and f2 and f3.
1120
B modifies f1 and f3, and C modifies f2 and f3.
1121
D merges the changes from B and C and resolves the conflict for f3.
1123
# TODO: jam 20070218 This seems like it could really be done
1124
# with make_branch_and_memory_tree() if we could just
1125
# create the content of those files.
1126
# TODO: jam 20070218 Another alternative is that we would really
1127
# like to only create this tree 1 time for all tests that
1128
# use it. Since 'log' only uses the tree in a readonly
1129
# fashion, it seems a shame to regenerate an identical
1130
# tree for each test.
1131
# TODO: vila 20100122 One way to address the shame above will be to
1132
# create a memory tree during test parametrization and give a
1133
# *copy* of this tree to each test. Copying a memory tree ought
1134
# to be cheap, at least cheaper than creating them with such
1136
tree = self.make_branch_and_tree('tree')
1138
self.addCleanup(tree.unlock)
1140
self.build_tree_contents([('tree/f1', 'A\n'),
1144
tree.add(['f1', 'f2', 'f3'], ['f1-id', 'f2-id', 'f3-id'])
1145
tree.commit('A', rev_id='A')
1147
self.build_tree_contents([('tree/f2', 'A\nC\n'),
1148
('tree/f3', 'A\nC\n'),
1150
tree.commit('C', rev_id='C')
1151
# Revert back to A to build the other history.
1152
tree.set_last_revision('A')
1153
tree.branch.set_last_revision_info(1, 'A')
1154
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1156
('tree/f3', 'A\nB\n'),
1158
tree.commit('B', rev_id='B')
1159
tree.set_parent_ids(['B', 'C'])
1160
self.build_tree_contents([('tree/f1', 'A\nB\n'),
1161
('tree/f2', 'A\nC\n'),
1162
('tree/f3', 'A\nB\nC\n'),
1164
tree.commit('D', rev_id='D')
1166
# Switch to a read lock for this tree.
1167
# We still have an addCleanup(tree.unlock) pending
1172
def check_delta(self, delta, **kw):
1173
"""Check the filenames touched by a delta are as expected.
1175
Caller only have to pass in the list of files for each part, all
1176
unspecified parts are considered empty (and checked as such).
1178
for n in 'added', 'removed', 'renamed', 'modified', 'unchanged':
1179
# By default we expect an empty list
1180
expected = kw.get(n, [])
1181
# strip out only the path components
1182
got = [x[0] for x in getattr(delta, n)]
1183
self.assertEqual(expected, got)
1185
def test_tree_with_single_merge(self):
1186
"""Make sure the tree layout is correct."""
1187
tree = self.create_tree_with_single_merge()
1188
rev_A_tree = tree.branch.repository.revision_tree('A')
1189
rev_B_tree = tree.branch.repository.revision_tree('B')
1190
rev_C_tree = tree.branch.repository.revision_tree('C')
1191
rev_D_tree = tree.branch.repository.revision_tree('D')
1193
self.check_delta(rev_B_tree.changes_from(rev_A_tree),
1194
modified=['f1', 'f3'])
1196
self.check_delta(rev_C_tree.changes_from(rev_A_tree),
1197
modified=['f2', 'f3'])
1199
self.check_delta(rev_D_tree.changes_from(rev_B_tree),
1200
modified=['f2', 'f3'])
1202
self.check_delta(rev_D_tree.changes_from(rev_C_tree),
1203
modified=['f1', 'f3'])
1205
def assertAllRevisionsForFileID(self, tree, file_id, revisions):
1206
"""Ensure _filter_revisions_touching_file_id returns the right values.
1208
Get the return value from _filter_revisions_touching_file_id and make
1209
sure they are correct.
1211
# The api for _filter_revisions_touching_file_id is a little crazy.
1212
# So we do the setup here.
1213
mainline = tree.branch.revision_history()
1214
mainline.insert(0, None)
1215
revnos = dict((rev, idx+1) for idx, rev in enumerate(mainline))
1216
view_revs_iter = self.get_view_revisions(
1217
mainline, revnos, tree.branch, 'reverse', True)
1218
actual_revs = log._filter_revisions_touching_file_id(
1219
tree.branch, file_id, list(view_revs_iter))
1220
self.assertEqual(revisions, [r for r, revno, depth in actual_revs])
1222
def test_file_id_f1(self):
1223
tree = self.create_tree_with_single_merge()
1224
# f1 should be marked as modified by revisions A and B
1225
self.assertAllRevisionsForFileID(tree, 'f1-id', ['B', 'A'])
1227
def test_file_id_f2(self):
1228
tree = self.create_tree_with_single_merge()
1229
# f2 should be marked as modified by revisions A, C, and D
1230
# because D merged the changes from C.
1231
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1233
def test_file_id_f3(self):
1234
tree = self.create_tree_with_single_merge()
1235
# f3 should be marked as modified by revisions A, B, C, and D
1236
self.assertAllRevisionsForFileID(tree, 'f3-id', ['D', 'C', 'B', 'A'])
1238
def test_file_id_with_ghosts(self):
1239
# This is testing bug #209948, where having a ghost would cause
1240
# _filter_revisions_touching_file_id() to fail.
1241
tree = self.create_tree_with_single_merge()
1242
# We need to add a revision, so switch back to a write-locked tree
1243
# (still a single addCleanup(tree.unlock) pending).
1246
first_parent = tree.last_revision()
1247
tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1248
self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1249
tree.commit('commit with a ghost', rev_id='XX')
1250
self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1251
self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1253
def test_unknown_file_id(self):
1254
tree = self.create_tree_with_single_merge()
1255
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1257
def test_empty_branch_unknown_file_id(self):
1258
tree = self.make_branch_and_tree('tree')
1259
self.assertAllRevisionsForFileID(tree, 'unknown', [])
1262
1020
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1463
1221
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1224
class TestRevisionNotInBranch(TestCaseForLogFormatter):
1226
def setup_a_tree(self):
1227
tree = self.make_branch_and_tree('tree')
1229
self.addCleanup(tree.unlock)
1231
'committer': 'Joe Foo <joe@foo.com>',
1232
'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1233
'timezone': 0, # UTC
1235
tree.commit('commit 1a', rev_id='1a', **kwargs)
1236
tree.commit('commit 2a', rev_id='2a', **kwargs)
1237
tree.commit('commit 3a', rev_id='3a', **kwargs)
1240
def setup_ab_tree(self):
1241
tree = self.setup_a_tree()
1242
tree.set_last_revision('1a')
1243
tree.branch.set_last_revision_info(1, '1a')
1245
'committer': 'Joe Foo <joe@foo.com>',
1246
'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1247
'timezone': 0, # UTC
1249
tree.commit('commit 2b', rev_id='2b', **kwargs)
1250
tree.commit('commit 3b', rev_id='3b', **kwargs)
1253
def test_one_revision(self):
1254
tree = self.setup_ab_tree()
1256
rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1257
log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1259
self.assertEqual(1, len(lf.revisions))
1260
self.assertEqual(None, lf.revisions[0].revno) # Out-of-branch
1261
self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1263
def test_many_revisions(self):
1264
tree = self.setup_ab_tree()
1266
start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1267
end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1268
log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1269
end_revision=end_rev)
1270
self.assertEqual(3, len(lf.revisions))
1271
self.assertEqual(None, lf.revisions[0].revno) # Out-of-branch
1272
self.assertEqual('3a', lf.revisions[0].rev.revision_id)
1273
self.assertEqual(None, lf.revisions[1].revno) # Out-of-branch
1274
self.assertEqual('2a', lf.revisions[1].rev.revision_id)
1275
self.assertEqual('1', lf.revisions[2].revno) # In-branch
1277
def test_long_format(self):
1278
tree = self.setup_ab_tree()
1279
start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1280
end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1281
self.assertFormatterResult("""\
1282
------------------------------------------------------------
1284
committer: Joe Foo <joe@foo.com>
1286
timestamp: Tue 2005-11-22 00:00:00 +0000
1289
------------------------------------------------------------
1291
committer: Joe Foo <joe@foo.com>
1293
timestamp: Tue 2005-11-22 00:00:00 +0000
1296
------------------------------------------------------------
1298
committer: Joe Foo <joe@foo.com>
1300
timestamp: Tue 2005-11-22 00:00:00 +0000
1304
tree.branch, log.LongLogFormatter, show_log_kwargs={
1305
'start_revision': start_rev, 'end_revision': end_rev
1308
def test_short_format(self):
1309
tree = self.setup_ab_tree()
1310
start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1311
end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1312
self.assertFormatterResult("""\
1321
1 Joe Foo\t2005-11-22
1325
tree.branch, log.ShortLogFormatter, show_log_kwargs={
1326
'start_revision': start_rev, 'end_revision': end_rev
1329
def test_line_format(self):
1330
tree = self.setup_ab_tree()
1331
start_rev = revisionspec.RevisionInfo(tree.branch, None, '1a')
1332
end_rev = revisionspec.RevisionInfo(tree.branch, None, '3a')
1333
self.assertFormatterResult("""\
1334
Joe Foo 2005-11-22 commit 3a
1335
Joe Foo 2005-11-22 commit 2a
1336
1: Joe Foo 2005-11-22 commit 1a
1338
tree.branch, log.LineLogFormatter, show_log_kwargs={
1339
'start_revision': start_rev, 'end_revision': end_rev
1467
1343
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1469
1345
def setUp(self):
1470
TestCaseForLogFormatter.setUp(self)
1346
super(TestLogWithBugs, self).setUp()
1471
1347
log.properties_handler_registry.register(
1472
1348
'bugs_properties_handler',
1473
1349
log._bugs_properties_handler)