From 7951e9a0a98b4737bc9ef698ff7ec8de081ce8bf Mon Sep 17 00:00:00 2001 From: "You-Sheng Yang (vicamo)" Date: Wed, 8 Feb 2023 00:11:02 +0800 Subject: [PATCH] Allow specifying remote branch at listing changes Signed-off-by: You-Sheng Yang (vicamo) Change-Id: I9267598fcf2eb9316023c453d29bb1ffe4f94404 --- git-review.1 | 1 + git_review/cmd.py | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/git-review.1 b/git-review.1 index 15a4bd83..d6352cb6 100644 --- a/git-review.1 +++ b/git-review.1 @@ -46,6 +46,7 @@ .Op Ar branch .Nm .Fl l +.Op Ar branch .Nm .Fl \-version .Sh DESCRIPTION diff --git a/git_review/cmd.py b/git_review/cmd.py index 8553158e..c8a0191b 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -623,7 +623,7 @@ def parse_gerrit_ssh_params_from_git_url(git_url): return (hostname, username, port, project_name) -def query_reviews(remote_url, project=None, change=None, +def query_reviews(remote_url, project=None, branch=None, change=None, current_patch_set=True, exception=CommandFailed, parse_exc=Exception): if remote_url.startswith('http://') or remote_url.startswith('https://'): @@ -632,13 +632,14 @@ def query_reviews(remote_url, project=None, change=None, query = query_reviews_over_ssh return query(remote_url, project=project, + branch=branch, change=change, current_patch_set=current_patch_set, exception=exception, parse_exc=parse_exc) -def query_reviews_over_http(remote_url, project=None, change=None, +def query_reviews_over_http(remote_url, project=None, branch=None, change=None, current_patch_set=True, exception=CommandFailed, parse_exc=Exception): if project: @@ -666,7 +667,10 @@ def query_reviews_over_http(remote_url, project=None, change=None, else: project_name = re.sub(r"^/|(\.git$)", "", urlparse(remote_url).path) - params = urlencode({'q': 'project:%s status:open' % project_name}) + query = 'project:%s status:open' % project_name + if branch: + query += ' branch:%s' % branch + params = urlencode({'q': query}) url += '?' + params if VERBOSE: @@ -696,7 +700,7 @@ def query_reviews_over_http(remote_url, project=None, change=None, return reviews -def query_reviews_over_ssh(remote_url, project=None, change=None, +def query_reviews_over_ssh(remote_url, project=None, branch=None, change=None, current_patch_set=True, exception=CommandFailed, parse_exc=Exception): (hostname, username, port, project_name) = \ @@ -709,6 +713,8 @@ def query_reviews_over_ssh(remote_url, project=None, change=None, query = "--patch-sets change:%s" % change else: query = "project:%s status:open" % project_name + if branch: + query += ' branch:%s' % branch port_data = "p%s" % port if port is not None else "" if username is None: @@ -1150,12 +1156,13 @@ class ReviewsPrinter(object): print("Found %d items for review" % total_reviews) -def list_reviews(remote, project, with_topic=False): +def list_reviews(remote, project, branch=None, with_topic=False): remote_url = get_remote_url(remote) reviews = [] for r in query_reviews(remote_url, project=project, + branch=branch, exception=CannotQueryOpenChangesets, parse_exc=CannotParseOpenChangesets): reviews.append(Review(r)) @@ -1752,7 +1759,9 @@ additional information: return elif options.list: with_topic = options.list > 1 - list_reviews(remote, config['project'], with_topic=with_topic) + list_reviews(remote, config['project'], + branch if options.branch or options.track else None, + with_topic=with_topic) return if options.custom_script: