Skip to content
Snippets Groups Projects
Commit 413bd72d authored by chrg's avatar chrg
Browse files

Add some logging

parent b725c65f
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,11 @@ import os
import git_filter_repo as fr
import tempfile
import subprocess
import logging
from dataclasses import dataclass, field
log = logging.getLogger("regit")
# Some code borrowed from https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/lint-history
......@@ -96,13 +99,17 @@ def transform_program(program: Path, args: tuple[str], folder: Path):
try:
ix = pargs.index("{}")
except ValueError:
cmd = [program] + pargs
log.debug("Running cmd %s", cmd)
return subprocess.run(
[program] + pargs, input=content, capture_output=True, check=True
cmd, input=content, capture_output=True, check=True
).stdout
else:
with tfile(folder, file.name, content) as tmp_file:
pargs[ix] = str(tmp_file)
subprocess.run([program] + pargs, check=True)
cmd = [program] + pargs
log.debug("Running cmd %s", cmd)
subprocess.run(cmd, check=True)
with open(tmp_file, "rb") as f:
return f.read()
......@@ -129,6 +136,12 @@ def transform_program(program: Path, args: tuple[str], folder: Path):
help="The file to output the csv mapping to",
type=click.File("w", lazy=False),
)
@click.option(
"-v",
"--verbose",
help="The verbosity of logging",
count=True,
)
@click.argument(
"program",
# help="The program to execute on each file",
......@@ -147,9 +160,13 @@ def regit(
mapping,
program: Path,
args: tuple[str],
verbose: int,
):
"""A simple program that runs a command on every commit on a repo."""
logging.basicConfig(level=verbose)
log.debug("Setting verbosity %s", verbose)
if output is None:
output = Path(tempfile.mkdtemp())
......@@ -175,7 +192,15 @@ def regit(
writer = csv.writer(mapping)
writer.writerow(["from", "to"])
for fm, to in filter._commit_renames.items():
writer.writerow([m.decode() for m in [fm, to]])
def handle(a):
if isinstance(a, bytes):
return a.decode()
else:
log.warning("Unexpected result %s", a)
return str(a)
writer.writerow([handle(m) for m in [fm, to]])
print(output)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment