~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_iter_reverse_revision_history.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Test iter_reverse_revision_history."""
 
18
 
 
19
from bzrlib import (
 
20
    errors,
 
21
    osutils,
 
22
    tests,
 
23
    )
 
24
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
 
25
 
 
26
 
 
27
class TestIterReverseRevisionHistory(TestCaseWithRepository):
 
28
 
 
29
    def create_linear_history(self):
 
30
        tree = self.make_branch_and_memory_tree('tree')
 
31
        tree.lock_write()
 
32
        try:
 
33
            tree.add('')
 
34
            tree.commit('1', rev_id='rev1')
 
35
            tree.commit('2', rev_id='rev2')
 
36
            tree.commit('3', rev_id='rev3')
 
37
            tree.commit('4', rev_id='rev4')
 
38
        finally:
 
39
            tree.unlock()
 
40
        return tree
 
41
 
 
42
    def create_linear_history_with_utf8(self):
 
43
        tree = self.make_branch_and_memory_tree('tree')
 
44
        tree.lock_write()
 
45
        try:
 
46
            tree.add('') # needed for MemoryTree
 
47
            try:
 
48
                tree.commit(u'F\xb5', rev_id=u'rev-\xb5'.encode('utf8'))
 
49
            except errors.NonAsciiRevisionId:
 
50
                raise tests.TestSkipped("%s doesn't support non-ascii"
 
51
                                        " revision ids."
 
52
                                        % self.repository_format)
 
53
            tree.commit(u'B\xe5r', rev_id=u'rev-\xe5'.encode('utf8'))
 
54
        finally:
 
55
            tree.unlock()
 
56
        return tree
 
57
 
 
58
    def create_merged_history(self):
 
59
        # TODO: jam 20070216 MutableTree doesn't yet have the pull() or
 
60
        #       merge_from_branch() apis. So we have to use real trees for
 
61
        #       this.
 
62
        tree1 = self.make_branch_and_tree('tree1')
 
63
        tree2 = self.make_branch_and_tree('tree2')
 
64
        tree1.lock_write()
 
65
        tree2.lock_write()
 
66
        try:
 
67
            tree1.add('')
 
68
            tree1.commit('rev-1-1', rev_id='rev-1-1')
 
69
            tree2.pull(tree1.branch)
 
70
            tree2.commit('rev-2-2', rev_id='rev-2-2')
 
71
            tree2.commit('rev-2-3', rev_id='rev-2-3')
 
72
            tree2.commit('rev-2-4', rev_id='rev-2-4')
 
73
 
 
74
            tree1.commit('rev-1-2', rev_id='rev-1-2')
 
75
            tree1.flush() # workaround merge using _write_inventory
 
76
            tree1.merge_from_branch(tree2.branch)
 
77
            tree1.commit('rev-1-3', rev_id='rev-1-3')
 
78
 
 
79
            tree2.commit('rev-2-5', rev_id='rev-2-5')
 
80
            # Make sure both repositories have all revisions
 
81
            tree1.branch.repository.fetch(tree2.branch.repository,
 
82
                                          revision_id='rev-2-5')
 
83
            tree2.branch.repository.fetch(tree1.branch.repository,
 
84
                                          revision_id='rev-1-3')
 
85
        finally:
 
86
            tree2.unlock()
 
87
            tree1.unlock()
 
88
        return tree1, tree2
 
89
 
 
90
    def test_is_generator(self):
 
91
        tree = self.create_linear_history()
 
92
        repo = tree.branch.repository
 
93
 
 
94
        rev_history = repo.iter_reverse_revision_history('rev4')
 
95
        self.assertEqual('rev4', rev_history.next())
 
96
        self.assertEqual('rev3', rev_history.next())
 
97
        self.assertEqual('rev2', rev_history.next())
 
98
        self.assertEqual('rev1', rev_history.next())
 
99
        self.assertRaises(StopIteration, rev_history.next)
 
100
 
 
101
    def assertRevHistoryList(self, expected, repo, revision_id):
 
102
        """Assert the return values of iter_reverse_revision_history."""
 
103
        actual = list(repo.iter_reverse_revision_history(revision_id))
 
104
        self.assertEqual(expected, actual)
 
105
 
 
106
    def test_linear_history(self):
 
107
        tree = self.create_linear_history()
 
108
        repo = tree.branch.repository
 
109
 
 
110
        self.assertRevHistoryList(['rev4', 'rev3', 'rev2', 'rev1'],
 
111
                                  repo, 'rev4')
 
112
 
 
113
    def test_partial_history(self):
 
114
        tree = self.create_linear_history()
 
115
        repo = tree.branch.repository
 
116
 
 
117
        self.assertRevHistoryList(['rev3', 'rev2', 'rev1'], repo, 'rev3')
 
118
 
 
119
    def test_revision_ids_are_utf8(self):
 
120
        tree = self.create_linear_history_with_utf8()
 
121
        repo = tree.branch.repository
 
122
 
 
123
        self.assertRevHistoryList(['rev-\xc3\xa5', 'rev-\xc2\xb5'],
 
124
                                  repo, 'rev-\xc3\xa5')
 
125
 
 
126
        self.callDeprecated([osutils._revision_id_warning],
 
127
                            self.assertRevHistoryList,
 
128
                                ['rev-\xc3\xa5', 'rev-\xc2\xb5'],
 
129
                                repo, u'rev-\xe5')
 
130
 
 
131
    def test_merged_history(self):
 
132
        tree1, tree2 = self.create_merged_history()
 
133
        repo = tree1.branch.repository
 
134
 
 
135
        self.assertRevHistoryList(['rev-1-1'],
 
136
                                  repo, 'rev-1-1')
 
137
        self.assertRevHistoryList(['rev-1-2', 'rev-1-1'],
 
138
                                  repo, 'rev-1-2')
 
139
        self.assertRevHistoryList(['rev-1-3', 'rev-1-2', 'rev-1-1'],
 
140
                                  repo, 'rev-1-3')
 
141
        self.assertRevHistoryList(['rev-2-2', 'rev-1-1'],
 
142
                                  repo, 'rev-2-2')
 
143
        self.assertRevHistoryList(['rev-2-3', 'rev-2-2', 'rev-1-1'],
 
144
                                  repo, 'rev-2-3')
 
145
        self.assertRevHistoryList(['rev-2-4', 'rev-2-3', 'rev-2-2', 'rev-1-1'],
 
146
                                  repo, 'rev-2-4')
 
147
        self.assertRevHistoryList(['rev-2-5', 'rev-2-4', 'rev-2-3', 'rev-2-2',
 
148
                                   'rev-1-1'], repo, 'rev-2-5')