Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
06523a7e
Commit
06523a7e
authored
6 years ago
by
Boris Feld
Browse files
Options
Downloads
Patches
Plain Diff
Extract all make-reference functions into a separate library module
parent
d00044f3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/scmperf_lib/__init__.py
+94
-0
94 additions, 0 deletions
lib/scmperf_lib/__init__.py
repo-scripts/make-reference
+4
-75
4 additions, 75 deletions
repo-scripts/make-reference
with
98 additions
and
75 deletions
lib/scmperf_lib/__init__.py
0 → 100644
+
94
−
0
View file @
06523a7e
import
json
import
subprocess
def
gather_repo_stats
(
repo
,
repo_id
,
repo_source
):
"""
gather repo related stats and returns a json-encodable dict
The dict contains:
- the repo_id given in parameter
- is the repo enabled (True by default)
- the repo_source given in parameter
- the hgversion taken from the hg binary
- the number of revisions and hidden revisions
- the number of heads and hidden heads
- the number of named branches and hidden named branches
- the format info taken from `hg debugformat`
"""
hgversion
=
shell_exec
([
"
hg
"
,
"
version
"
,
"
-T
"
,
"
{ver}
"
])
numrevs
=
count_line_exec
([
"
hg
"
,
"
-R
"
,
repo
,
"
log
"
,
"
-T
"
,
"
{rev}
\n
"
])
numrevshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
log
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numheads
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
heads
"
,
"
-t
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numheadshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
heads
"
,
"
-t
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numbranches
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
branches
"
,
"
-c
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numbrancheshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
branches
"
,
"
-c
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
# Format information
raw_format_data
=
json
.
loads
(
shell_exec
([
"
hg
"
,
"
-R
"
,
repo
,
"
debugformat
"
,
"
-T
"
,
"
json
"
])
)
format_data
=
{}
for
format_value
in
raw_format_data
:
repo_value
=
format_value
[
"
repo
"
]
if
isinstance
(
repo_value
,
basestring
):
# String values should be valid ASCII
repo_value
=
repo_value
.
encode
(
"
ascii
"
)
# Keys should be valid ASCII
format_data
[
format_value
[
"
name
"
].
encode
(
"
ascii
"
)]
=
repo_value
# Generate YAML file
return
{
"
reference-repo
"
:
{
"
id
"
:
repo_id
,
"
enabled
"
:
True
,
"
source
"
:
repo_source
,
"
hg-version
"
:
hgversion
,
"
number-revisions
"
:
{
"
visible
"
:
numrevs
,
"
all
"
:
numrevshidden
},
"
number-heads
"
:
{
"
visible
"
:
numheads
,
"
all
"
:
numheadshidden
},
"
number-named-branch
"
:
{
"
visible
"
:
numbranches
,
"
all
"
:
numbrancheshidden
,
},
"
format-info
"
:
format_data
,
}
}
def
shell_exec
(
command
,
env
=
None
):
"""
return the standard output of a given command
- stderr is discarded
- non-zero return code will raise `subprocess.CalledProcessError`
"""
process
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
shell
=
False
,
env
=
env
)
output
,
unused_err
=
process
.
communicate
()
retcode
=
process
.
poll
()
if
retcode
:
raise
subprocess
.
CalledProcessError
(
retcode
,
command
)
return
output
def
count_line_exec
(
command
,
env
=
None
):
"""
execute the given command and count the number of stdout lines
Similar to `cmd | wc -l`
"""
output
=
shell_exec
(
command
,
env
)
return
len
(
output
.
splitlines
())
This diff is collapsed.
Click to expand it.
repo-scripts/make-reference
+
4
−
75
View file @
06523a7e
#!/usr/bin/env python
import
argparse
import
json
import
os
import
os.path
import
shutil
...
...
@@ -5,7 +4,6 @@
import
os
import
os.path
import
shutil
import
subprocess
import
sys
import
tarfile
from
glob
import
glob
...
...
@@ -9,7 +7,7 @@
import
sys
import
tarfile
from
glob
import
glob
from
os.path
import
join
from
os.path
import
abspath
,
basename
,
dirname
,
join
import
yaml
...
...
@@ -13,35 +11,6 @@
import
yaml
def
gather_repo_stats
(
repo
,
repo_id
,
repo_source
):
"""
Gather repo related stats
"""
hgversion
=
shell_exec
([
"
hg
"
,
"
version
"
,
"
-T
"
,
"
{ver}
"
])
numrevs
=
count_line_exec
([
"
hg
"
,
"
-R
"
,
repo
,
"
log
"
,
"
-T
"
,
"
{rev}
\n
"
])
numrevshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
log
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numheads
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
heads
"
,
"
-t
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numheadshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
heads
"
,
"
-t
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numbranches
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
branches
"
,
"
-c
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
numbrancheshidden
=
count_line_exec
(
[
"
hg
"
,
"
-R
"
,
repo
,
"
--hidden
"
,
"
branches
"
,
"
-c
"
,
"
-T
"
,
"
{rev}
\n
"
]
)
# Format information
raw_format_data
=
json
.
loads
(
shell_exec
([
"
hg
"
,
"
-R
"
,
repo
,
"
debugformat
"
,
"
-T
"
,
"
json
"
])
)
format_data
=
{}
parent_dir
=
abspath
(
join
(
dirname
(
abspath
(
__file__
)),
"
..
"
))
sys
.
path
.
insert
(
0
,
join
(
parent_dir
,
"
lib
"
))
...
...
@@ -47,45 +16,5 @@
for
format_value
in
raw_format_data
:
repo_value
=
format_value
[
"
repo
"
]
if
isinstance
(
repo_value
,
basestring
):
# String values should be valid ASCII
repo_value
=
repo_value
.
encode
(
"
ascii
"
)
# Keys should be valid ASCII
format_data
[
format_value
[
"
name
"
].
encode
(
"
ascii
"
)]
=
repo_value
# Generate YAML file
return
{
"
reference-repo
"
:
{
"
id
"
:
repo_id
,
"
enabled
"
:
True
,
"
source
"
:
repo_source
,
"
hg-version
"
:
hgversion
,
"
number-revisions
"
:
{
"
visible
"
:
numrevs
,
"
all
"
:
numrevshidden
},
"
number-heads
"
:
{
"
visible
"
:
numheads
,
"
all
"
:
numheadshidden
},
"
number-named-branch
"
:
{
"
visible
"
:
numbranches
,
"
all
"
:
numbrancheshidden
,
},
"
format-info
"
:
format_data
,
}
}
def
shell_exec
(
command
,
env
=
None
):
# Simulate bash script printing the commands it runs
process
=
subprocess
.
Popen
(
command
,
stdout
=
subprocess
.
PIPE
,
shell
=
False
,
env
=
env
)
output
,
unused_err
=
process
.
communicate
()
retcode
=
process
.
poll
()
if
retcode
:
raise
subprocess
.
CalledProcessError
(
retcode
,
command
)
return
output
def
count_line_exec
(
command
,
env
=
None
):
output
=
shell_exec
(
command
,
env
)
return
len
(
output
.
splitlines
())
from
scmperf_lib
import
gather_repo_stats
,
shell_exec
# isort:skip
def
main
(
args
):
...
...
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