Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
regit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Systems Engineering
regit
Commits
413bd72d
Commit
413bd72d
authored
Mar 20, 2023
by
chrg
Browse files
Options
Downloads
Patches
Plain Diff
Add some logging
parent
b725c65f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
regit/__main__.py
+28
-3
28 additions, 3 deletions
regit/__main__.py
with
28 additions
and
3 deletions
regit/__main__.py
+
28
−
3
View file @
413bd72d
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment