[MERGE] support non '.bzr' control directories better.

Martin Pool mbp at canonical.com
Sun Jun 4 12:58:11 BST 2006


On  1 Jun 2006, Robert Collins <robertc at robertcollins.net> wrote:
> This should be useful for jelmer's SVN work, and was needed for my hg
> plugin.
> 
> Branch is at
> http://people.ubuntu.com/~robertc/baz2.0/non-bzr-control-dirs

About +0.5; you can merge it if you like but I'd like it simplified a
bit.

> === modified file 'bzrlib/bzrdir.py'
> --- bzrlib/bzrdir.py	
> +++ bzrlib/bzrdir.py	
> @@ -931,6 +931,9 @@
>      _formats = {}
>      """The known formats."""
>  
> +    _control_formats = set()
> +    """The core control formats - .bzr, ...."""
> +

This comment makes it look like they're strings, but they're actually
Format objects. (Right?)  Also should say that it's a class variable
holding all registered commands.

>      _lock_file_name = 'branch-lock'
>  
>      # _lock_class must be set in subclasses to the lock type, typ.
> @@ -938,7 +941,18 @@
>  
>      @classmethod
>      def find_format(klass, transport):
> -        """Return the format registered for URL."""
> +        """Return the format present at transport."""
> +        for format in klass._control_formats:
> +            try:
> +                return format.probe_transport(transport)
> +            except errors.NotBranchError:
> +                # this format does not find a control dir here.
> +                pass
> +        raise errors.NotBranchError(path=transport.base)
> +
> +    @classmethod
> +    def probe_transport(klass, transport):
> +        """Return the .bzrdir style transport present at URL."""
>          try:
>              format_string = transport.get(".bzr/branch-format").read()
>              return klass._formats[format_string]
> @@ -1021,6 +1035,22 @@
>          """
>          return True
>  
> +    @classmethod
> +    def known_formats(klass):
> +        """Return all the known formats.
> +        
> +        Concrete formats should override _known_formats.
> +        """
> +        result = set()
> +        for format in klass._control_formats:
> +            result.update(format._known_formats())
> +        return result
> +    
> +    @classmethod
> +    def _known_formats(klass):
> +        """Return the known format instances for this control format."""
> +        return set(klass._formats.values())
> +
>      def open(self, transport, _found=False):
>          """Return an instance of this format for the dir transport points at.

I think there are too many layers here: do we really need sets of sets?
I understand it can optimize probing a little (read .bzr/branch-format
once, then compare to various strings) but we can deal with that later.

>          
> @@ -1044,6 +1074,17 @@
>          klass._formats[format.get_format_string()] = format
>  
>      @classmethod
> +    def register_control_format(klass, format):
> +        """Register a format that does not use '.bzrdir' for its control dir.
> +
> +        TODO: This should be pulled up into a 'ControlDirFormat' base class
> +        which BzrDirFormat can inherit from, and renamed to register_format 
> +        there. It has been done without that for now for simplicity of
> +        implementation.
> +        """
> +        klass._control_formats.add(format)

OK

> +
> +    @classmethod
>      def set_default_format(klass, format):
>          klass._default_format = format
>  
> @@ -1055,6 +1096,14 @@
>          assert klass._formats[format.get_format_string()] is format
>          del klass._formats[format.get_format_string()]
>  
> +    @classmethod
> +    def unregister_control_format(klass, format):
> +        klass._control_formats.remove(format)
> +
> +
> +# register BzrDirFormat as a control format
> +BzrDirFormat.register_control_format(BzrDirFormat)
> +
>  
>  class BzrDirFormat4(BzrDirFormat):
>      """Bzr dir format 4.
> 
> === modified file 'bzrlib/inventory.py'
> --- bzrlib/inventory.py	
> +++ bzrlib/inventory.py	

> @@ -671,6 +673,15 @@
>          self.text_sha1 = work_tree.get_file_sha1(self.file_id)
>          self.executable = work_tree.is_executable(self.file_id)
>  
> +    def __repr__(self):
> +        return ("%s(%r, %r, parent_id=%r, sha1=%r, len=%s)"
> +                % (self.__class__.__name__,
> +                   self.file_id,
> +                   self.name,
> +                   self.parent_id,
> +                   self.text_sha1,
> +                   self.text_size))
> +
>      def _forget_tree_state(self):
>          self.text_sha1 = None
>          self.executable = None

OK, good.

> @@ -847,6 +858,8 @@
>          #if root_id is None:
>          #    root_id = bzrlib.branch.gen_file_id('TREE_ROOT')
>          self.root = RootEntry(root_id)
> +        # FIXME: this isn't ever used, changin it to self.revision may break
> +        # things. TODO make everything one or the other.
>          self.revision_id = revision_id
>          self._byid = {self.root.file_id: self.root}

Let's make it revision_id everywhere.

> @@ -1057,6 +1070,7 @@
>          if not isinstance(other, Inventory):
>              return NotImplemented
>  
> +        # is this needed? (Doesn't dict do this ?)
>          if len(self._byid) != len(other._byid):
>              # shortcut: obviously not the same
>              return False
> 

I think you should just remove it.


-- 
Martin




More information about the bazaar mailing list