/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/bzrdir.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-02-04 17:41:12 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070204174112-iv6gxzinnjddlaxj
Add tests for redirection. Preserve transport decorations.

* bzrlib/tests/test_http.py:
(TestRedirections): new tests.

* bzrlib/tests/HttpServer.py:
(HttpServer): Make server host and port public once the socket
have been established.

* bzrlib/tests/HTTPTestUtil.py:
(RedirectRequestHandler, HTTPServerRedirecting): New http test
server for redirections. Only a whole host can be redirected, so
far.

* bzrlib/errors.py:
(RedirectRequested.__init__): Add a 'qual_proto' oso that
transport decorations can be transmitted to redirected transport.
(RedirectRequested._requalify_url,
RedirectRequested.get_source_url,
RedirectRequested.get_target_url): New methods providing fully
decorated urls.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): The redirection should preserve
transport decorations.
(BzrDirMetaFormat1): To be able to specialize bzr branches from
foreign branches, we need to register BzrDirMetaFormat1 as the
default control format (instead of BzrDirMetaFormat which is
abstract and can still be used by foreign branches).

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
                redirected = False
525
525
            except errors.RedirectRequested, e:
526
526
 
527
 
                relpath = transport.relpath(e.source)
 
527
                qualified_source = e.get_source_url()
 
528
                relpath = transport.relpath(qualified_source)
528
529
                if not e.target.endswith(relpath):
529
530
                    # Not redirected to a branch-format, not a branch
530
531
                    raise errors.NotBranchError(path=e.target)
531
532
 
532
533
                target = e.target[:-len(relpath)]
533
 
                note('%s has been%s redirected to %s',
 
534
                note('%s is%s redirected to %s',
534
535
                     transport.base,
535
536
                     e.permanently,
536
537
                     target)
537
538
                # Let's try with a new transport
 
539
                qualified_target = e.get_target_url()[:-len(relpath)]
538
540
                transport = get_transport(target)
539
541
                redirections += 1
540
542
        if redirected:
1257
1259
 
1258
1260
    @classmethod
1259
1261
    def register_control_format(klass, format):
1260
 
        """Register a format that does not use '.bzrdir' for its control dir.
 
1262
        """Register a format that does not use '.bzr' for its control dir.
1261
1263
 
1262
1264
        TODO: This should be pulled up into a 'ControlDirFormat' base class
1263
1265
        which BzrDirFormat can inherit from, and renamed to register_format 
1289
1291
        klass._control_formats.remove(format)
1290
1292
 
1291
1293
 
1292
 
# register BzrDirFormat as a control format
1293
 
BzrDirFormat.register_control_format(BzrDirFormat)
1294
 
 
1295
 
 
1296
1294
class BzrDirFormat4(BzrDirFormat):
1297
1295
    """Bzr dir format 4.
1298
1296
 
1527
1525
        except KeyError:
1528
1526
            raise errors.UnknownFormatError(format=format_string)
1529
1527
 
 
1528
    # REVIEWER: The following line is black magic for me. Any
 
1529
    # pointer appreciated
1530
1530
    repository_format = property(__return_repository_format, __set_repository_format)
1531
1531
 
1532
1532
 
 
1533
# register BzrDirMetaFormat1 as a control format. Our only
 
1534
# concrete control format (BzrDirFormat is an abstract one).
 
1535
BzrDirFormat.register_control_format(BzrDirMetaFormat1)
 
1536
 
 
1537
# Register bzr formats
1533
1538
BzrDirFormat.register_format(BzrDirFormat4())
1534
1539
BzrDirFormat.register_format(BzrDirFormat5())
1535
1540
BzrDirFormat.register_format(BzrDirFormat6())