[PATCH 1/5] Fix lookups for uncommitted keys
Konstantin Ryabitsev <[email protected]> Thu, 3 Jun 2021 13:18:11 -0400
| Newsgroups | org.kernel.lore.signatures |
|---|---|
| Message-ID | <7754d7d35d03b462109c4a93d625f0af21383312.1622740672.git.konstantin.ryabitsev@linux.dev> |
Fix for the case when a key is added the repository but hasn't been committed yet -- we were looking for it in the wrong subpath. Signed-off-by: Konstantin Ryabitsev <[email protected]> --- patatt/__init__.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/patatt/__init__.py b/patatt/__init__.py index 9602392..460d282 100644 --- a/patatt/__init__.py +++ b/patatt/__init__.py @@ -47,7 +47,7 @@ OPT_HDRS = [b'message-id'] KEYCACHE = dict() # My version -__VERSION__ = '0.4.3' +__VERSION__ = '0.4.4' MAX_SUPPORTED_FORMAT_VERSION = 1 @@ -723,19 +723,21 @@ def get_public_key(source: str, keytype: str, identity: str, selector: str) -> T parts = source.split(':', 4) if len(parts) < 4: raise ConfigurationError('Invalid ref, must have at least 3 colons: %s' % source) - gittop = parts[1] + gitrepo = parts[1] gitref = parts[2] gitsub = parts[3] - if not gittop: - gittop = get_git_toplevel() - if not gittop: - raise KeyError('Not in a git tree, so cannot use a ref: source') - - gittop = os.path.expanduser(gittop) - if gittop.find('$') >= 0: - gittop = os.path.expandvars(gittop) - if os.path.isdir(os.path.join(gittop, '.git')): - gittop = os.path.join(gittop, '.git') + if not gitrepo: + gitrepo = get_git_toplevel() + if not gitrepo: + raise KeyError('Not in a git tree, so cannot use a ref:: source') + + gitrepo = os.path.expanduser(gitrepo) + if gitrepo.find('$') >= 0: + gitrepo = os.path.expandvars(gitrepo) + if os.path.isdir(os.path.join(gitrepo, '.git')): + gittop = os.path.join(gitrepo, '.git') + else: + gittop = gitrepo # it could omit the refspec, meaning "whatever the current ref" # grab the key from a fully ref'ed path @@ -767,8 +769,8 @@ def get_public_key(source: str, keytype: str, identity: str, selector: str) -> T logger.debug('KEYSRC : %s', keysrc) return out, 'ref:%s:%s' % (gittop, keysrc) - # Does it exist on disk in gittop? - fullpath = os.path.join(gittop, subpath) + # Does it exist on disk but hasn't been committed yet? + fullpath = os.path.join(gitrepo, subpath) if os.path.exists(fullpath): with open(fullpath, 'rb') as fh: logger.debug('KEYSRC : %s', fullpath) -- 2.31.1