From 2d184a135d1608ac2cd5b9ebf617eae0af89efeb Mon Sep 17 00:00:00 2001 From: David Mrva Date: Sun, 16 Feb 2020 20:22:54 +0000 Subject: [PATCH 1/3] replaced .format() with f-strings --- scripts/find_commits_touching_func.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/find_commits_touching_func.py b/scripts/find_commits_touching_func.py index 85675cb6df42b..3de81bae281e7 100755 --- a/scripts/find_commits_touching_func.py +++ b/scripts/find_commits_touching_func.py @@ -99,7 +99,7 @@ def get_hits(defname, files=()): r = sh.git( "blame", "-L", - r"/def\s*{start}/,/def/".format(start=defname), + rf"/def\s*{defname}/,/def/", f, _tty_out=False, ) @@ -119,8 +119,8 @@ def get_hits(defname, files=()): def get_commit_info(c, fmt, sep="\t"): r = sh.git( "log", - "--format={}".format(fmt), - "{}^..{}".format(c, c), + f"--format={fmt}", + f"{c}^..{c}", "-n", "1", _tty_out=False, @@ -203,10 +203,9 @@ def sorter(i): h, s, d = get_commit_vitals(hit.commit) p = hit.path.split(os.path.realpath(os.curdir) + os.path.sep)[-1] - fmt = "{:%d} {:10} {:<%d} {:<%d}" % (HASH_LEN, SUBJ_LEN, PATH_LEN) if len(s) > SUBJ_LEN: s = s[: SUBJ_LEN - 5] + " ..." - print(fmt.format(h[:HASH_LEN], d.isoformat()[:10], s, p[-20:])) + print(f"{h[:HASH_LEN]:{HASH_LEN}} {d.isoformat()[:10]:10} {s:<{SUBJ_LEN}} {p[-20:]:<{PATH_LEN}}") print("\n") From 7db30a10ba9f99059d4025498dcda03cb05c1e06 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Sun, 16 Feb 2020 20:55:42 +0000 Subject: [PATCH 2/3] reduced a line length --- scripts/find_commits_touching_func.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/find_commits_touching_func.py b/scripts/find_commits_touching_func.py index 3de81bae281e7..ddf728468be13 100755 --- a/scripts/find_commits_touching_func.py +++ b/scripts/find_commits_touching_func.py @@ -205,7 +205,11 @@ def sorter(i): if len(s) > SUBJ_LEN: s = s[: SUBJ_LEN - 5] + " ..." - print(f"{h[:HASH_LEN]:{HASH_LEN}} {d.isoformat()[:10]:10} {s:<{SUBJ_LEN}} {p[-20:]:<{PATH_LEN}}") + print(f"{h[:HASH_LEN]:{HASH_LEN}} " + f"{d.isoformat()[:10]:10} " + f"{s:<{SUBJ_LEN}} " + f"{p[-20:]:<{PATH_LEN}}" + ) print("\n") From 5be6b98122589138d8707efbab1ce947ee68a1ad Mon Sep 17 00:00:00 2001 From: David Mrva Date: Sun, 16 Feb 2020 21:50:02 +0000 Subject: [PATCH 3/3] fixed linting issue --- scripts/find_commits_touching_func.py | 28 ++++++++------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/scripts/find_commits_touching_func.py b/scripts/find_commits_touching_func.py index ddf728468be13..ba2f54dd9bbe3 100755 --- a/scripts/find_commits_touching_func.py +++ b/scripts/find_commits_touching_func.py @@ -96,13 +96,7 @@ def get_hits(defname, files=()): cs = set() for f in files: try: - r = sh.git( - "blame", - "-L", - rf"/def\s*{defname}/,/def/", - f, - _tty_out=False, - ) + r = sh.git("blame", "-L", rf"/def\s*{defname}/,/def/", f, _tty_out=False,) except sh.ErrorReturnCode_128: logger.debug("no matches in %s" % f) continue @@ -117,14 +111,7 @@ def get_hits(defname, files=()): def get_commit_info(c, fmt, sep="\t"): - r = sh.git( - "log", - f"--format={fmt}", - f"{c}^..{c}", - "-n", - "1", - _tty_out=False, - ) + r = sh.git("log", f"--format={fmt}", f"{c}^..{c}", "-n", "1", _tty_out=False,) return str(r).split(sep) @@ -205,11 +192,12 @@ def sorter(i): if len(s) > SUBJ_LEN: s = s[: SUBJ_LEN - 5] + " ..." - print(f"{h[:HASH_LEN]:{HASH_LEN}} " - f"{d.isoformat()[:10]:10} " - f"{s:<{SUBJ_LEN}} " - f"{p[-20:]:<{PATH_LEN}}" - ) + print( + f"{h[:HASH_LEN]:{HASH_LEN}} " + f"{d.isoformat()[:10]:10} " + f"{s:<{SUBJ_LEN}} " + f"{p[-20:]:<{PATH_LEN}}" + ) print("\n")