The constructor is for internal use only.
| 32 | |
| 33 | |
| 34 | class Refspec: |
| 35 | """The constructor is for internal use only.""" |
| 36 | |
| 37 | def __init__(self, owner, ptr) -> None: |
| 38 | self._owner = owner |
| 39 | self._refspec = ptr |
| 40 | |
| 41 | @property |
| 42 | def src(self) -> str: |
| 43 | """Source or lhs of the refspec""" |
| 44 | return ffi.string(C.git_refspec_src(self._refspec)).decode('utf-8') |
| 45 | |
| 46 | @property |
| 47 | def dst(self) -> str: |
| 48 | """Destination or rhs of the refspec""" |
| 49 | return ffi.string(C.git_refspec_dst(self._refspec)).decode('utf-8') |
| 50 | |
| 51 | @property |
| 52 | def force(self) -> bool: |
| 53 | """Whether this refspeca llows non-fast-forward updates""" |
| 54 | return bool(C.git_refspec_force(self._refspec)) |
| 55 | |
| 56 | @property |
| 57 | def string(self) -> str: |
| 58 | """String which was used to create this refspec""" |
| 59 | return ffi.string(C.git_refspec_string(self._refspec)).decode('utf-8') |
| 60 | |
| 61 | @property |
| 62 | def direction(self): |
| 63 | """Direction of this refspec (fetch or push)""" |
| 64 | return C.git_refspec_direction(self._refspec) |
| 65 | |
| 66 | def src_matches(self, ref: str) -> bool: |
| 67 | """Return True if the given string matches the source of this refspec, |
| 68 | False otherwise. |
| 69 | """ |
| 70 | return bool(C.git_refspec_src_matches(self._refspec, to_bytes(ref))) |
| 71 | |
| 72 | def dst_matches(self, ref: str) -> bool: |
| 73 | """Return True if the given string matches the destination of this |
| 74 | refspec, False otherwise.""" |
| 75 | return bool(C.git_refspec_dst_matches(self._refspec, to_bytes(ref))) |
| 76 | |
| 77 | def _transform(self, ref: str, fn: Callable) -> str: |
| 78 | buf = ffi.new('git_buf *', (ffi.NULL, 0)) |
| 79 | err = fn(buf, self._refspec, to_bytes(ref)) |
| 80 | check_error(err) |
| 81 | |
| 82 | try: |
| 83 | return ffi.string(buf.ptr).decode('utf-8') |
| 84 | finally: |
| 85 | C.git_buf_dispose(buf) |
| 86 | |
| 87 | def transform(self, ref: str) -> str: |
| 88 | """Transform a reference name according to this refspec from the lhs to |
| 89 | the rhs. Return an string. |
| 90 | """ |
| 91 | return self._transform(ref, C.git_refspec_transform) |
no outgoing calls
no test coverage detected
searching dependent graphs…