[MERGE] Quicker initial commit

Aaron Bentley aaron.bentley at utoronto.ca
Thu Aug 23 17:42:20 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ian Clatworthy wrote:

>  class InventoryFile(InventoryEntry):
> @@ -716,12 +700,28 @@
>      def _forget_tree_state(self):
>          self.text_sha1 = None
>  
> -    def _snapshot_text(self, file_parents, work_tree, commit_builder):
> -        """See InventoryEntry._snapshot_text."""
> +    def snapshot(self, revision, path, previous_entries,
> +                 work_tree, commit_builder):
> +        """See InventoryEntry.snapshot."""
> +        # We have a custom implementation of this for files because it's
> +        # performance critical.
> +        if len(previous_entries) == 0:
> +            # Initial commit so we know the sha is coming later
> +            self.executable = work_tree.is_executable(self.file_id, path=path)
> +        else:
> +            self._read_tree_state(path, work_tree)
> +            if len(previous_entries) == 1:
> +                parent_ie = previous_entries.values()[0]
> +                if self._unchanged(parent_ie):
> +                    self.revision = parent_ie.revision
> +                    return False
> +        self.revision = revision

^^^ This looks odd.

Perhaps it would be clearer as:

        if len(previous_entries) == 0:
            # Initial commit so we know the sha is coming later
            self.executable = work_tree.is_executable(self.file_id,
path=path)
        else:
            self._read_tree_state(path, work_tree)
        if len(previous_entries) == 1:
            parent_ie = previous_entries.values()[0]
            if self._unchanged(parent_ie):
                self.revision = parent_ie.revision
                return False
        else:
            self.revision = revision
            self.text_sha1, self.text_size = commit_builder.modified ...

I missed the "return False" on the first reading, which made it look
very strange indeed.

> === modified file 'bzrlib/workingtree_4.py'
> --- bzrlib/workingtree_4.py	2007-08-21 01:40:39 +0000
> +++ bzrlib/workingtree_4.py	2007-08-23 00:12:35 +0000
> @@ -1505,7 +1505,7 @@
>          return self._repository.weave_store.get_weave(file_id,
>                  self._repository.get_transaction())
>  
> -    def get_file(self, file_id):
> +    def get_file(self, file_id, path=None):
>          return StringIO(self.get_file_text(file_id))

I think you should add a test to make sure all Tree implementations will
accept a path in get_file.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGzbjs0F+nu1YWqI0RAuGZAJ0WcJzwusI52Vv1K3pYGfp+VY94lACggs1C
uZhSqhZbzSrfTRtbsrrdOso=
=M+0Y
-----END PGP SIGNATURE-----



More information about the bazaar mailing list