From a0963a1b51c0e26acf1879538dc2cdca48b5ccb8 Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Sat, 11 Mar 2017 11:55:01 +0100 Subject: [PATCH] Allow choosing field for author in named branch This adds a setting for choosing which of {name, email, username} to use as "author" when constructing the name for the branch to where a change is downloaded. The rationale is that sometimes the given "name" is just long and unwieldy (when displaying the branch in the shell prompt, for example), and one may be already used to the "username". Change-Id: Ieed465f69ed0c0864979a92f609bd8f58cd8e883 --- git-review.1 | 6 ++++++ git_review/cmd.py | 28 +++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/git-review.1 b/git-review.1 index 2e14ba29..e2f82664 100644 --- a/git-review.1 +++ b/git-review.1 @@ -292,6 +292,12 @@ This setting takes precedence over repository\-specific configuration in the .Pa .gitreview file. +.It gitreview.branchauthor +This setting changes the look of the author part when naming the local +branch of a downloaded change. Value must be one of "name", "email", +or "username". Default is "name". See also the +.Fl \-download +option. .El .Bl -tag .It color.review diff --git a/git_review/cmd.py b/git_review/cmd.py index 048da27f..b86cfdff 100644 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -43,7 +43,7 @@ GLOBAL_CONFIG = "/etc/git-review/git-review.conf" USER_CONFIG = os.path.join(CONFIGDIR, "git-review.conf") DEFAULTS = dict(scheme='ssh', hostname=False, port=None, project=False, branch='master', remote="gerrit", rebase="1", - track="0", usepushurl="0", notopic=False) + track="0", usepushurl="0", notopic=False, branchauthor="name") COPYRIGHT = """\ Copyright (C) 2011-2020 OpenStack LLC. @@ -69,6 +69,7 @@ _use_color = None _orig_head = None _rewrites = None _rewrites_push = None +BRANCHAUTHOR = None class colors(object): @@ -732,6 +733,7 @@ def load_config_file(config_file): 'track': 'track', 'notopic': 'notopic', 'usepushurl': 'usepushurl', + 'branchauthor': 'branchauthor', } config = {} for config_key, option_name in options.items(): @@ -1200,7 +1202,8 @@ def fetch_review(review, masterbranch, remote, project): except KeyError: topic = review try: - author = re.sub(r'\W+', '_', review_info['owner']['name']).lower() + author = re.sub(r'\W+', '_', + review_info['owner'][BRANCHAUTHOR]).lower() except KeyError: author = 'unknown' remote_branch = review_info['branch'] @@ -1413,7 +1416,19 @@ git-review is a tool that helps submitting git branches to gerrit for review. """ - parser = argparse.ArgumentParser(usage=usage, description=description) + epilog = """\ +additional information: + + Options configurable using: git config --global gitreview.OPTION VALUE + + branchauthor name (default), username, email +""" + + parser = argparse.ArgumentParser( + usage=usage, + description=description, + formatter_class=argparse.RawDescriptionHelpFormatter, + epilog=epilog) topic_arg_group = parser.add_mutually_exclusive_group() topic_arg_group.add_argument("-t", "--topic", dest="topic", @@ -1607,6 +1622,13 @@ review. yes = options.yes status = 0 + global BRANCHAUTHOR + BRANCHAUTHOR = config['branchauthor'] + if BRANCHAUTHOR not in ["name", "email", "username"]: + warn("Invalid gitreview.branchauthor: %s (using default: %s)" + % (BRANCHAUTHOR, DEFAULTS["branchauthor"])) + BRANCHAUTHOR = DEFAULTS["branchauthor"] + if options.track: remote, branch = resolve_tracking(remote, branch)