Skip to content

Commit

Permalink
Remove some deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavid committed Mar 24, 2024
1 parent c7c65cf commit 9bdbfe6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 162 deletions.
35 changes: 26 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
- Fix tests on EPEL8 builds for s390x
[#1283](https://github.com/libgit2/pygit2/pull/1283)

Breaking changes:

- Remove deprecated `Repository.add_submodule(...)`, use `Repository.submodules.add(...)`
- Remove deprecated `Repository.lookup_submodule(...)`, use `Repository.submodules[...]`
- Remove deprecated `Repository.init_submodules(...)`, use `Repository.submodules.init(...)`
- Remove deprecated `Repository.update_submodule(...)`, use `Repository.submodules.update(...)`

- Remove deprecated support for passing dicts to repository\'s `merge(...)`,
`merge_commits(...)` and `merge_trees(...)`. Instead pass `MergeFlag` for `flags`, and
`MergeFileFlag` for `file_flags`.

- Remove deprecated support for passing a string for the favor argument to repository\'s
`merge(...)`, `merge_commits(...)` and `merge_trees(...)`. Instead pass `MergeFavor`.


# 1.14.1 (2024-02-10)

Expand Down Expand Up @@ -66,15 +80,18 @@ Breaking changes:

Deprecations:

- Deprecate `Repository.add_submodule(...)`, use `Repository.submodules.add(...)`
- Deprecate `Repository.lookup_submodule(...)`, use `Repository.submodules[...]`
- Deprecate `Repository.init_submodules(...)`, use `Repository.submodules.init(...)`
- Deprecate `Repository.update_submodule(...)`, use `Repository.submodules.update(...)`
- Deprecate `GIT_*` constants, use `pygit2.enums`
- Passign dicts to repository\'s `merge(...)`, `merge_commits(...)`
and `merge_trees(...)` is deprecated. Instead pass `MergeFavor` for
the `favor` argument, `MergeFlag` for `flags`, and `MergeFileFlag`
for `file_flags`.
- Deprecate `Repository.add_submodule(...)`, use `Repository.submodules.add(...)`
- Deprecate `Repository.lookup_submodule(...)`, use `Repository.submodules[...]`
- Deprecate `Repository.init_submodules(...)`, use `Repository.submodules.init(...)`
- Deprecate `Repository.update_submodule(...)`, use `Repository.submodules.update(...)`
- Deprecate `GIT_*` constants, use `pygit2.enums`

- Passing dicts to repository\'s `merge(...)`, `merge_commits(...)` and `merge_trees(...)`
is deprecated. Instead pass `MergeFlag` for the `flags` argument, and `MergeFileFlag` for
`file_flags`.

- Passing a string for the favor argument to repository\'s `merge(...)`, `merge_commits(...)`
and `merge_trees(...)` is deprecated. Instead pass `MergeFavor`.

# 1.13.3 (2023-11-21)

Expand Down
11 changes: 8 additions & 3 deletions docs/submodule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ A submodule is a foreign repository that is embedded within a
dedicated subdirectory of the repositories tree.

.. autoclass:: pygit2.Repository
:members: add_submodule, init_submodules, listall_submodules,
lookup_submodule, update_submodules
:members: listall_submodules

:noindex:
.. py:attribute:: Repository.submodules
The collection of submodules, an instance of
:py:class:`pygit2.submodules.SubmoduleCollection`

.. autoclass:: pygit2.submodules.SubmoduleCollection
:members:


The Submodule type
Expand Down
29 changes: 0 additions & 29 deletions pygit2/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,32 +1309,3 @@ class SubmoduleStatus(IntFlag):

WD_UNTRACKED = _pygit2.GIT_SUBMODULE_STATUS_WD_UNTRACKED
'submodule workdir contains untracked files (flag available if ignore is NONE)'


def _deprecated_flag_dict_to_intflag(flag_dict, default_value):
"""
Convert a dict eg {"find_renames": True, "skip_reuc": True} to an IntFlag.
"""

enum_type = type(default_value)
assert issubclass(enum_type, IntFlag)

value = default_value

for k, v in flag_dict.items():
k = k.upper()

try:
f = enum_type[k]
except KeyError:
try:
f = enum_type['_DEPRECATED_' + k]
except KeyError:
raise ValueError(f'unknown {enum_type.__name__}: {k}')

if v:
value |= f
else:
value &= ~f

return value
39 changes: 1 addition & 38 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
MergeFlag,
RepositoryOpenFlag,
RepositoryState,
_deprecated_flag_dict_to_intflag,
)
from .errors import check_error
from .ffi import ffi, C
Expand Down Expand Up @@ -134,26 +133,6 @@ def pack_all_objects(pack_builder):
def __iter__(self):
return iter(self.odb)

#
# Submodules
#

def add_submodule(self, *args, **kwargs):
warnings.warn('Use repo.submodules.add(...)', DeprecationWarning)
return self.submodules.add(*args, **kwargs)

def lookup_submodule(self, path: str) -> Submodule:
warnings.warn('Use repo.submodules[...]', DeprecationWarning)
return self.submodules[path]

def init_submodules(self, *args, **kwargs):
warnings.warn('Use repo.submodules.init(...)', DeprecationWarning)
return self.submodules.init(*args, **kwargs)

def update_submodules(self, *args, **kwargs):
warnings.warn('Use repo.submodules.update(...)', DeprecationWarning)
return self.submodules.update(*args, **kwargs)

#
# Mapping interface
#
Expand Down Expand Up @@ -624,29 +603,13 @@ def index(self):
def _merge_options(favor: MergeFavor, flags: MergeFlag, file_flags: MergeFileFlag):
"""Return a 'git_merge_opts *'"""

# Parse deprecated favor value (str)
if isinstance(favor, str):
try:
favor = MergeFavor[favor.upper()]
except KeyError:
raise ValueError(f'unknown favor: {favor}')
warnings.warn('Use pygit2.enums.MergeFavor', DeprecationWarning)
# Check arguments type
if not isinstance(favor, (int, MergeFavor)):
raise TypeError('favor argument must be MergeFavor')

# Parse deprecated flags value (dict[str, bool])
if isinstance(flags, dict):
flags = _deprecated_flag_dict_to_intflag(flags, MergeFlag.FIND_RENAMES)
warnings.warn('Use pygit2.enums.MergeFlag', DeprecationWarning)
if not isinstance(flags, (int, MergeFlag)):
raise TypeError('flags argument must be MergeFlag')

# Parse deprecated file_flags value (dict[str, bool])
if isinstance(file_flags, dict):
file_flags = _deprecated_flag_dict_to_intflag(
file_flags, MergeFileFlag.DEFAULT
)
warnings.warn('Use pygit2.enums.MergeFileFlag', DeprecationWarning)
if not isinstance(file_flags, (int, MergeFileFlag)):
raise TypeError('file_flags argument must be MergeFileFlag')

Expand Down
119 changes: 36 additions & 83 deletions test/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,6 @@ def test_merge_favor(mergerepo, favor):
assert mergerepo.index.conflicts is None


@pytest.mark.parametrize(
'favor',
[
'ours',
'theirs',
'union',
],
)
def test_merge_favor_deprecated_names(mergerepo, favor):
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'
with pytest.warns(DeprecationWarning):
mergerepo.merge(branch_head_hex, favor=favor)

assert mergerepo.index.conflicts is None


def test_merge_fail_on_conflict(mergerepo):
branch_head_hex = '1b2bae55ac95a4be3f8983b86cd579226d0eb247'

Expand All @@ -188,10 +172,6 @@ def test_merge_fail_on_conflict(mergerepo):
branch_head_hex, flags=MergeFlag.FIND_RENAMES | MergeFlag.FAIL_ON_CONFLICT
)

# Deprecated flags dict
with pytest.warns(DeprecationWarning), pytest.raises(pygit2.GitError):
mergerepo.merge(branch_head_hex, flags={'fail_on_conflict': True})


def test_merge_commits(mergerepo):
branch_head_hex = '03490f16b15a09913edb3a067a3dc67fbb8d41f1'
Expand All @@ -217,15 +197,8 @@ def test_merge_commits_favor(mergerepo):
)
assert merge_index.conflicts is None

# Deprecated favor value
with pytest.warns(DeprecationWarning):
merge_index = mergerepo.merge_commits(
mergerepo.head.target, branch_head_hex, favor='ours'
)
assert merge_index.conflicts is None

# Incorrect favor value
with pytest.raises(ValueError):
with pytest.raises(TypeError):
mergerepo.merge_commits(mergerepo.head.target, branch_head_hex, favor='foo')


Expand Down Expand Up @@ -256,66 +229,46 @@ def test_merge_trees_favor(mergerepo):
)
assert merge_index.conflicts is None

with pytest.raises(ValueError):
with pytest.raises(TypeError):
mergerepo.merge_trees(
ancestor_id, mergerepo.head.target, branch_head_hex, favor='foo'
)


def test_merge_options_deprecated_names():
with pytest.warns(DeprecationWarning):
favor = MergeFavor.OURS
flags = MergeFlag.FIND_RENAMES | MergeFlag.FAIL_ON_CONFLICT
file_flags = MergeFileFlag.IGNORE_WHITESPACE | MergeFileFlag.DIFF_PATIENCE
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
o2 = pygit2.Repository._merge_options(
favor='ours',
flags={'fail_on_conflict': True},
file_flags={'ignore_whitespace': True, 'patience': True},
)
assert favor == o1.file_favor == o2.file_favor
assert flags == o1.flags == o2.flags
assert file_flags == o1.file_flags == o2.file_flags

favor = MergeFavor.THEIRS
flags = 0
file_flags = 0
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
o2 = pygit2.Repository._merge_options(
favor='theirs',
flags={'find_renames': False},
file_flags={'ignore_whitespace': False},
)
assert favor == o1.file_favor == o2.file_favor
assert flags == o1.flags == o2.flags
assert file_flags == o1.file_flags == o2.file_flags

favor = MergeFavor.UNION
flags = MergeFlag.FIND_RENAMES | MergeFlag.NO_RECURSIVE
file_flags = (
MergeFileFlag.STYLE_DIFF3
| MergeFileFlag.IGNORE_WHITESPACE
| MergeFileFlag.DIFF_PATIENCE
)
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
o2 = pygit2.Repository._merge_options(
favor='union',
flags={'find_renames': True, 'no_recursive': True},
file_flags={
'diff3_style': True,
'ignore_whitespace': True,
'patience': True,
},
)
assert favor == o1.file_favor == o2.file_favor
assert flags == o1.flags == o2.flags
assert file_flags == o1.file_flags == o2.file_flags
def test_merge_options():
favor = MergeFavor.OURS
flags = MergeFlag.FIND_RENAMES | MergeFlag.FAIL_ON_CONFLICT
file_flags = MergeFileFlag.IGNORE_WHITESPACE | MergeFileFlag.DIFF_PATIENCE
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
assert favor == o1.file_favor
assert flags == o1.flags
assert file_flags == o1.file_flags

favor = MergeFavor.THEIRS
flags = 0
file_flags = 0
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
assert favor == o1.file_favor
assert flags == o1.flags
assert file_flags == o1.file_flags

favor = MergeFavor.UNION
flags = MergeFlag.FIND_RENAMES | MergeFlag.NO_RECURSIVE
file_flags = (
MergeFileFlag.STYLE_DIFF3
| MergeFileFlag.IGNORE_WHITESPACE
| MergeFileFlag.DIFF_PATIENCE
)
o1 = pygit2.Repository._merge_options(
favor=favor, flags=flags, file_flags=file_flags
)
assert favor == o1.file_favor
assert flags == o1.flags
assert file_flags == o1.file_flags


def test_merge_many(mergerepo):
Expand Down

0 comments on commit 9bdbfe6

Please sign in to comment.