Home Home > GIT Browse > SLE15
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Poirier <bpoirier@suse.com>2019-01-19 09:35:30 +0900
committerBenjamin Poirier <bpoirier@suse.com>2019-01-19 09:46:00 +0900
commita010ff559ce523c7f98fb582b3ea3ed535daa168 (patch)
treed904fa84d41ff19d1dd16798b8945d3d2f0b24a3
parent949d090add4b8249a771de3e824975510f718596 (diff)
git-sort: series_sort: Make "series.conf" the implicit argument
Similar to series_insert, "series.conf" becomes the default file where to read/write the patch series. In contrast to series_sort, if the input is not a tty and no argument is specified, the old mode is preserved, which is to behave as an stdin/stdout filter. This way, the original usecase of piping all or a subset of series.conf lines through series_sort (for example, in the method described in the script header) remains unchanged.
-rwxr-xr-xscripts/git_sort/series_sort.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/scripts/git_sort/series_sort.py b/scripts/git_sort/series_sort.py
index ae50761a97..7fbfbcb9b0 100755
--- a/scripts/git_sort/series_sort.py
+++ b/scripts/git_sort/series_sort.py
@@ -67,22 +67,31 @@ if __name__ == "__main__":
"as appropriate. Default: false.")
parser.add_argument("series", nargs="?", metavar="series.conf",
help="series.conf file which will be modified in "
- "place. Default: read input from stdin.")
+ "place. Default: if stdin is a terminal, "
+ "\"series.conf\"; otherwise, read input from stdin.")
args = parser.parse_args()
repo_path = lib.repo_path()
repo = pygit2.Repository(repo_path)
index = git_sort.SortIndex(repo)
- if args.series is not None:
+ filter_mode = False
+ if args.series is None:
+ if sys.stdin.isatty():
+ path = "series.conf"
+ else:
+ filter_mode = True
+ else:
+ path = args.series
+ if filter_mode:
+ f = sys.stdin
+ else:
try:
- f = open(args.series)
+ f = open(path)
except FileNotFoundError as err:
print("Error: %s" % (err,), file=sys.stderr)
sys.exit(1)
- series = os.path.abspath(args.series)
- else:
- f = sys.stdin
+ series_path = os.path.abspath(path)
lines = f.readlines()
if args.prefix is not None:
@@ -91,7 +100,7 @@ if __name__ == "__main__":
try:
before, inside, after = series_conf.split(lines)
except exc.KSNotFound as err:
- if args.series is None:
+ if filter_mode:
before = []
inside = lines
after = []
@@ -137,10 +146,10 @@ if __name__ == "__main__":
after,
])
- if args.series is not None:
- f = open(series, mode="w")
- else:
+ if filter_mode:
f = sys.stdout
+ else:
+ f = open(series_path, mode="w")
f.writelines(output)
try:
lib.update_tags(index, to_update)