/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 breezy/rename_map.py

  • Committer: Martin
  • Date: 2017-11-19 20:33:06 UTC
  • mto: This revision was merged to the branch mainline in revision 6821.
  • Revision ID: gzlist@googlemail.com-20171119203306-lm94zmwsggx4dt3z
Create a cross compatible lsprof main()

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
 
from cStringIO import StringIO
19
 
 
20
 
from bzrlib import (
 
17
from __future__ import absolute_import
 
18
 
 
19
 
 
20
from . import (
21
21
    osutils,
22
22
    progress,
23
23
    trace,
24
 
)
25
 
from bzrlib.ui import ui_factory
26
 
 
 
24
    )
 
25
from .i18n import gettext
 
26
from .sixish import (
 
27
    BytesIO,
 
28
    viewitems,
 
29
    )
 
30
from .ui import ui_factory
27
31
 
28
32
class RenameMap(object):
29
33
    """Determine a mapping of renames."""
65
69
        try:
66
70
            for num, (file_id, contents) in enumerate(
67
71
                tree.iter_files_bytes(desired_files)):
68
 
                task.update('Calculating hashes', num, len(file_ids))
69
 
                s = StringIO()
 
72
                task.update(gettext('Calculating hashes'), num, len(file_ids))
 
73
                s = BytesIO()
70
74
                s.writelines(contents)
71
75
                s.seek(0)
72
76
                self.add_edge_hashes(s.readlines(), file_id)
103
107
        task = ui_factory.nested_progress_bar()
104
108
        try:
105
109
            for num, path in enumerate(paths):
106
 
                task.update('Determining hash hits', num, len(paths))
 
110
                task.update(gettext('Determining hash hits'), num, len(paths))
107
111
                hits = self.hitcounts(self.tree.get_file_lines(None,
108
112
                                                               path=path))
109
 
                all_hits.extend((v, path, k) for k, v in hits.items())
 
113
                all_hits.extend((v, path, k) for k, v in viewitems(hits))
110
114
        finally:
111
115
            task.finished()
112
116
        return all_hits
147
151
                    break
148
152
                required_parents.setdefault(path, []).append(child)
149
153
        require_ids = {}
150
 
        for parent, children in required_parents.iteritems():
 
154
        for parent, children in viewitems(required_parents):
151
155
            child_file_ids = set()
152
156
            for child in children:
153
157
                file_id = matches.get(child)
164
168
        parent directories.
165
169
        """
166
170
        all_hits = []
167
 
        for file_id, file_id_children in missing_parents.iteritems():
168
 
            for path, path_children in required_parents.iteritems():
 
171
        for file_id, file_id_children in viewitems(missing_parents):
 
172
            for path, path_children in viewitems(required_parents):
169
173
                hits = len(path_children.intersection(file_id_children))
170
174
                if hits > 0:
171
175
                    all_hits.append((hits, path, file_id))
182
186
            for (file_id, paths, changed_content, versioned, parent, name,
183
187
                 kind, executable) in iterator:
184
188
                if kind[1] is None and versioned[1]:
185
 
                    missing_parents.setdefault(parent[0], set()).add(file_id)
 
189
                    if not self.tree.has_filename(self.tree.id2path(parent[0])):
 
190
                        missing_parents.setdefault(parent[0], set()).add(file_id)
186
191
                    if kind[0] == 'file':
187
192
                        missing_files.add(file_id)
188
193
                    else:
238
243
            pp.next_phase()
239
244
            delta = rn._make_inventory_delta(matches)
240
245
            for old, new, file_id, entry in delta:
241
 
                trace.note("%s => %s", old, new)
 
246
                trace.note( gettext("{0} => {1}").format(old, new) )
242
247
            if not dry_run:
243
248
                tree.add(required_parents)
244
249
                tree.apply_inventory_delta(delta)
247
252
 
248
253
    def _make_inventory_delta(self, matches):
249
254
        delta = []
250
 
        file_id_matches = dict((f, p) for p, f in matches.items())
251
 
        for old_path, entry in self.tree.iter_entries_by_dir(matches.values()):
 
255
        file_id_matches = dict((f, p) for p, f in viewitems(matches))
 
256
        for old_path, entry in self.tree.iter_entries_by_dir(file_id_matches):
252
257
            new_path = file_id_matches[entry.file_id]
253
258
            parent_path, new_name = osutils.split(new_path)
254
259
            parent_id = matches.get(parent_path)
255
260
            if parent_id is None:
256
261
                parent_id = self.tree.path2id(parent_path)
 
262
                if parent_id is None:
 
263
                    added, ignored = self.tree.smart_add([parent_path], recurse=False)
 
264
                    if len(ignored) > 0 and ignored[0] == parent_path:
 
265
                        continue
 
266
                    else:
 
267
                        parent_id = self.tree.path2id(parent_path)
257
268
            if entry.name == new_name and entry.parent_id == parent_id:
258
269
                continue
259
270
            new_entry = entry.copy()