Skip to content

CLN: 29547 replace .format() with f-strings #32044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions scripts/find_commits_touching_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,7 @@ def get_hits(defname, files=()):
cs = set()
for f in files:
try:
r = sh.git(
"blame",
"-L",
r"/def\s*{start}/,/def/".format(start=defname),
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
Expand All @@ -117,14 +111,7 @@ def get_hits(defname, files=()):


def get_commit_info(c, fmt, sep="\t"):
r = sh.git(
"log",
"--format={}".format(fmt),
"{}^..{}".format(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)


Expand Down Expand Up @@ -203,10 +190,14 @@ 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}} "
f"{d.isoformat()[:10]:10} "
f"{s:<{SUBJ_LEN}} "
f"{p[-20:]:<{PATH_LEN}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing the behavior, can you test this and make sure it works as the original.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way do you see the behaviour changed?

)

print("\n")

Expand Down