-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_ide: Prioritize upstream settings
... and print a diff of the settings that have changed. Bug: b/358194883 Change-Id: I36f5a95304d1558cefeeb3cfd21323e0c0ea469f Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230993 Presubmit-Verified: CQ Bot Account <[email protected]> Lint: Lint 🤖 <[email protected]> Reviewed-by: Anthony DiGirolamo <[email protected]> Commit-Queue: Chad Norvell <[email protected]>
- Loading branch information
1 parent
70e52ae
commit fdeee8e
Showing
12 changed files
with
86 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 The Pigweed Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
"""Print git-style diffs.""" | ||
|
||
|
||
import difflib | ||
import sys | ||
from typing import Iterable, Sequence, Union | ||
|
||
from pw_cli.color import colors | ||
|
||
_COLOR = colors() | ||
|
||
|
||
def colorize_diff_line(line: str) -> str: | ||
if line.startswith('--- ') or line.startswith('+++ '): | ||
return _COLOR.bold_white(line) | ||
if line.startswith('-'): | ||
return _COLOR.red(line) | ||
if line.startswith('+'): | ||
return _COLOR.green(line) | ||
if line.startswith('@@ '): | ||
return _COLOR.cyan(line) | ||
return line | ||
|
||
|
||
def colorize_diff(lines: Union[str, Iterable[str]]) -> str: | ||
"""Takes a diff str or list of str lines and returns a colorized version.""" | ||
if isinstance(lines, str): | ||
lines = lines.splitlines(True) | ||
|
||
return ''.join(colorize_diff_line(line) for line in lines) | ||
|
||
|
||
def print_diff( | ||
a: Sequence[str], b: Sequence[str], fromfile="", tofile="", indent=0 | ||
) -> None: | ||
"""Print a git-style diff of two string sequences.""" | ||
indent_str = ' ' * indent | ||
diff = colorize_diff(difflib.unified_diff(a, b, fromfile, tofile)) | ||
|
||
for line in diff.splitlines(True): | ||
sys.stdout.write(indent_str + line) | ||
|
||
sys.stdout.write("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters