detached
     ˆÃÂÆ570ÁÅÄ :    ‹      Õ–ßoÚ0ÇßûWx~ØPº‡ÖdêÒÐZ@”iš¦	™Ø‹ÄŽìK3ö×Ï!™ h?´MÊSÎ—oîîsv’c/Âépñq6"o÷wdöþÍÝxHhàÃå \„Õ�~»ÓM(¡1bvPE»¸l»�ÅbL“>8´*Â¶@AƒVú‚ÂbÉ…¿†
Œµ�_ˆY09:%d2k"ÀØzaËÉdÖ·s%Ü9P:ËR“;ÙƒÌÒ2¨‚ùðPÇg+#veÚîßJá#íËæ«}¦Ò´Ã˜<òDmô€¢ÉhÀTº!ÎF
*2ÚÁ*ázÛÞ¨5%<Áý4N?{�O_>0N|ë}=Ln¦ƒ�žJü´æÞknipÇ’ÔµVRœ?Tâõõ|À°Ò„ÒEVe¨Œ>HÁ#£F&q÷¬Wž ¶ÇªJ"~Ö=iÆìv>š,Âñ¼j‰(CªûÃ£ÁŒ[©‘„ÊÊ�ÝÕDUø—zå²›ïKR×kÕ&FÒ"'•¿™ë­6…>æô=<IÈÝNG4Ø_Ž‹|VU¯Ó{Õêv[½éu®»W„œú7óÝÿ,?Gãr—I-–B&|·L�§9ám œ×£5	j£�6×¨R¹äªG¹Ü*á·ç„³ùh¥ýZi7Mêò_#Xµ£ÁH9æGg°Z7¨úÎIñì>õ70w|sÄµ_þ{œ_œ9 žÆìÇ=Õ”ùp“¯�È
    7   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þDü²,Ü¢#á�a	HçÈ„iÿÇÀÆÅ )ý    # Copyright (C) 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from io import BytesIO

from . import (
    osutils,
    progress,
    trace,
    )
from .i18n import gettext
from .ui import ui_factory


class RenameMap:
    """Determine a mapping of renames."""

    def __init__(self, tree):
        self.tree = tree
        self.edge_hashes = {}

    @staticmethod
    def iter_edge_hashes(lines):
        """Iterate through the hashes of line pairs (which make up an edge).

        The hash is truncated using a modulus to avoid excessive memory
        consumption by the hitscount dict.  A modulus of 10Mi means that the
        maximum number of keys is 10Mi.  (Keys are normally 32 bits, e.g.
        4 Gi)
        """
        modulus = 1024 * 1024 * 10
        for n in range(len(lines)):
            yield hash(tuple(lines[n:n + 2])) % modulus

    def add_edge_hashes(self, lines, tag):
        """Update edge_hashes to include the given lines.

        :param lines: The lines to update the hashes for.
        :param tag: A tag uniquely associated with these lines (i.e. file-id)
        """
        for my_hash in self.iter_edge_hashes(lines):
            self.edge_hashes.setdefault(my_hash, set()).add(tag)

    def add_file_edge_hashes(self, tree, file_ids):
        """Update to reflect the hashes for files in the tree.

        :param tree: The tree containing the files.
        :param file_ids: A list of file_ids to perform the updates for.
        """
        desired_files = [(tree.id2path(f), f) for f in file_ids]
        with ui_factory.nested_progress_bar() as task:
            for num, (file_id, contents) in enumerate(
                    tree.iter_files_bytes(desired_files)):
                task.update(gettext('Calculating hashes'), num, len(file_ids))
                s = BytesIO()
                s.writelines(contents)
                s.seek(0)
                self.add_edge_hashes(s.readlines(), file_id)

    def hitcounts(self, lines):
        """Count the number of hash hits for each tag, for the given lines.

        Hits are weighted according to the number of tags the hash is
        associated with; more tags means that the hash is less rare and should
        tend to be ignored.
        :param lines: The lines to calculate hashes of.
        :return: a dict of {tag: hitcount}
        """
        hits = {}
        for my_hash in self.iter_edge_hashes(lines):
            tags = self.edge_hashes.get(my_hash)
            if tags is None:
                continue
            taglen = len(tags)
            for tag in tags:
                if tag not in hits:
                    hits[tag] = 0
                hits[tag] += 1.0 / taglen
        return hits

    def get_all_hits(self,