Skip to content
Snippets Groups Projects
Commit a3d8f1eb authored by Georges Racinet's avatar Georges Racinet
Browse files

dulwich: backporting fix for bytes problem in alternates

Sub-classing Dulwich whole testcase brings in all the tests
from that class, but we don't care: they pass in less than a
second.

Given the release rate of dulwich, a new version should be
available soon, but we haven't tested anything from 0.20.5.
It doesn't look like the best time to update. In any case
the backport gives us more options.

Closes heptapod#370
parent a262a8ad
No related branches found
No related tags found
1 merge request!38dulwich: backporting fix for bytes problem in alternates
Pipeline #13434 failed
# Python package
from . import patch # noqa: F401
# Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import dulwich
from dulwich.object_store import (
DiskObjectStore,
INFODIR,
GitFile,
)
# backport from dulwich commits:
# 06b65c3c2aef57939143e33d404f9883ec286597
# 544e90f8cbce1282ecb3d8ff73b5d7ecae905601
#
# see also https://github.com/dulwich/dulwich/pull/815 and heptapod#370
def _read_alternate_paths(self):
try:
f = GitFile(os.path.join(self.path, INFODIR, "alternates"), 'rb')
except FileNotFoundError:
return
with f:
for line in f.readlines():
line = line.rstrip(b"\n")
if line.startswith(b"#"):
continue
if os.path.isabs(line):
yield os.fsdecode(line)
else:
yield os.fsdecode(os.path.join(os.fsencode(self.path),
line))
if dulwich.__version__ < (0, 20, 14):
# our tests will run immediately on the dulwich with the fix,
# only coverage telling us it's time to remove the unneeded patch
DiskObjectStore._read_alternate_paths = _read_alternate_paths
# Copyright 2019-2020 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
from dulwich.tests.test_object_store import (
DiskObjectStore,
DiskObjectStoreTests,
)
class AlternatePathsTests(DiskObjectStoreTests):
def test_read_alternate_paths(self):
store = DiskObjectStore(self.store_dir)
abs_path = os.path.abspath(os.path.normpath('/abspath'))
# ensures in particular existence of the alternates file
store.add_alternate_path(abs_path)
self.assertEqual(set(store._read_alternate_paths()), {abs_path})
store.add_alternate_path("relative-path")
self.assertIn(os.path.join(store.path, "relative-path"),
set(store._read_alternate_paths()))
# arguably, add_alternate_path() could strip comments.
# Meanwhile it's more convenient to use it than to import INFODIR
store.add_alternate_path("# comment")
for alt_path in store._read_alternate_paths():
self.assertNotIn("#", alt_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment