/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/plugins/fastimport/cache_manager.py

  • Committer: Martin
  • Date: 2017-06-05 20:48:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6658.
  • Revision ID: gzlist@googlemail.com-20170605204831-20accykspjcrx0a8
Apply 2to3 dict fixer and clean up resulting mess using view helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
    def finalize(self):
53
53
        if self.disk_blobs is not None:
54
 
            for info in self.disk_blobs.itervalues():
 
54
            for info in self.disk_blobs.values():
55
55
                if info[-1] is not None:
56
56
                    os.unlink(info[-1])
57
57
            self.disk_blobs = None
145
145
        #self._show_stats_for(self._blobs, "other blobs", note=note)
146
146
        #self.reftracker.dump_stats(note=note)
147
147
 
148
 
    def _show_stats_for(self, dict, label, note=trace.note, tuple_key=False):
 
148
    def _show_stats_for(self, a_dict, label, note, tuple_key=False):
149
149
        """Dump statistics about a given dictionary.
150
150
 
151
151
        By the key and value need to support len().
152
152
        """
153
 
        count = len(dict)
 
153
        count = len(a_dict)
154
154
        if tuple_key:
155
 
            size = sum(map(len, (''.join(k) for k in dict.keys())))
 
155
            size = sum(map(len, (''.join(k) for k in a_dict)))
156
156
        else:
157
 
            size = sum(map(len, dict.keys()))
158
 
        size += sum(map(len, dict.values()))
 
157
            size = sum(map(len, a_dict))
 
158
        size += sum(map(len, a_dict.values()))
159
159
        size = size * 1.0 / 1024
160
160
        unit = 'K'
161
161
        if size > 1024:
176
176
        self.inventories.clear()
177
177
 
178
178
    def _flush_blobs_to_disk(self):
179
 
        blobs = self._sticky_blobs.keys()
 
179
        blobs = list(self._sticky_blobs)
180
180
        sticky_blobs = self._sticky_blobs
181
181
        total_blobs = len(sticky_blobs)
182
182
        blobs.sort(key=lambda k:len(sticky_blobs[k]))
275
275
        if self._decref(id, self._sticky_blobs, None):
276
276
            self._sticky_memory_bytes -= len(content)
277
277
        return content
278
 
 
279
 
 
280
 
def invert_dictset(d):
281
 
    """Invert a dictionary with keys matching a set of values, turned into lists."""
282
 
    # Based on recipe from ASPN
283
 
    result = {}
284
 
    for k, c in d.iteritems():
285
 
        for v in c:
286
 
            keys = result.setdefault(v, [])
287
 
            keys.append(k)
288
 
    return result
289
 
 
290