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

  • Committer: John Arbash Meinel
  • Date: 2008-07-22 18:12:25 UTC
  • mto: (3514.4.6 merge_lca_multi)
  • mto: This revision was merged to the branch mainline in revision 3590.
  • Revision ID: john@arbash-meinel.com-20080722181225-nx1dwfmb4wky600x
Revert back to using MemoryTree.mkdir() rather than creating the directory during add().

This complicates the api a bit, because we have to use multiple passes,
but at least we don't change any tested behavior.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
        tree = memorytree.MemoryTree.create_on_branch(self._branch)
65
65
        tree.lock_write()
66
66
        try:
67
 
            to_add_paths = []
 
67
            # Unfortunately, MemoryTree.add(directory) just creates an
 
68
            # inventory entry. And the only public function to create a
 
69
            # directory is MemoryTree.mkdir() which creates the directory, but
 
70
            # also always adds it. So we have to use a multi-pass setup.
 
71
            to_add_directories = []
 
72
            to_add_files = []
68
73
            to_add_file_ids = []
69
74
            to_add_kinds = []
70
75
            new_contents = {}
73
78
            for action, info in actions:
74
79
                if action == 'add':
75
80
                    path, file_id, kind, content = info
76
 
                    to_add_paths.append(path)
77
 
                    to_add_file_ids.append(file_id)
78
 
                    to_add_kinds.append(kind)
79
 
                    if content is not None:
80
 
                        new_contents[file_id] = content
 
81
                    if kind == 'directory':
 
82
                        to_add_directories.append((path, file_id))
 
83
                    else:
 
84
                        to_add_files.append(path)
 
85
                        to_add_file_ids.append(file_id)
 
86
                        to_add_kinds.append(kind)
 
87
                        if content is not None:
 
88
                            new_contents[file_id] = content
81
89
                elif action == 'modify':
82
90
                    file_id, content = info
83
91
                    new_contents[file_id] = content
87
95
                    raise errors.UnknownBuildAction(action)
88
96
            if to_unversion_ids:
89
97
                tree.unversion(to_unversion_ids)
90
 
            tree.add(to_add_paths, to_add_file_ids, to_add_kinds)
 
98
            for path, file_id in to_add_directories:
 
99
                if path == '':
 
100
                    # Special case, because the path already exists
 
101
                    tree.add([path], [file_id], ['directory'])
 
102
                else:
 
103
                    tree.mkdir(path, file_id)
 
104
            tree.add(to_add_files, to_add_file_ids, to_add_kinds)
91
105
            for file_id, content in new_contents.iteritems():
92
106
                tree.put_file_bytes_non_atomic(file_id, content)
93
107