0
  L   ˆl–ß=¿Jõ4Ÿº‚ œP.\·˜´o�þB g Ùm–HW\óÇƒh¹Æa–Ãa¾”Ò~êq@³q°Üeõ1hßÅ      00000071
  7   	ˆl–Ãa¾”Ò~êq@³q°Üeõ1hß‘äÇò 8à#mèÂ2=#_ÏÉƒh¹È¿Æ      	0
  C   ˆl–ßi~”d*eJe@=q°Üe•1hß�þ[+¢Y¹Yz7@Ó • ?Ê„AuïÉ_ŠI|¥�+Wé3ž¯ÁÈ ?÷     # test_client.py -- Compatibility tests for git client.
# Copyright (C) 2010 Google, Inc.
#
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
# General Public License as public by the Free Software Foundation; version 2.0
# or (at your option) any later version. You can redistribute it and/or
# modify it under the terms of either of these two licenses.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# You should have received a copy of the licenses; if not, see
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
# License, Version 2.0.
#

"""Compatibility tests between the Dulwich client and the cgit server."""

import copy
from io import BytesIO
import os
import select
import signal
import stat
import subprocess
import sys
import tarfile
import tempfile
import threading

from urllib.parse import unquote

import http.server

from dulwich import (
    client,
    file,
    index,
    protocol,
    objects,
    repo,
)
from dulwich.tests import (
    SkipTest,
    expectedFailure,
)
from dulwich.tests.compat.utils import (
    CompatTestCase,
    check_for_daemon,
    import_repo_to_dir,
    rmtree_ro,
    run_git_or_fail,
    _DEFAULT_GIT,
)


if sys.platform == "win32":
    import ctypes


class DulwichClientTestBase:
    """Tests for client/server compatibility."""

    def setUp(self):
        self.gitroot = os.path.dirname(
            import_repo_to_dir("server_new.export").rstrip(os.sep)
        )
        self.dest = os.path.join(self.gitroot, "dest")
        file.ensure_dir_exists(self.dest)
        run_git_or_fail(["init", "--quiet", "--bare"], cwd=self.dest)

    def tearDown(self):
        rmtree_ro(self.gitroot)

    def assertDestEqualsSrc(self):
        repo_dir = os.path.join(self.gitroot, "server_new.export")
        dest_repo_dir = os.path.join(self.gitroot, "dest")
        with repo.Repo(repo_dir) as src:
            with repo.Repo(dest_repo_dir) as dest:
                self.assertReposEqual(src, dest)

    def _client(self):
        raise NotImplementedError()

    def _build_path(self):
        raise NotImplementedError()

    def _do_send_pack(self):
        c = self._client()
        srcpath = os.path.join(self.gitroot, "server_new.export")
        with repo.Repo(srcpath) as src:
            sendrefs = dict(src.get_refs())
            del sendrefs[b"HEAD"]
            c.send_pack(
                self._build_path("/dest"),
                lambda _: sendrefs,
                src.generate_pack_data,
            )

    def test_send_pack(self):
        self._do_send_pack()
        self.assertDestEqualsSrc()

    def test_send_pack_nothing_to_send(self):
        self._do_send_pack()
        self.assertDestEqualsSrc()
        # nothing to send, but shouldn't raise either.
        self._do_send_pack()

    @staticmethod
    def _add_file(repo, tree_id, filename, contents):
        tree = repo[tree_id]
        blob = objects.Blob()
        blob.data = contents.encode("utf-8")
        repo.object_store.add_object(blob)
        tree.add(filename.encode("utf-8"), stat.S_IFREG | 0o644, blob.id)
        repo.object_store.add_object(tree)
        return tree.id

    def test_send_pack_from_shallow_clone(self):
        c = self._client()
        server_new_path = os.path.join(self.gitroot, "server_new.export")
        run_git_or_fail(["config", "http.uploadpack", "true"], cwd=server_new_path)
        run_git_or_fail(["config", "http.receivepack", "true"], cwd=s