Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Autopsy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IRT
Autopsy
Commits
5fd2c2ae
Commit
5fd2c2ae
authored
4 years ago
by
Greg DiCristofaro
Browse files
Options
Downloads
Patches
Plain Diff
comment fixes
parent
80179969
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apidiff.py
+21
-19
21 additions, 19 deletions
apidiff.py
with
21 additions
and
19 deletions
apidiff.py
+
21
−
19
View file @
5fd2c2ae
"""
"""
Generates an api diff from one commit to another. This script relies on gitpython and similarly require git
Generates an api diff from one commit to another. This script relies on gitpython and similarly require git
installed on the system. This script also requires python
3
installed on the system. This script also requires python
3.
C
an be called as follows:
This script c
an be called as follows:
python apidiff.py <previous tag id> <latest tag id> -r <repo path> -o <output path>
python apidiff.py <previous tag id> <latest tag id> -r <repo path> -o <output path>
If the
'
-o
'
flag is not specified, this will create a folder at apidiff_output in the same directory as the
script.
If the
'
-o
'
flag is not specified, this
script
will create a folder at apidiff_output in the same directory as the
For full list of options call:
script.
For full list of options call:
python apidiff.py -h
python apidiff.py -h
"""
"""
...
@@ -43,10 +43,10 @@ def compare_xml(jdiff_path: str, root_dir: str, output_folder: str, oldapi_folde
...
@@ -43,10 +43,10 @@ def compare_xml(jdiff_path: str, root_dir: str, output_folder: str, oldapi_folde
:param root_dir: directory for output .
:param root_dir: directory for output .
:param output_folder: Folder for diff output.
:param output_folder: Folder for diff output.
:param oldapi_folder: Folder name of old api (i.e. release-4.10.2).
:param oldapi_folder: Folder name of old api (i.e. release-4.10.2).
:param newapi_folder: Folder name of
old
api (i.e. release-4.10.2).
:param newapi_folder: Folder name of
new
api (i.e. release-4.10.2).
:param api_file_name: Name of xml file name (i.e. if output.xml, just
'
output
'
)
:param api_file_name: Name of xml file name (i.e. if output.xml, just
'
output
'
)
:param log_path: Path to log file.
:param log_path: Path to log file.
:return: jdiff
comparison
code.
:return: jdiff
exit
code.
"""
"""
jdiff_parent
=
os
.
path
.
dirname
(
jdiff_path
)
jdiff_parent
=
os
.
path
.
dirname
(
jdiff_path
)
...
@@ -91,7 +91,7 @@ def compare_xml(jdiff_path: str, root_dir: str, output_folder: str, oldapi_folde
...
@@ -91,7 +91,7 @@ def compare_xml(jdiff_path: str, root_dir: str, output_folder: str, oldapi_folde
return
code
return
code
def
gen_xml
(
jdiff_path
:
str
,
output_path
:
str
,
log_output_path
:
str
,
src
:
str
,
packages
):
def
gen_xml
(
jdiff_path
:
str
,
output_path
:
str
,
log_output_path
:
str
,
src
:
str
,
packages
:
List
[
str
]
):
"""
"""
Uses jdiff to generate an xml representation of the source code.
Uses jdiff to generate an xml representation of the source code.
:param jdiff_path: Path to jdiff jar.
:param jdiff_path: Path to jdiff jar.
...
@@ -103,7 +103,7 @@ def gen_xml(jdiff_path: str, output_path: str, log_output_path: str, src: str, p
...
@@ -103,7 +103,7 @@ def gen_xml(jdiff_path: str, output_path: str, log_output_path: str, src: str, p
make_dir
(
output_path
)
make_dir
(
output_path
)
log
=
open_log_file
(
log_output_path
)
log
=
open_log_file
(
log_output_path
)
log_and_print
(
log
,
f
"
Generating XML for:
{
src
}
outputting
{
output_path
}
"
)
log_and_print
(
log
,
f
"
Generating XML for:
{
src
}
outputting
to:
{
output_path
}
"
)
cmd
=
[
"
javadoc
"
,
cmd
=
[
"
javadoc
"
,
"
-doclet
"
,
"
jdiff.JDiff
"
,
"
-doclet
"
,
"
jdiff.JDiff
"
,
"
-docletpath
"
,
fix_path
(
jdiff_path
),
"
-docletpath
"
,
fix_path
(
jdiff_path
),
...
@@ -144,7 +144,7 @@ def _list_paths(root_tree: Tree, src_folder, path: Path = None) -> Iterator[Tupl
...
@@ -144,7 +144,7 @@ def _list_paths(root_tree: Tree, src_folder, path: Path = None) -> Iterator[Tupl
def
_get_tree
(
repo_path
:
str
,
commit_id
:
str
)
->
Tree
:
def
_get_tree
(
repo_path
:
str
,
commit_id
:
str
)
->
Tree
:
"""
"""
Retrieves the tree that can be walked for files and file content at the specified commit.
Retrieves the
git
tree that can be walked for files and file content at the specified commit.
Args:
Args:
repo_path: The path to the repo or a child directory of the repo.
repo_path: The path to the repo or a child directory of the repo.
commit_id: The commit id.
commit_id: The commit id.
...
@@ -157,10 +157,10 @@ def _get_tree(repo_path: str, commit_id: str) -> Tree:
...
@@ -157,10 +157,10 @@ def _get_tree(repo_path: str, commit_id: str) -> Tree:
def
copy_commit_paths
(
repo_path
,
commit_id
,
src_folder
,
output_folder
):
def
copy_commit_paths
(
repo_path
,
commit_id
,
src_folder
,
output_folder
):
"""
"""
Copies all files located within a repo
with
in the folder
'
src_folder
'
to
'
output_folder
'
Copies all files located within a repo in the folder
'
src_folder
'
to
'
output_folder
'
.
:param repo_path: The path to the repo.
:param repo_path: The path to the repo.
:param commit_id: The commit id.
:param commit_id: The commit id.
:param src_folder: The source folder.
:param src_folder: The
relative path in the repo to the
source folder.
:param output_folder: The output folder where the source will be copied.
:param output_folder: The output folder where the source will be copied.
"""
"""
tree
=
_get_tree
(
repo_path
,
commit_id
)
tree
=
_get_tree
(
repo_path
,
commit_id
)
...
@@ -175,7 +175,7 @@ def copy_commit_paths(repo_path, commit_id, src_folder, output_folder):
...
@@ -175,7 +175,7 @@ def copy_commit_paths(repo_path, commit_id, src_folder, output_folder):
def
open_log_file
(
log_path
):
def
open_log_file
(
log_path
):
"""
"""
Opens a path to a lof file for appending. Creating
necessary
directories and file
s
as necessary.
Opens a path to a lof file for appending. Creating directories and
log
file as necessary.
:param log_path: The path to the log file.
:param log_path: The path to the log file.
:return: The log file opened for writing.
:return: The log file opened for writing.
"""
"""
...
@@ -189,7 +189,7 @@ def open_log_file(log_path):
...
@@ -189,7 +189,7 @@ def open_log_file(log_path):
def
fix_path
(
path
):
def
fix_path
(
path
):
"""
"""
Generates a path that is escaped from cygwin paths if present.
Generates a path that is escaped from cygwin paths if present.
:param path: Path (possibly cygdrive).
:param path: Path (possibly
including
cygdrive).
:return: The normalized path.
:return: The normalized path.
"""
"""
if
"
cygdrive
"
in
path
:
if
"
cygdrive
"
in
path
:
...
@@ -227,16 +227,17 @@ def make_dir(dir_path: str):
...
@@ -227,16 +227,17 @@ def make_dir(dir_path: str):
return
False
return
False
def
run_compare
(
output_path
:
str
,
jdiff_path
:
str
,
repo_path
:
str
,
src_rel_path
:
str
,
prev_commit_id
:
str
,
latest_commit_id
:
str
,
packages
:
List
[
str
]):
def
run_compare
(
output_path
:
str
,
jdiff_path
:
str
,
repo_path
:
str
,
src_rel_path
:
str
,
prev_commit_id
:
str
,
latest_commit_id
:
str
,
packages
:
List
[
str
]):
"""
"""
Runs a comparison of the api between two different commits/branches/tags of the same repo generating a jdiff diff.
Runs a comparison of the api between two different commits/branches/tags of the same repo generating a jdiff diff.
:param output_path: The output path for artifacts.
:param output_path: The output path for artifacts.
:param jdiff_path: The path to the jdiff jar.
:param jdiff_path: The path to the jdiff jar.
:param repo_path: The path to the repo.
:param repo_path: The path to the repo.
:param src_rel_path: The relative path in the repo to the source directory.
:param src_rel_path: The relative path in the repo to the source directory.
:param prev_commit_id: The previous commit id.
:param prev_commit_id: The previous commit
/branch/tag
id.
:param latest_commit_id: The latest commit id.
:param latest_commit_id: The latest commit
/branch/tag
id.
:param packages: The packages to be considered for the api diff
:param packages: The packages to be considered for the api diff
.
"""
"""
log_path
=
os
.
path
.
join
(
output_path
,
"
messages.log
"
)
log_path
=
os
.
path
.
join
(
output_path
,
"
messages.log
"
)
output_file_name
=
"
output
"
output_file_name
=
"
output
"
...
@@ -254,12 +255,13 @@ def run_compare(output_path: str, jdiff_path: str, repo_path: str, src_rel_path:
...
@@ -254,12 +255,13 @@ def run_compare(output_path: str, jdiff_path: str, repo_path: str, src_rel_path:
def
main
():
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
"
Generates a jdiff diff of the java api between two scripts
"
,
parser
=
argparse
.
ArgumentParser
(
description
=
"
Generates a jdiff diff of the java api between two commits in a
"
"
repo.
"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
dest
=
'
prev_commit
'
,
type
=
str
,
help
=
r
'
The git commit id/branch/tag to be used for the first
'
parser
.
add_argument
(
dest
=
'
prev_commit
'
,
type
=
str
,
help
=
r
'
The git commit id/branch/tag to be used for the first
'
r
'
commit
'
)
r
'
commit
'
)
parser
.
add_argument
(
dest
=
'
latest_commit
'
,
type
=
str
,
help
=
r
'
The git commit id/branch/tag to be used for the latest
'
parser
.
add_argument
(
dest
=
'
latest_commit
'
,
type
=
str
,
help
=
r
'
The git commit id/branch/tag to be used for the latest
'
r
'
commit
'
)
r
'
commit
'
)
parser
.
add_argument
(
'
-r
'
,
'
--repo
'
,
dest
=
'
repo_path
'
,
type
=
str
,
required
=
True
,
parser
.
add_argument
(
'
-r
'
,
'
--repo
'
,
dest
=
'
repo_path
'
,
type
=
str
,
required
=
True
,
help
=
'
The path to the repo. If not specified, path of script is used.
'
)
help
=
'
The path to the repo. If not specified, path of script is used.
'
)
...
...
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