diff options
author | Eric Engestrom <eric@engestrom.ch> | 2022-11-24 15:59:51 +0000 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2022-11-30 17:08:48 +0000 |
commit | cf841cdd0bcf0784fb6a4301e624e12f3502ba5a (patch) | |
tree | ea0f632eb3b653cb34d3f89d57dba1ab2941ba92 /bin | |
parent | 707015891fc65dcf5b0b2601aa78f1fb33a01f39 (diff) | |
download | mesa-cf841cdd0bcf0784fb6a4301e624e12f3502ba5a.tar.gz |
commit_in_branch.py: variables cleanup
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19988>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/commit_in_branch.py | 22 | ||||
-rw-r--r-- | bin/commit_in_branch_test.py | 40 |
2 files changed, 30 insertions, 32 deletions
diff --git a/bin/commit_in_branch.py b/bin/commit_in_branch.py index 36ee7a9795e..444f2b9ab7a 100755 --- a/bin/commit_in_branch.py +++ b/bin/commit_in_branch.py @@ -45,24 +45,26 @@ def is_commit_valid(commit: str) -> bool: return ret == 0 -def branch_has_commit(upstream: str, branch: str, commit: str) -> bool: +def branch_has_commit(upstream_branch: str, commit: str) -> bool: """ Returns True if the commit is actually present in the branch """ ret = subprocess.call(['git', 'merge-base', '--is-ancestor', - commit, upstream + '/' + branch], + commit, upstream_branch], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return ret == 0 -def branch_has_backport_of_commit(upstream: str, branch: str, commit: str) -> str: +def branch_has_backport_of_commit(upstream_branch: str, commit: str) -> str: """ Returns the commit hash if the commit has been backported to the branch, or an empty string if is hasn't """ + upstream, _ = upstream_branch.split('/', 1) + out = subprocess.check_output(['git', 'log', '--format=%H', - upstream + '..' + upstream + '/' + branch, + upstream + '..' + upstream_branch, '--grep', 'cherry picked from commit ' + commit], stderr=subprocess.DEVNULL) return out.decode().strip() @@ -125,17 +127,15 @@ if __name__ == "__main__": help='colorize output (default: true if stdout is a terminal)') args = parser.parse_args() - upstream, branch = args.branch.split('/', 1) - - if branch_has_commit(upstream, branch, args.commit): - print_(args, True, 'Commit ' + args.commit + ' is in branch ' + branch) + if branch_has_commit(args.branch, args.commit): + print_(args, True, 'Commit ' + args.commit + ' is in branch ' + args.branch) exit(0) - backport = branch_has_backport_of_commit(upstream, branch, args.commit) + backport = branch_has_backport_of_commit(args.branch, args.commit) if backport: print_(args, True, - 'Commit ' + args.commit + ' was backported to branch ' + branch + ' as commit ' + backport) + 'Commit ' + args.commit + ' was backported to branch ' + args.branch + ' as commit ' + backport) exit(0) - print_(args, False, 'Commit ' + args.commit + ' is NOT in branch ' + branch) + print_(args, False, 'Commit ' + args.commit + ' is NOT in branch ' + args.branch) exit(1) diff --git a/bin/commit_in_branch_test.py b/bin/commit_in_branch_test.py index aeb09a65000..8ecece80165 100644 --- a/bin/commit_in_branch_test.py +++ b/bin/commit_in_branch_test.py @@ -88,33 +88,31 @@ def test_is_commit_valid(commit: str, expected: bool) -> None: @pytest.mark.parametrize( 'branch, commit, expected', [ - ('20.1', '20.1-branchpoint', True), - ('20.1', '20.0', False), - ('20.1', 'main', False), - ('20.1', 'e58a10af640ba58b6001f5c5ad750b782547da76', True), - ('20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True), - ('staging/20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True), - ('20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', False), - ('main', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', True), - ('20.0', 'd043d24654c851f0be57dbbf48274b5373dea42b', False), + (get_upstream() + '/20.1', '20.1-branchpoint', True), + (get_upstream() + '/20.1', '20.0', False), + (get_upstream() + '/20.1', 'main', False), + (get_upstream() + '/20.1', 'e58a10af640ba58b6001f5c5ad750b782547da76', True), + (get_upstream() + '/20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True), + (get_upstream() + '/staging/20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', True), + (get_upstream() + '/20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', False), + (get_upstream() + '/main', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', True), + (get_upstream() + '/20.0', 'd043d24654c851f0be57dbbf48274b5373dea42b', False), ]) def test_branch_has_commit(branch: str, commit: str, expected: bool) -> None: - upstream = get_upstream() - assert branch_has_commit(upstream, branch, commit) == expected + assert branch_has_commit(branch, commit) == expected @pytest.mark.parametrize( 'branch, commit, expected', [ - ('20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'), - ('staging/20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'), - ('20.1', '20.1-branchpoint', ''), - ('20.1', '20.0', ''), - ('20.1', '20.2', 'abac4859618e02aea00f705b841a7c5c5007ad1a'), - ('20.1', 'main', ''), - ('20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', ''), - ('20.0', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', '8cd4f57381cefe69019a3282d457d5bda3644030'), + (get_upstream() + '/20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'), + (get_upstream() + '/staging/20.1', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', 'd043d24654c851f0be57dbbf48274b5373dea42b'), + (get_upstream() + '/20.1', '20.1-branchpoint', ''), + (get_upstream() + '/20.1', '20.0', ''), + (get_upstream() + '/20.1', '20.2', 'abac4859618e02aea00f705b841a7c5c5007ad1a'), + (get_upstream() + '/20.1', 'main', ''), + (get_upstream() + '/20.1', 'd043d24654c851f0be57dbbf48274b5373dea42b', ''), + (get_upstream() + '/20.0', 'dd2bd68fa69124c86cd008b256d06f44fab8e6cd', '8cd4f57381cefe69019a3282d457d5bda3644030'), ]) def test_branch_has_backport_of_commit(branch: str, commit: str, expected: bool) -> None: - upstream = get_upstream() - assert branch_has_backport_of_commit(upstream, branch, commit) == expected + assert branch_has_backport_of_commit(branch, commit) == expected |