/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_foreign.py

  • Committer: Jelmer Vernooij
  • Date: 2009-04-09 21:50:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4281.
  • Revision ID: jelmer@samba.org-20090409215023-l1wqokoy35s9z8zy
Fix tests after CommitBuilder changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for foreign VCS utility code."""
19
19
 
 
20
 
20
21
from bzrlib import (
21
22
    branch,
22
23
    errors,
34
35
    )
35
36
from bzrlib.inventory import Inventory
36
37
from bzrlib.revision import Revision
37
 
from bzrlib.tests import TestCase, TestCaseWithTransport
 
38
from bzrlib.tests import (
 
39
    TestCase,
 
40
    TestCaseWithTransport,
 
41
    )
38
42
 
39
43
# This is the dummy foreign revision control system, used 
40
44
# mainly here in the testsuite to test the foreign VCS infrastructure.
92
96
        self._format = _format
93
97
        self._base = a_bzrdir.transport.base
94
98
        self._ignore_fallbacks = False
95
 
        foreign.ForeignBranch.__init__(self, DummyForeignVcsMapping(DummyForeignVcs()))
96
 
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, *args, **kwargs)
 
99
        foreign.ForeignBranch.__init__(self, 
 
100
            DummyForeignVcsMapping(DummyForeignVcs()))
 
101
        branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, 
 
102
            *args, **kwargs)
97
103
 
98
104
    def dpull(self, source, stop_revision=None):
99
 
        # This just handles simple cases, but that's good enough for tests
100
 
        my_history = self.revision_history()
101
 
        their_history = source.revision_history()
102
 
        if their_history[:min(len(my_history), len(their_history))] != my_history:
103
 
            raise errors.DivergedBranches(self, source)
104
 
        todo = their_history[len(my_history):]
105
 
        revidmap = {}
106
 
        for revid in todo:
107
 
            rev = source.repository.get_revision(revid)
108
 
            tree = source.repository.revision_tree(revid)
109
 
            builder = self.get_commit_builder([self.last_revision()], 
110
 
                    self.get_config(), rev.timestamp,
111
 
                    rev.timezone, rev.committer, rev.properties)
112
 
            for path, ie in tree.inventory.iter_entries():
113
 
                builder.record_entry_contents(ie.copy(), 
114
 
                    [self.repository.get_inventory(self.last_revision())],
115
 
                    path, tree, None)
116
 
            builder.finish_inventory()
117
 
            revidmap[revid] = builder.commit(rev.message)
118
 
            trace.mutter('lossily pushed revision %s -> %s', 
119
 
                revid, revidmap[revid])
 
105
        source.lock_read()
 
106
        try:
 
107
            # This just handles simple cases, but that's good enough for tests
 
108
            my_history = self.revision_history()
 
109
            their_history = source.revision_history()
 
110
            if their_history[:min(len(my_history), len(their_history))] != my_history:
 
111
                raise errors.DivergedBranches(self, source)
 
112
            todo = their_history[len(my_history):]
 
113
            revidmap = {}
 
114
            for revid in todo:
 
115
                rev = source.repository.get_revision(revid)
 
116
                tree = source.repository.revision_tree(revid)
 
117
                def get_file_with_stat(file_id, path=None):
 
118
                    return (tree.get_file(file_id), None)
 
119
                tree.get_file_with_stat = get_file_with_stat
 
120
                new_revid = self.mapping.revision_id_foreign_to_bzr(
 
121
                    (str(rev.timestamp), str(rev.timezone), str(self.revno())))
 
122
                parent_revno, parent_revid= self.last_revision_info()
 
123
                builder = self.get_commit_builder([parent_revid], 
 
124
                        self.get_config(), rev.timestamp,
 
125
                        rev.timezone, rev.committer, rev.properties,
 
126
                        new_revid)
 
127
                try:
 
128
                    for path, ie in tree.inventory.iter_entries():
 
129
                        new_ie = ie.copy()
 
130
                        new_ie.revision = None
 
131
                        builder.record_entry_contents(new_ie, 
 
132
                            [self.repository.get_inventory(parent_revid)],
 
133
                            path, tree, 
 
134
                            (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
 
135
                    builder.finish_inventory()
 
136
                except:
 
137
                    builder.abort()
 
138
                    raise
 
139
                revidmap[revid] = builder.commit(rev.message)
 
140
                self.set_last_revision_info(parent_revno+1, revidmap[revid])
 
141
                trace.mutter('lossily pushed revision %s -> %s', 
 
142
                    revid, revidmap[revid])
 
143
        finally:
 
144
            source.unlock()
120
145
        return revidmap
121
146
 
122
147