mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
44dc946468
Summary: There's a bug here, so let's add a test exposing it. A future diff will fix the bug and update the test. Reviewed By: jordanwebster Differential Revision: D37771384 fbshipit-source-id: f482cf6d07ba4f16d833b9337a61b9dd7a85d7ac
77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
# pyre-strict
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Dict, List, Optional
|
|
|
|
|
|
class Status:
|
|
added: List[str]
|
|
deleted: List[str]
|
|
modified: List[str]
|
|
removed: List[str]
|
|
untracked: List[str]
|
|
copies: Dict[str, str]
|
|
|
|
ADDED = "added"
|
|
DELETED = "deleted"
|
|
MODIFIED = "modified"
|
|
REMOVED = "removed"
|
|
UNTRACKED = "untracked"
|
|
|
|
def __init__(self, raw_json: str) -> None:
|
|
self.added = []
|
|
self.deleted = []
|
|
self.modified = []
|
|
self.removed = []
|
|
self.untracked = []
|
|
self.copies = {}
|
|
|
|
for entry in json.loads(raw_json):
|
|
st = entry["status"]
|
|
path = entry["path"]
|
|
copy = entry.get("copy")
|
|
if st == "M":
|
|
self.modified.append(path)
|
|
elif st == "A":
|
|
self.added.append(path)
|
|
elif st == "R":
|
|
self.removed.append(path)
|
|
elif st == "!":
|
|
self.deleted.append(path)
|
|
elif st == "?":
|
|
self.untracked.append(path)
|
|
else:
|
|
raise ValueError("unknown status state '%s' for '%s'" % (st, path))
|
|
|
|
if copy is not None:
|
|
self.copies[path] = copy
|
|
|
|
def __getitem__(self, path: str) -> Optional[str]:
|
|
for kind, entries in [
|
|
(Status.ADDED, self.added),
|
|
(Status.DELETED, self.deleted),
|
|
(Status.MODIFIED, self.modified),
|
|
(Status.REMOVED, self.removed),
|
|
(Status.UNTRACKED, self.untracked),
|
|
]:
|
|
if path in entries:
|
|
return kind
|
|
|
|
return None
|
|
|
|
def empty(self) -> bool:
|
|
return not (
|
|
self.added + self.deleted + self.modified + self.removed + self.untracked
|
|
)
|
|
|
|
def __str__(self) -> str:
|
|
return "\n".join(
|
|
f"{k}: {v}" for (k, v) in sorted(vars(self).items()) if len(v) > 0
|
|
)
|