Parse a patch generated with `git show` or `git diff` using PATCH_COMMON_ARGS. Returns a list of Scannable. A patch looks like this: ``` commit $SHA Author: $NAME <$EMAIL> Date: $DATE $SUBJECT $BODY1 $BODY2 ... $AFFECTED_FILE_LI
(
sha: Optional[str], patch: str, exclusion_regexes: Optional[Set[Pattern[str]]]
)
| 202 | |
| 203 | |
| 204 | def parse_patch( |
| 205 | sha: Optional[str], patch: str, exclusion_regexes: Optional[Set[Pattern[str]]] |
| 206 | ) -> Iterable[Scannable]: |
| 207 | """ |
| 208 | Parse a patch generated with `git show` or `git diff` using PATCH_COMMON_ARGS. |
| 209 | Returns a list of Scannable. |
| 210 | |
| 211 | A patch looks like this: |
| 212 | |
| 213 | ``` |
| 214 | commit $SHA |
| 215 | Author: $NAME <$EMAIL> |
| 216 | Date: $DATE |
| 217 | |
| 218 | $SUBJECT |
| 219 | |
| 220 | $BODY1 |
| 221 | $BODY2 |
| 222 | ... |
| 223 | |
| 224 | $AFFECTED_FILE_LINE\0$DIFF1 |
| 225 | $DIFF2 |
| 226 | ... |
| 227 | ``` |
| 228 | |
| 229 | For a non-merge commit, $DIFFn looks like this: |
| 230 | |
| 231 | ``` |
| 232 | diff --git $A_NAME $B_NAME |
| 233 | $META_INFO |
| 234 | $META_INFO |
| 235 | ... |
| 236 | --- $A_NAME |
| 237 | +++ $A_NAME |
| 238 | @@ $FROM $TO @@ |
| 239 | $ACTUAL_CHANGES |
| 240 | @@ $FROM $TO @@ |
| 241 | $MORE_CHANGES |
| 242 | ``` |
| 243 | |
| 244 | $A_NAME and $B_NAME may be /dev/null in case of creation or removal. When they are |
| 245 | not, they start with "a/" and "b/" respectively. |
| 246 | |
| 247 | For a 2-parent merge commit with resolved conflicts, $DIFFn looks like this: |
| 248 | |
| 249 | ``` |
| 250 | diff --cc $NAME |
| 251 | $META_INFO |
| 252 | $META_INFO |
| 253 | ... |
| 254 | --- $A_NAME |
| 255 | +++ $B_NAME |
| 256 | @@@ $FROM1 $FROM2 $TO @@@ |
| 257 | $ACTUAL_CHANGES |
| 258 | ``` |
| 259 | |
| 260 | Note that: |
| 261 | - The diff line only contains one name, without any "a/" or "b/" prefixes. |
no test coverage detected