MAJOR=5
MINOR=0
DEVNAME=tty
DEVMODE=0666
  B   ˆl–äY>”JeJe@†à¸Û*bÑ¿�þZxaY¹BáYI#MùÍ„Í¾ÏÌ_ŠI|¥�+Wé3ž¯ÃË ?÷     # Copyright 2009-2010 Gregory P. Ward
# Copyright 2009-2010 Intelerad Medical Systems Incorporated
# Copyright 2010-2011 Fog Creek Software
# Copyright 2010-2011 Unity Technologies
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''setup for largefiles repositories: reposetup'''

import copy

from mercurial.i18n import _

from mercurial import (
    error,
    extensions,
    localrepo,
    match as matchmod,
    scmutil,
    util,
)

from mercurial.dirstateutils import timestamp

from . import (
    lfcommands,
    lfutil,
)


def reposetup(ui, repo):
    # wire repositories should be given new wireproto functions
    # by "proto.wirereposetup()" via "hg.wirepeersetupfuncs"
    if not repo.local():
        return

    class lfilesrepo(repo.__class__):
        # the mark to examine whether "repo" object enables largefiles or not
        _largefilesenabled = True

        lfstatus = False

        # When lfstatus is set, return a context that gives the names
        # of largefiles instead of their corresponding standins and
        # identifies the largefiles as always binary, regardless of
        # their actual contents.
        def __getitem__(self, changeid):
            ctx = super(lfilesrepo, self).__getitem__(changeid)
            if self.lfstatus:

                def files(orig):
                    filenames = orig()
                    return [lfutil.splitstandin(f) or f for f in filenames]

                extensions.wrapfunction(ctx, 'files', files)

                def manifest(orig):
                    man1 = orig()

                    class lfilesmanifest(man1.__class__):
                        def __contains__(self, filename):
                            orig = super(lfilesmanifest, self).__contains__
                            return orig(filename) or orig(
                                lfutil.standin(filename)
                            )

                    man1.__class__ = lfilesmanifest
                    return man1

                extensions.wrapfunction(ctx, 'manifest', manifest)

                def filectx(orig, path, fileid=None, filelog=None):
                    try:
                        if filelog is not None:
                            result = orig(path, fileid, filelog)
                        else:
                            result = orig(path, fileid)
                    except error.LookupError:
                        # Adding a null character will cause Mercurial to
                        # identify this as a binary file.
                        if filelog is not None:
                            result = orig(lfutil.standin(path), fileid, filelog)
                        else:
                            result = orig(lfutil.standin(path), fileid)
                        olddata = result.data
                        result.data = lambda: olddata() + b'\0'
                    return result

                extensions.wrapfunction(ctx, 'filectx', filectx)

            return ctx

        # Figure out the status of big files and insert them into the
        # appropriate list in the result. Also removes standin files
        # from the listing. Revert to the original status if
        # self.lfstatus is False.
        # XXX large file status is buggy when used on repo proxy.
        # XXX this needs to be investigated.
        @localrepo.unfilteredmethod
        def status(
            self,
            node1=b'.',
            node2=None,
            match=None,
            ignored=False,
            clean=False,
            unknown=False,
            listsubrepos=False,
        ):
            listignored, listclean, listunknown = ignored, clean, unknown
            orig = super(lfilesrepo, self).status
            if not self.lfstatus:
                return orig(
                    node1,
                    node2,
                    match,
             