915
1042
wt.branch, log.GnuChangelogLogFormatter,
916
1043
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
1046
class TestShowChangedRevisions(tests.TestCaseWithTransport):
1372
1156
tree = self.make_branch_and_tree('tree')
1373
1157
tree.lock_write()
1374
1158
self.addCleanup(tree.unlock)
1375
tree.commit('1a', rev_id='1a')
1376
tree.commit('2a', rev_id='2a')
1377
tree.commit('3a', rev_id='3a')
1159
tree.commit('1a', rev_id=b'1a')
1160
tree.commit('2a', rev_id=b'2a')
1161
tree.commit('3a', rev_id=b'3a')
1380
1164
def setup_ab_tree(self):
1381
1165
tree = self.setup_a_tree()
1382
tree.set_last_revision('1a')
1383
tree.branch.set_last_revision_info(1, '1a')
1384
tree.commit('2b', rev_id='2b')
1385
tree.commit('3b', rev_id='3b')
1166
tree.set_last_revision(b'1a')
1167
tree.branch.set_last_revision_info(1, b'1a')
1168
tree.commit('2b', rev_id=b'2b')
1169
tree.commit('3b', rev_id=b'3b')
1388
1172
def setup_ac_tree(self):
1389
1173
tree = self.setup_a_tree()
1390
1174
tree.set_last_revision(revision.NULL_REVISION)
1391
1175
tree.branch.set_last_revision_info(0, revision.NULL_REVISION)
1392
tree.commit('1c', rev_id='1c')
1393
tree.commit('2c', rev_id='2c')
1394
tree.commit('3c', rev_id='3c')
1176
tree.commit('1c', rev_id=b'1c')
1177
tree.commit('2c', rev_id=b'2c')
1178
tree.commit('3c', rev_id=b'3c')
1397
1181
def test_all_new(self):
1398
1182
tree = self.setup_ab_tree()
1399
old, new = log.get_history_change('1a', '3a', tree.branch.repository)
1183
old, new = log.get_history_change(b'1a', b'3a', tree.branch.repository)
1400
1184
self.assertEqual([], old)
1401
self.assertEqual(['2a', '3a'], new)
1185
self.assertEqual([b'2a', b'3a'], new)
1403
1187
def test_all_old(self):
1404
1188
tree = self.setup_ab_tree()
1405
old, new = log.get_history_change('3a', '1a', tree.branch.repository)
1189
old, new = log.get_history_change(b'3a', b'1a', tree.branch.repository)
1406
1190
self.assertEqual([], new)
1407
self.assertEqual(['2a', '3a'], old)
1191
self.assertEqual([b'2a', b'3a'], old)
1409
1193
def test_null_old(self):
1410
1194
tree = self.setup_ab_tree()
1411
1195
old, new = log.get_history_change(revision.NULL_REVISION,
1412
'3a', tree.branch.repository)
1196
b'3a', tree.branch.repository)
1413
1197
self.assertEqual([], old)
1414
self.assertEqual(['1a', '2a', '3a'], new)
1198
self.assertEqual([b'1a', b'2a', b'3a'], new)
1416
1200
def test_null_new(self):
1417
1201
tree = self.setup_ab_tree()
1418
old, new = log.get_history_change('3a', revision.NULL_REVISION,
1202
old, new = log.get_history_change(b'3a', revision.NULL_REVISION,
1419
1203
tree.branch.repository)
1420
1204
self.assertEqual([], new)
1421
self.assertEqual(['1a', '2a', '3a'], old)
1205
self.assertEqual([b'1a', b'2a', b'3a'], old)
1423
1207
def test_diverged(self):
1424
1208
tree = self.setup_ab_tree()
1425
old, new = log.get_history_change('3a', '3b', tree.branch.repository)
1426
self.assertEqual(old, ['2a', '3a'])
1427
self.assertEqual(new, ['2b', '3b'])
1209
old, new = log.get_history_change(b'3a', b'3b', tree.branch.repository)
1210
self.assertEqual(old, [b'2a', b'3a'])
1211
self.assertEqual(new, [b'2b', b'3b'])
1429
1213
def test_unrelated(self):
1430
1214
tree = self.setup_ac_tree()
1431
old, new = log.get_history_change('3a', '3c', tree.branch.repository)
1432
self.assertEqual(old, ['1a', '2a', '3a'])
1433
self.assertEqual(new, ['1c', '2c', '3c'])
1215
old, new = log.get_history_change(b'3a', b'3c', tree.branch.repository)
1216
self.assertEqual(old, [b'1a', b'2a', b'3a'])
1217
self.assertEqual(new, [b'1c', b'2c', b'3c'])
1435
1219
def test_show_branch_change(self):
1436
1220
tree = self.setup_ab_tree()
1438
log.show_branch_change(tree.branch, s, 3, '3a')
1222
log.show_branch_change(tree.branch, s, 3, b'3a')
1439
1223
self.assertContainsRe(s.getvalue(),
1440
1224
'[*]{60}\nRemoved Revisions:\n(.|\n)*2a(.|\n)*3a(.|\n)*'
1441
1225
'[*]{60}\n\nAdded Revisions:\n(.|\n)*2b(.|\n)*3b')
1443
1227
def test_show_branch_change_no_change(self):
1444
1228
tree = self.setup_ab_tree()
1446
log.show_branch_change(tree.branch, s, 3, '3b')
1230
log.show_branch_change(tree.branch, s, 3, b'3b')
1447
1231
self.assertEqual(s.getvalue(),
1448
1232
'Nothing seems to have changed\n')
1450
1234
def test_show_branch_change_no_old(self):
1451
1235
tree = self.setup_ab_tree()
1453
log.show_branch_change(tree.branch, s, 2, '2b')
1237
log.show_branch_change(tree.branch, s, 2, b'2b')
1454
1238
self.assertContainsRe(s.getvalue(), 'Added Revisions:')
1455
1239
self.assertNotContainsRe(s.getvalue(), 'Removed Revisions:')
1457
1241
def test_show_branch_change_no_new(self):
1458
1242
tree = self.setup_ab_tree()
1459
tree.branch.set_last_revision_info(2, '2b')
1243
tree.branch.set_last_revision_info(2, b'2b')
1461
log.show_branch_change(tree.branch, s, 3, '3b')
1245
log.show_branch_change(tree.branch, s, 3, b'3b')
1462
1246
self.assertContainsRe(s.getvalue(), 'Removed Revisions:')
1463
1247
self.assertNotContainsRe(s.getvalue(), 'Added Revisions:')
1250
class TestRevisionNotInBranch(TestCaseForLogFormatter):
1252
def setup_a_tree(self):
1253
tree = self.make_branch_and_tree('tree')
1255
self.addCleanup(tree.unlock)
1257
'committer': 'Joe Foo <joe@foo.com>',
1258
'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1259
'timezone': 0, # UTC
1261
tree.commit('commit 1a', rev_id=b'1a', **kwargs)
1262
tree.commit('commit 2a', rev_id=b'2a', **kwargs)
1263
tree.commit('commit 3a', rev_id=b'3a', **kwargs)
1266
def setup_ab_tree(self):
1267
tree = self.setup_a_tree()
1268
tree.set_last_revision(b'1a')
1269
tree.branch.set_last_revision_info(1, b'1a')
1271
'committer': 'Joe Foo <joe@foo.com>',
1272
'timestamp': 1132617600, # Mon 2005-11-22 00:00:00 +0000
1273
'timezone': 0, # UTC
1275
tree.commit('commit 2b', rev_id=b'2b', **kwargs)
1276
tree.commit('commit 3b', rev_id=b'3b', **kwargs)
1279
def test_one_revision(self):
1280
tree = self.setup_ab_tree()
1282
rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
1283
log.show_log(tree.branch, lf, verbose=True, start_revision=rev,
1285
self.assertEqual(1, len(lf.revisions))
1286
self.assertEqual(None, lf.revisions[0].revno) # Out-of-branch
1287
self.assertEqual(b'3a', lf.revisions[0].rev.revision_id)
1289
def test_many_revisions(self):
1290
tree = self.setup_ab_tree()
1292
start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1293
end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
1294
log.show_log(tree.branch, lf, verbose=True, start_revision=start_rev,
1295
end_revision=end_rev)
1296
self.assertEqual(3, len(lf.revisions))
1297
self.assertEqual(None, lf.revisions[0].revno) # Out-of-branch
1298
self.assertEqual(b'3a', lf.revisions[0].rev.revision_id)
1299
self.assertEqual(None, lf.revisions[1].revno) # Out-of-branch
1300
self.assertEqual(b'2a', lf.revisions[1].rev.revision_id)
1301
self.assertEqual('1', lf.revisions[2].revno) # In-branch
1303
def test_long_format(self):
1304
tree = self.setup_ab_tree()
1305
start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1306
end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
1307
self.assertFormatterResult(b"""\
1308
------------------------------------------------------------
1310
committer: Joe Foo <joe@foo.com>
1312
timestamp: Tue 2005-11-22 00:00:00 +0000
1315
------------------------------------------------------------
1317
committer: Joe Foo <joe@foo.com>
1319
timestamp: Tue 2005-11-22 00:00:00 +0000
1322
------------------------------------------------------------
1324
committer: Joe Foo <joe@foo.com>
1326
timestamp: Tue 2005-11-22 00:00:00 +0000
1330
tree.branch, log.LongLogFormatter, show_log_kwargs={
1331
'start_revision': start_rev, 'end_revision': end_rev
1334
def test_short_format(self):
1335
tree = self.setup_ab_tree()
1336
start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1337
end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
1338
self.assertFormatterResult(b"""\
1347
1 Joe Foo\t2005-11-22
1351
tree.branch, log.ShortLogFormatter, show_log_kwargs={
1352
'start_revision': start_rev, 'end_revision': end_rev
1355
def test_line_format(self):
1356
tree = self.setup_ab_tree()
1357
start_rev = revisionspec.RevisionInfo(tree.branch, None, b'1a')
1358
end_rev = revisionspec.RevisionInfo(tree.branch, None, b'3a')
1359
self.assertFormatterResult(b"""\
1360
Joe Foo 2005-11-22 commit 3a
1361
Joe Foo 2005-11-22 commit 2a
1362
1: Joe Foo 2005-11-22 commit 1a
1364
tree.branch, log.LineLogFormatter, show_log_kwargs={
1365
'start_revision': start_rev, 'end_revision': end_rev
1467
1369
class TestLogWithBugs(TestCaseForLogFormatter, TestLogMixin):
1469
1371
def setUp(self):
1470
TestCaseForLogFormatter.setUp(self)
1372
super(TestLogWithBugs, self).setUp()
1471
1373
log.properties_handler_registry.register(
1472
1374
'bugs_properties_handler',
1473
1375
log._bugs_properties_handler)
1543
1445
def test_bugs_handler_present(self):
1544
1446
self.properties_handler_registry.get('bugs_properties_handler')
1449
class TestLogForAuthors(TestCaseForLogFormatter):
1452
super(TestLogForAuthors, self).setUp()
1453
self.wt = self.make_standard_commit('nicky',
1454
authors=['John Doe <jdoe@example.com>',
1455
'Jane Rey <jrey@example.com>'])
1457
def assertFormatterResult(self, formatter, who, result):
1458
formatter_kwargs = dict()
1460
author_list_handler = log.author_list_registry.get(who)
1461
formatter_kwargs['author_list_handler'] = author_list_handler
1462
TestCaseForLogFormatter.assertFormatterResult(self, result,
1463
self.wt.branch, formatter, formatter_kwargs=formatter_kwargs)
1465
def test_line_default(self):
1466
self.assertFormatterResult(log.LineLogFormatter, None, b"""\
1467
1: John Doe 2005-11-22 add a
1470
def test_line_committer(self):
1471
self.assertFormatterResult(log.LineLogFormatter, 'committer', b"""\
1472
1: Lorem Ipsum 2005-11-22 add a
1475
def test_line_first(self):
1476
self.assertFormatterResult(log.LineLogFormatter, 'first', b"""\
1477
1: John Doe 2005-11-22 add a
1480
def test_line_all(self):
1481
self.assertFormatterResult(log.LineLogFormatter, 'all', b"""\
1482
1: John Doe, Jane Rey 2005-11-22 add a
1486
def test_short_default(self):
1487
self.assertFormatterResult(log.ShortLogFormatter, None, b"""\
1488
1 John Doe\t2005-11-22
1493
def test_short_committer(self):
1494
self.assertFormatterResult(log.ShortLogFormatter, 'committer', b"""\
1495
1 Lorem Ipsum\t2005-11-22
1500
def test_short_first(self):
1501
self.assertFormatterResult(log.ShortLogFormatter, 'first', b"""\
1502
1 John Doe\t2005-11-22
1507
def test_short_all(self):
1508
self.assertFormatterResult(log.ShortLogFormatter, 'all', b"""\
1509
1 John Doe, Jane Rey\t2005-11-22
1514
def test_long_default(self):
1515
self.assertFormatterResult(log.LongLogFormatter, None, b"""\
1516
------------------------------------------------------------
1518
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1519
committer: Lorem Ipsum <test@example.com>
1521
timestamp: Tue 2005-11-22 00:00:00 +0000
1526
def test_long_committer(self):
1527
self.assertFormatterResult(log.LongLogFormatter, 'committer', b"""\
1528
------------------------------------------------------------
1530
committer: Lorem Ipsum <test@example.com>
1532
timestamp: Tue 2005-11-22 00:00:00 +0000
1537
def test_long_first(self):
1538
self.assertFormatterResult(log.LongLogFormatter, 'first', b"""\
1539
------------------------------------------------------------
1541
author: John Doe <jdoe@example.com>
1542
committer: Lorem Ipsum <test@example.com>
1544
timestamp: Tue 2005-11-22 00:00:00 +0000
1549
def test_long_all(self):
1550
self.assertFormatterResult(log.LongLogFormatter, 'all', b"""\
1551
------------------------------------------------------------
1553
author: John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1554
committer: Lorem Ipsum <test@example.com>
1556
timestamp: Tue 2005-11-22 00:00:00 +0000
1561
def test_gnu_changelog_default(self):
1562
self.assertFormatterResult(log.GnuChangelogLogFormatter, None, b"""\
1563
2005-11-22 John Doe <jdoe@example.com>
1569
def test_gnu_changelog_committer(self):
1570
self.assertFormatterResult(log.GnuChangelogLogFormatter, 'committer', b"""\
1571
2005-11-22 Lorem Ipsum <test@example.com>
1577
def test_gnu_changelog_first(self):
1578
self.assertFormatterResult(log.GnuChangelogLogFormatter, 'first', b"""\
1579
2005-11-22 John Doe <jdoe@example.com>
1585
def test_gnu_changelog_all(self):
1586
self.assertFormatterResult(log.GnuChangelogLogFormatter, 'all', b"""\
1587
2005-11-22 John Doe <jdoe@example.com>, Jane Rey <jrey@example.com>
1546
1594
class TestLogExcludeAncestry(tests.TestCaseWithTransport):
1548
1596
def make_branch_with_alternate_ancestries(self, relpath='.'):
1549
1597
# See test_merge_sorted_exclude_ancestry below for the difference with
1550
1598
# bt.per_branch.test_iter_merge_sorted_revision.
1551
# TestIterMergeSortedRevisionsBushyGraph.
1599
# TestIterMergeSortedRevisionsBushyGraph.
1552
1600
# make_branch_with_alternate_ancestries
1553
1601
# and test_merge_sorted_exclude_ancestry
1554
1602
# See the FIXME in assertLogRevnos too.
1581
1630
def assertLogRevnos(self, expected_revnos, b, start, end,
1582
exclude_common_ancestry):
1631
exclude_common_ancestry, generate_merge_revisions=True):
1583
1632
# FIXME: the layering in log makes it hard to test intermediate levels,
1584
# I wish adding filters with their parameters were easier...
1633
# I wish adding filters with their parameters was easier...
1585
1634
# -- vila 20100413
1586
1635
iter_revs = log._calc_view_revisions(
1587
1636
b, start, end, direction='reverse',
1588
generate_merge_revisions=True,
1637
generate_merge_revisions=generate_merge_revisions,
1589
1638
exclude_common_ancestry=exclude_common_ancestry)
1590
1639
self.assertEqual(expected_revnos,
1591
1640
[revid for revid, revno, depth in iter_revs])
1593
1642
def test_merge_sorted_exclude_ancestry(self):
1594
1643
b = self.make_branch_with_alternate_ancestries()
1595
self.assertLogRevnos(['3', '1.1.2', '1.2.1', '1.1.1', '2', '1'],
1644
self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'1.1.1', b'2', b'1'],
1645
b, b'1', b'3', exclude_common_ancestry=False)
1597
1646
# '2' is part of the '3' ancestry but not part of '1.1.1' ancestry so
1598
1647
# it should be mentioned even if merge_sort order will make it appear
1600
self.assertLogRevnos(['3', '1.1.2', '1.2.1', '2'],
1601
b, '1.1.1', '3', True)
1649
self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'2'],
1650
b, b'1.1.1', b'3', exclude_common_ancestry=True)
1652
def test_merge_sorted_simple_revnos_exclude_ancestry(self):
1653
b = self.make_branch_with_alternate_ancestries()
1654
self.assertLogRevnos([b'3', b'2'],
1655
b, b'1', b'3', exclude_common_ancestry=True,
1656
generate_merge_revisions=False)
1657
self.assertLogRevnos([b'3', b'1.1.2', b'1.2.1', b'1.1.1', b'2'],
1658
b, b'1', b'3', exclude_common_ancestry=True,
1659
generate_merge_revisions=True)
1662
class TestLogDefaults(TestCaseForLogFormatter):
1663
def test_default_log_level(self):
1665
Test to ensure that specifying 'levels=1' to make_log_request_dict
1666
doesn't get overwritten when using a LogFormatter that supports more
1670
wt = self._prepare_tree_with_merges()
1673
class CustomLogFormatter(log.LogFormatter):
1674
def __init__(self, *args, **kwargs):
1675
super(CustomLogFormatter, self).__init__(*args, **kwargs)
1677
def get_levels(self):
1678
# log formatter supports all levels:
1680
def log_revision(self, revision):
1681
self.revisions.append(revision)
1683
log_formatter = LogCatcher()
1684
# First request we don't specify number of levels, we should get a
1685
# sensible default (whatever the LogFormatter handles - which in this
1686
# case is 0/everything):
1687
request = log.make_log_request_dict(limit=10)
1688
log.Logger(b, request).show(log_formatter)
1689
# should have all three revisions:
1690
self.assertEqual(len(log_formatter.revisions), 3)
1693
log_formatter = LogCatcher()
1694
# now explicitly request mainline revisions only:
1695
request = log.make_log_request_dict(limit=10, levels=1)
1696
log.Logger(b, request).show(log_formatter)
1697
# should now only have 2 revisions:
1698
self.assertEqual(len(log_formatter.revisions), 2)