From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cMVaARiVm2KBzAAAbAwnHQ (envelope-from ) for ; Sat, 04 Jun 2022 19:23:36 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id aLRqABiVm2LjpwAAG6o9tA (envelope-from ) for ; Sat, 04 Jun 2022 19:23:36 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 519123E34D for ; Sat, 4 Jun 2022 19:23:35 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 743755F7C5; Sat, 4 Jun 2022 17:23:31 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 3682C5F7AE for ; Sat, 4 Jun 2022 17:23:29 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 66F665FBD7; Sat, 4 Jun 2022 13:23:28 -0400 (EDT) Received: (nullmailer pid 1150071 invoked by uid 1000); Sat, 04 Jun 2022 17:23:25 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH v3 07/17] CLI/git: rename environment variables. Date: Sat, 4 Jun 2022 14:23:03 -0300 Message-Id: <20220604172313.1149879-8-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220604172313.1149879-1-david@tethera.net> References: <20220604172313.1149879-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ZTOTIQ5APRO2V2FT6CBX4NOAASNUAC2D X-Message-ID-Hash: ZTOTIQ5APRO2V2FT6CBX4NOAASNUAC2D X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654363415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=SkSt9n90Ua0od7XBV2quiNhvgj1vr8mCwqYuNIVfk0Q=; b=MEucKfNPTnvpMqDajfNKrI/BUQOwPYQL2lVHSvkBkG/j9c+0hw/rIJ3OcKLDwLVrQ+309K LJfllDQfuzdf+2il2329ZInw36Dbj/cIxFhIt7BHZUKIrW7AprKJcSYWbJD37RY1pXIMLT 3qMEReM2F16xBWhjb0mNsjRVmcOb5iDiNDJdtObIwJ4uSO7f5/DrOka0K3m0fpHEis6qSn P7rMHH8CzNd616UJ4uZldqSkrkCuTq04x3dvWOrlSfOQBVXLNPead7c2zMxK6O4P34tNlF gYTgZeurZtr46nc05cqeBXnrOb1njhynxoSHJDJ7zfb7CGujFYheQLa2EBQ9YA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654363415; a=rsa-sha256; cv=none; b=OkImCGEr4avAh9ms7H2HpZG5GYwF2DrEB/B3bzFx3To2fhLNQ8WV12cipUS/CqZ1zTmPGP nvYqG1cMivZh6ZlGh8X54giPcmi8aaZX4E3DcQa7sinlCdGxtHNvnpzD2r+VkoG3qGzDC5 I7tyOoNsNpj4cj2E2BDeXX/NF1UOaTTJWKMiuSHLkZR0e1Hy/e+6czd/G+ZJyqaBcVVJuB C2d69S+86OzI9mr1om1hl5LeUWYoJrW4vuUHsvLJUKK5Osommmrg2NMykxkj5Y2HyswLQh clmV68Uq7ShxNi67Nq+EsHQ+xdkzwRCd70q58Nq17GjxyGAJ9S+upaM3L53OKg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.05 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 519123E34D X-Spam-Score: -1.05 X-Migadu-Scanner: scn1.migadu.com X-TUID: +ieWFfdBA0HB Although the code required to support both new and old environment variables is small, it complicates the semantics of configuration, and make the documentation harder to follow. --- notmuch-git.py | 35 ++++++++++++++--------------------- test/T850-git.sh | 6 +++--- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/notmuch-git.py b/notmuch-git.py index 5475d0db..f3ad6927 100644 --- a/notmuch-git.py +++ b/notmuch-git.py @@ -18,13 +18,6 @@ """ Manage notmuch tags with Git - -Environment variables: - -* NMBGIT specifies the location of the git repository used by nmbug. - If not specified $HOME/.nmbug is used. -* NMBPREFIX specifies the prefix in the notmuch database for tags of - interest to nmbug. If not specified 'notmuch::' is used. """ from __future__ import print_function @@ -50,7 +43,7 @@ _LOG = _logging.getLogger('nmbug') _LOG.setLevel(_logging.WARNING) _LOG.addHandler(_logging.StreamHandler()) -NMBGIT = None +NOTMUCH_GIT_DIR = None TAG_PREFIX = None _HEX_ESCAPE_REGEX = _re.compile('%[0-9A-F]{2}') @@ -198,7 +191,7 @@ def _spawn(args, input=None, additional_env=None, wait=False, stdin=None, def _git(args, **kwargs): - args = ['git', '--git-dir', NMBGIT] + list(args) + args = ['git', '--git-dir', NOTMUCH_GIT_DIR] + list(args) return _spawn(args=args, **kwargs) @@ -266,7 +259,7 @@ def clone(repository): with _tempfile.TemporaryDirectory(prefix='nmbug-clone.') as workdir: _spawn( args=[ - 'git', 'clone', '--no-checkout', '--separate-git-dir', NMBGIT, + 'git', 'clone', '--no-checkout', '--separate-git-dir', NOTMUCH_GIT_DIR, repository, workdir], wait=True) _git(args=['config', '--unset', 'core.worktree'], wait=True, expect=(0, 5)) @@ -358,7 +351,7 @@ def init(remote=None): This wraps 'git init' with a few extra steps to support subsequent status and commit commands. """ - _spawn(args=['git', '--git-dir', NMBGIT, 'init', '--bare'], wait=True) + _spawn(args=['git', '--git-dir', NOTMUCH_GIT_DIR, 'init', '--bare'], wait=True) _git(args=['config', 'core.logallrefupdates', 'true'], wait=True) # create an empty blob (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391) _git(args=['hash-object', '-w', '--stdin'], input='', wait=True) @@ -366,7 +359,7 @@ def init(remote=None): args=[ 'commit', '--allow-empty', '-m', 'Start a new nmbug repository' ], - additional_env={'GIT_WORK_TREE': NMBGIT}, + additional_env={'GIT_WORK_TREE': NOTMUCH_GIT_DIR}, wait=True) @@ -589,7 +582,7 @@ def get_status(): def _index_tags(): "Write notmuch tags to the nmbug.index." - path = _os.path.join(NMBGIT, 'nmbug.index') + path = _os.path.join(NOTMUCH_GIT_DIR, 'nmbug.index') query = ' '.join('tag:"{tag}"'.format(tag=tag) for tag in get_tags()) prefix = '+{0}'.format(_ENCODED_TAG_PREFIX) _git( @@ -708,7 +701,7 @@ if __name__ == '__main__': help='Git repository to operate on.') parser.add_argument( '-p', '--tag-prefix', metavar='PREFIX', - default = _os.getenv('NMBPREFIX', 'notmuch::'), + default = _os.getenv('NOTMUCH_GIT_PREFIX', 'notmuch::'), help='Prefix of tags to operate on.') parser.add_argument( '-l', '--log-level', @@ -821,13 +814,13 @@ if __name__ == '__main__': args = parser.parse_args() if args.git_dir: - NMBGIT = args.git_dir + NOTMUCH_GIT_DIR = args.git_dir else: - NMBGIT = _os.path.expanduser( - _os.getenv('NMBGIT', _os.path.join('~', '.nmbug'))) - _NMBGIT = _os.path.join(NMBGIT, '.git') - if _os.path.isdir(_NMBGIT): - NMBGIT = _NMBGIT + NOTMUCH_GIT_DIR = _os.path.expanduser( + _os.getenv('NOTMUCH_GIT_DIR', _os.path.join('~', '.nmbug'))) + _NOTMUCH_GIT_DIR = _os.path.join(NOTMUCH_GIT_DIR, '.git') + if _os.path.isdir(_NOTMUCH_GIT_DIR): + NOTMUCH_GIT_DIR = _NOTMUCH_GIT_DIR TAG_PREFIX = args.tag_prefix _ENCODED_TAG_PREFIX = _hex_quote(TAG_PREFIX, safe='+@=,') # quote ':' @@ -837,7 +830,7 @@ if __name__ == '__main__': _LOG.setLevel(level) # for test suite - for var in ['NMBGIT', 'NMBPREFIX', 'NOTMUCH_PROFILE', 'NOTMUCH_CONFIG' ]: + for var in ['NOTMUCH_GIT_DIR', 'NOTMUCH_GIT_PREFIX', 'NOTMUCH_PROFILE', 'NOTMUCH_CONFIG' ]: _LOG.debug('env {:s} = {:s}'.format(var, _os.getenv(var,'%None%'))) if not getattr(args, 'func', None): diff --git a/test/T850-git.sh b/test/T850-git.sh index 713b326f..994950ed 100755 --- a/test/T850-git.sh +++ b/test/T850-git.sh @@ -80,11 +80,11 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "environment passed through when run as 'notmuch git'" -env NMBGIT=foo NMBPREFIX=bar NOTMUCH_PROFILE=default notmuch git -C tags.git -p '' -ldebug status |& \ +env NOTMUCH_GIT_DIR=foo NOTMUCH_GIT_PREFIX=bar NOTMUCH_PROFILE=default notmuch git -C tags.git -p '' -ldebug status |& \ grep '^env ' | notmuch_dir_sanitize > OUTPUT cat < EXPECTED -env NMBGIT = foo -env NMBPREFIX = bar +env NOTMUCH_GIT_DIR = foo +env NOTMUCH_GIT_PREFIX = bar env NOTMUCH_PROFILE = default env NOTMUCH_CONFIG = CWD/notmuch-config EOF -- 2.35.2