| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
"""Exceptions for vcsgraph operations.""" |
| 18 |
|
| 19 |
|
| 20 |
class Error(Exception): |
| 21 |
"""Base class for vcsgraph exceptions.""" |
| 22 |
|
| 23 |
pass |
| 24 |
|
| 25 |
|
| 26 |
class UnsupportedOperation(Error): |
| 27 |
"""Requested operation is not supported.""" |
| 28 |
|
| 29 |
pass |
| 30 |
|
| 31 |
|
| 32 |
class GhostRevisionsHaveNoRevno(Error): |
| 33 |
"""When searching for revnos, we encounter a ghost.""" |
| 34 |
|
| 35 |
def __init__(self, revision_id, ghost_revision_id): |
| 36 |
"""Initialize GhostRevisionsHaveNoRevno exception. |
| 37 |
|
| 38 |
Args: |
| 39 |
revision_id: The revision ID being searched for. |
| 40 |
ghost_revision_id: The ghost revision ID encountered. |
| 41 |
""" |
| 42 |
self.revision_id = revision_id |
| 43 |
self.ghost_revision_id = ghost_revision_id |
| 44 |
super().__init__( |
| 45 |
f"Ghost revision {ghost_revision_id!r} has no revno, " |
| 46 |
f"cannot determine revno for {revision_id!r}" |
| 47 |
) |
| 48 |
|
| 49 |
def __eq__(self, other): |
| 50 |
"""Check equality with another GhostRevisionsHaveNoRevno instance. |
| 51 |
|
| 52 |
Args: |
| 53 |
other: Object to compare with. |
| 54 |
|
| 55 |
Returns: |
| 56 |
True if both instances have the same revision_id and ghost_revision_id. |
| 57 |
""" |
| 58 |
if not isinstance(other, GhostRevisionsHaveNoRevno): |
| 59 |
return False |
| 60 |
return ( |
| 61 |
self.revision_id == other.revision_id |
| 62 |
and self.ghost_revision_id == other.ghost_revision_id |
| 63 |
) |
| 64 |
|
| 65 |
|
| 66 |
class InvalidRevisionId(Error): |
| 67 |
"""Invalid revision ID.""" |
| 68 |
|
| 69 |
def __init__(self, revision_id, client): |
| 70 |
"""Initialize InvalidRevisionId exception. |
| 71 |
|
| 72 |
Args: |
| 73 |
revision_id: The invalid revision ID. |
| 74 |
client: The client that encountered the invalid revision. |
| 75 |
""" |
| 76 |
self.revision_id = revision_id |
| 77 |
self.client = client |
| 78 |
super().__init__(f"Invalid revision ID {revision_id!r}") |
| 79 |
|
| 80 |
def __eq__(self, other): |
| 81 |
"""Check equality with another InvalidRevisionId instance. |
| 82 |
|
| 83 |
Args: |
| 84 |
other: Object to compare with. |
| 85 |
|
| 86 |
Returns: |
| 87 |
True if both instances have the same revision_id and client. |
| 88 |
""" |
| 89 |
if not isinstance(other, InvalidRevisionId): |
| 90 |
return False |
| 91 |
return self.revision_id == other.revision_id and self.client == other.client |
| 92 |
|
| 93 |
|
| 94 |
class NoCommonAncestor(Error): |
| 95 |
"""No common ancestor found between revisions.""" |
| 96 |
|
| 97 |
def __init__(self, revision_a, revision_b): |
| 98 |
"""Initialize NoCommonAncestor exception. |
| 99 |
|
| 100 |
Args: |
| 101 |
revision_a: First revision ID. |
| 102 |
revision_b: Second revision ID. |
| 103 |
""" |
| 104 |
self.revision_a = revision_a |
| 105 |
self.revision_b = revision_b |
| 106 |
super().__init__( |
| 107 |
f"No common ancestor found between {revision_a!r} and {revision_b!r}" |
| 108 |
) |
| 109 |
|
| 110 |
def __eq__(self, other): |
| 111 |
"""Check equality with another NoCommonAncestor instance. |
| 112 |
|
| 113 |
Args: |
| 114 |
other: Object to compare with. |
| 115 |
|
| 116 |
Returns: |
| 117 |
True if both instances have the same revision_a and revision_b. |
| 118 |
""" |
| 119 |
if not isinstance(other, NoCommonAncestor): |
| 120 |
return False |
| 121 |
return ( |
| 122 |
self.revision_a == other.revision_a and self.revision_b == other.revision_b |
| 123 |
) |
| 124 |
|
| 125 |
|
| 126 |
class RevisionNotPresent(Error): |
| 127 |
"""Revision not present in the graph.""" |
| 128 |
|
| 129 |
def __init__(self, revision_id, graph): |
| 130 |
"""Initialize RevisionNotPresent exception. |
| 131 |
|
| 132 |
Args: |
| 133 |
revision_id: The revision ID not present in the graph. |
| 134 |
graph: The graph object where the revision was not found. |
| 135 |
""" |
| 136 |
self.revision_id = revision_id |
| 137 |
self.graph = graph |
| 138 |
super().__init__(f"Revision {revision_id!r} not present in graph") |
| 139 |
|
| 140 |
def __eq__(self, other): |
| 141 |
"""Check equality with another RevisionNotPresent instance. |
| 142 |
|
| 143 |
Args: |
| 144 |
other: Object to compare with. |
| 145 |
|
| 146 |
Returns: |
| 147 |
True if both instances have the same revision_id and graph. |
| 148 |
""" |
| 149 |
if not isinstance(other, RevisionNotPresent): |
| 150 |
return False |
| 151 |
return self.revision_id == other.revision_id and self.graph == other.graph |
| 152 |
|
| 153 |
|
| 154 |
class GraphCycleError(Error): |
| 155 |
"""Cycle detected in graph. |
| 156 |
|
| 157 |
Raised when a cycle is detected in a directed graph that should be acyclic. |
| 158 |
""" |
| 159 |
|
| 160 |
def __init__(self, graph): |
| 161 |
"""Initialize with the graph containing the cycle. |
| 162 |
|
| 163 |
Args: |
| 164 |
graph: The graph object that contains a cycle. |
| 165 |
""" |
| 166 |
self.graph = graph |
| 167 |
super().__init__(f"Cycle in graph {graph!r}") |
| 168 |
|
| 169 |
def __eq__(self, other): |
| 170 |
"""Check equality with another GraphCycleError instance. |
| 171 |
|
| 172 |
Args: |
| 173 |
other: Object to compare with. |
| 174 |
|
| 175 |
Returns: |
| 176 |
True if both instances have the same graph. |
| 177 |
""" |
| 178 |
if not isinstance(other, GraphCycleError): |
| 179 |
return False |
| 180 |
return self.graph == other.graph |