~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branchbuilder.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-04 14:48:21 UTC
  • mto: (4349.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4350.
  • Revision ID: v.ladeuil+lp@free.fr-20090504144821-39dvqkikmd3zqkdg
Handle servers proposing several authentication schemes.

* bzrlib/transport/http/_urllib2_wrappers.py:
(AbstractAuthHandler.auth_required): Several schemes can be
proposed by the server, try to match each one in turn.
(BasicAuthHandler.auth_match): Delete dead code.

* bzrlib/tests/test_http.py:
(load_tests): Separate proxy and http authentication tests as they
require different server setups.
(TestAuth.create_transport_readonly_server): Simplified by using
parameter provided by load_tests.
(TestAuth.test_changing_nonce): Adapt to new parametrization.
(TestProxyAuth.create_transport_readonly_server): Deleted.

* bzrlib/tests/http_utils.py:
(DigestAndBasicAuthRequestHandler, HTTPBasicAndDigestAuthServer,
ProxyBasicAndDigestAuthServer): Add a test server proposing both
basic and digest auth schemes but accepting only digest as valid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    commit,
22
22
    errors,
23
23
    memorytree,
24
 
    revision,
25
24
    )
26
25
 
27
26
 
104
103
        finally:
105
104
            tree.unlock()
106
105
 
107
 
    def _do_commit(self, tree, message=None, message_callback=None, **kwargs):
 
106
    def _do_commit(self, tree, message=None, **kwargs):
108
107
        reporter = commit.NullCommitReporter()
109
 
        if message is None and message_callback is None:
 
108
        if message is None:
110
109
            message = u'commit %d' % (self._branch.revno() + 1,)
111
 
        return tree.commit(message, message_callback=message_callback,
 
110
        return tree.commit(message,
112
111
            reporter=reporter,
113
112
            **kwargs)
114
113
 
115
 
    def _move_branch_pointer(self, new_revision_id,
116
 
        allow_leftmost_as_ghost=False):
 
114
    def _move_branch_pointer(self, new_revision_id):
117
115
        """Point self._branch to a different revision id."""
118
116
        self._branch.lock_write()
119
117
        try:
120
118
            # We don't seem to have a simple set_last_revision(), so we
121
119
            # implement it here.
122
120
            cur_revno, cur_revision_id = self._branch.last_revision_info()
123
 
            try:
124
 
                g = self._branch.repository.get_graph()
125
 
                new_revno = g.find_distance_to_null(new_revision_id,
126
 
                    [(cur_revision_id, cur_revno)])
127
 
                self._branch.set_last_revision_info(new_revno, new_revision_id)
128
 
            except errors.GhostRevisionsHaveNoRevno:
129
 
                if not allow_leftmost_as_ghost:
130
 
                    raise
131
 
                new_revno = 1
 
121
            g = self._branch.repository.get_graph()
 
122
            new_revno = g.find_distance_to_null(new_revision_id,
 
123
                                                [(cur_revision_id, cur_revno)])
 
124
            self._branch.set_last_revision_info(new_revno, new_revision_id)
132
125
        finally:
133
126
            self._branch.unlock()
134
127
        if self._tree is not None:
162
155
        self._tree = None
163
156
 
164
157
    def build_snapshot(self, revision_id, parent_ids, actions,
165
 
        message=None, timestamp=None, allow_leftmost_as_ghost=False,
166
 
        committer=None, timezone=None, message_callback=None):
 
158
                       message=None, timestamp=None):
167
159
        """Build a commit, shaped in a specific way.
168
160
 
169
161
        :param revision_id: The handle for the new commit, can be None
176
168
            ('rename', ('orig-path', 'new-path'))
177
169
        :param message: An optional commit message, if not supplied, a default
178
170
            commit message will be written.
179
 
        :param message_callback: A message callback to use for the commit, as
180
 
            per mutabletree.commit.
181
171
        :param timestamp: If non-None, set the timestamp of the commit to this
182
172
            value.
183
 
        :param timezone: An optional timezone for timestamp.
184
 
        :param committer: An optional username to use for commit
185
 
        :param allow_leftmost_as_ghost: True if the leftmost parent should be
186
 
            permitted to be a ghost.
187
173
        :return: The revision_id of the new commit
188
174
        """
189
175
        if parent_ids is not None:
190
 
            if len(parent_ids) == 0:
191
 
                base_id = revision.NULL_REVISION
192
 
            else:
193
 
                base_id = parent_ids[0]
 
176
            base_id = parent_ids[0]
194
177
            if base_id != self._branch.last_revision():
195
 
                self._move_branch_pointer(base_id,
196
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
178
                self._move_branch_pointer(base_id)
197
179
 
198
180
        if self._tree is not None:
199
181
            tree = self._tree
202
184
        tree.lock_write()
203
185
        try:
204
186
            if parent_ids is not None:
205
 
                tree.set_parent_ids(parent_ids,
206
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
187
                tree.set_parent_ids(parent_ids)
207
188
            # Unfortunately, MemoryTree.add(directory) just creates an
208
189
            # inventory entry. And the only public function to create a
209
190
            # directory is MemoryTree.mkdir() which creates the directory, but
250
231
            for file_id, content in new_contents.iteritems():
251
232
                tree.put_file_bytes_non_atomic(file_id, content)
252
233
            return self._do_commit(tree, message=message, rev_id=revision_id,
253
 
                timestamp=timestamp, timezone=timezone, committer=committer,
254
 
                message_callback=message_callback)
 
234
                timestamp=timestamp)
255
235
        finally:
256
236
            tree.unlock()
257
237