Skip to content

Commit cd77a49

Browse files
committedDec 29, 2023
Add enum RevSpecFlag
1 parent ee7252f commit cd77a49

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed
 

‎docs/revparse.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ You can use any of the fancy `<rev>` forms supported by libgit2::
1616

1717
Constants:
1818

19-
.. py:data:: GIT_REVPARSE_SINGLE
20-
.. py:data:: GIT_REVPARSE_RANGE
21-
.. py:data:: GIT_REVPARSE_MERGE_BASE
19+
.. py:data:: pygit2.enums.RevSpecFlag.SINGLE
20+
.. py:data:: pygit2.enums.RevSpecFlag.RANGE
21+
.. py:data:: pygit2.enums.RevSpecFlag.MERGE_BASE

‎pygit2/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
RepositoryOpenFlag,
7070
RepositoryState,
7171
ResetMode,
72+
RevSpecFlag,
7273
StashApplyProgress,
7374
FileStatus,
7475
SubmoduleIgnore,

‎pygit2/_pygit2.pyi

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ GIT_OID_HEXSZ: int
2222
GIT_OID_HEX_ZERO: str
2323
GIT_OID_MINPREFIXLEN: int
2424
GIT_OID_RAWSZ: int
25-
GIT_REVPARSE_MERGE_BASE: int
26-
GIT_REVPARSE_RANGE: int
27-
GIT_REVPARSE_SINGLE: int
2825
LIBGIT2_VERSION: str
2926
LIBGIT2_VER_MAJOR: int
3027
LIBGIT2_VER_MINOR: int

‎pygit2/enums.py

+16
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,22 @@ class ResetMode(IntEnum):
987987
"MIXED plus changes in working tree discarded"
988988

989989

990+
class RevSpecFlag(IntFlag):
991+
"""
992+
Revparse flags.
993+
These indicate the intended behavior of the spec passed to Repository.revparse()
994+
"""
995+
996+
SINGLE = _pygit2.GIT_REVSPEC_SINGLE
997+
"The spec targeted a single object."
998+
999+
RANGE = _pygit2.GIT_REVSPEC_RANGE
1000+
"The spec targeted a range of commits."
1001+
1002+
MERGE_BASE = _pygit2.GIT_REVSPEC_MERGE_BASE
1003+
"The spec used the '...' operator, which invokes special semantics."
1004+
1005+
9901006
class SortMode(IntFlag):
9911007
"""
9921008
Flags to specify the sorting which a revwalk should perform.

‎src/pygit2.c

+4
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ PyInit__pygit2(void)
551551
*/
552552
INIT_TYPE(RevSpecType, NULL, NULL)
553553
ADD_TYPE(m, RevSpec)
554+
ADD_CONSTANT_INT(m, GIT_REVSPEC_SINGLE)
555+
ADD_CONSTANT_INT(m, GIT_REVSPEC_RANGE)
556+
ADD_CONSTANT_INT(m, GIT_REVSPEC_MERGE_BASE)
557+
/* Deprecated enums */
554558
ADD_CONSTANT_INT(m, GIT_REVPARSE_SINGLE)
555559
ADD_CONSTANT_INT(m, GIT_REVPARSE_RANGE)
556560
ADD_CONSTANT_INT(m, GIT_REVPARSE_MERGE_BASE)

‎src/revspec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ RevSpec_to_object__get__(RevSpec *self)
8484
}
8585

8686
PyDoc_STRVAR(RevSpec_flags__doc__,
87-
"A combination of GIT_REVPARSE_* flags which indicate the\n"
87+
"A combination of enums.RevSpecFlag constants indicating the\n"
8888
"intended behavior of the spec passed to Repository.revparse()");
8989

9090
PyObject *

‎test/test_revparse.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
"""Tests for revision parsing."""
2727

28-
from pygit2 import GIT_REVPARSE_SINGLE, GIT_REVPARSE_RANGE, GIT_REVPARSE_MERGE_BASE, InvalidSpecError
28+
from pygit2 import RevSpecFlag, InvalidSpecError
2929
from pytest import raises
3030

3131
HEAD_SHA = '2be5719152d4f82c7302b1c0932d8e5f0a4a0e98'
@@ -61,21 +61,21 @@ def test_revparse_1(testrepo):
6161
s = testrepo.revparse('master')
6262
assert s.from_object.hex == HEAD_SHA
6363
assert s.to_object is None
64-
assert s.flags == GIT_REVPARSE_SINGLE
64+
assert s.flags == RevSpecFlag.SINGLE
6565

6666

6767
def test_revparse_range_1(testrepo):
6868
s = testrepo.revparse('HEAD^1..acecd5e')
6969
assert s.from_object.hex == PARENT_SHA
7070
assert s.to_object.hex.startswith('acecd5e')
71-
assert s.flags == GIT_REVPARSE_RANGE
71+
assert s.flags == RevSpecFlag.RANGE
7272

7373

7474
def test_revparse_range_2(testrepo):
7575
s = testrepo.revparse('HEAD...i18n')
7676
assert s.from_object.hex.startswith('2be5719')
7777
assert s.to_object.hex.startswith('5470a67')
78-
assert s.flags == GIT_REVPARSE_RANGE | GIT_REVPARSE_MERGE_BASE
78+
assert s.flags == RevSpecFlag.RANGE | RevSpecFlag.MERGE_BASE
7979
assert testrepo.merge_base(s.from_object.id, s.to_object.id) is not None
8080

8181

0 commit comments

Comments
 (0)