X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=devel%2Fnmbug%2Fnmbug;h=043c186369c1f55fce114b230746f138d7bc2345;hb=144cf30e2c71d57795b5fbdec10af0ef73aa01ff;hp=1dd5f14fe7b4dbaf01a4fdfbd1d5332ae15b983a;hpb=07dff496304d6dc2e8033a18691b095ed9cd212f;p=notmuch diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index 1dd5f14f..043c1863 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Copyright (c) 2011-2014 David Bremner # W. Trevor King @@ -51,10 +51,10 @@ except ImportError: # Python 2 from urllib import unquote as _unquote -__version__ = '0.2' +__version__ = '0.3' _LOG = _logging.getLogger('nmbug') -_LOG.setLevel(_logging.ERROR) +_LOG.setLevel(_logging.WARNING) _LOG.addHandler(_logging.StreamHandler()) NMBGIT = _os.path.expanduser( @@ -65,7 +65,8 @@ if _os.path.isdir(_NMBGIT): TAG_PREFIX = _os.getenv('NMBPREFIX', 'notmuch::') _HEX_ESCAPE_REGEX = _re.compile('%[0-9A-F]{2}') -_TAG_FILE_REGEX = _re.compile('tags/(?P[^/]*)/(?P[^/]*)') +_TAG_DIRECTORY = 'tags/' +_TAG_FILE_REGEX = _re.compile(_TAG_DIRECTORY + '(?P[^/]*)/(?P[^/]*)') # magic hash for Git (git hash-object -t blob /dev/null) _EMPTYBLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' @@ -169,8 +170,9 @@ class _SubprocessContextManager(object): stream.close() setattr(self._process, name, None) status = self._process.wait() - _LOG.debug('collect {args} with status {status}'.format( - args=self._args, status=status)) + _LOG.debug( + 'collect {args} with status {status} (expected {expect})'.format( + args=self._args, status=status, expect=self._expect)) if status not in self._expect: raise SubprocessError(args=self._args, status=status) @@ -211,13 +213,14 @@ def _spawn(args, input=None, additional_env=None, wait=False, stdin=None, input = input.encode(encoding) (stdout, stderr) = p.communicate(input=input) status = p.wait() - _LOG.debug('collect {args} with status {status}'.format( - args=args, status=status)) + _LOG.debug( + 'collect {args} with status {status} (expected {expect})'.format( + args=args, status=status, expect=expect)) if stdout is not None: stdout = stdout.decode(encoding) if stderr is not None: stderr = stderr.decode(encoding) - if status: + if status not in expect: raise SubprocessError( args=args, status=status, stdout=stdout, stderr=stderr) return (status, stdout, stderr) @@ -306,9 +309,16 @@ def clone(repository): 'git', 'clone', '--no-checkout', '--separate-git-dir', NMBGIT, repository, workdir], wait=True) - _git(args=['config', '--unset', 'core.worktree'], wait=True) + _git(args=['config', '--unset', 'core.worktree'], wait=True, expect=(0, 5)) _git(args=['config', 'core.bare', 'true'], wait=True) _git(args=['branch', 'config', 'origin/config'], wait=True) + existing_tags = get_tags() + if existing_tags: + _LOG.warning( + 'Not checking out to avoid clobbering existing tags: {}'.format( + ', '.join(existing_tags))) + else: + checkout() def _is_committed(status): @@ -475,7 +485,7 @@ def log(args=()): 'nmbug log HEAD..@{upstream}'. """ # we don't want output trapping here, because we want the pager. - args = ['log', '--name-status'] + list(args) + args = ['log', '--name-status', '--no-renames'] + list(args) with _git(args=args, expect=(0, 1, -13)) as p: p.wait() @@ -674,8 +684,11 @@ def _unpack_diff_lines(stream): for line in stream: match = _TAG_FILE_REGEX.match(line.strip()) if not match: - raise ValueError( - 'Invalid line in diff: {!r}'.format(line.strip())) + message = 'non-tag line in diff: {!r}'.format(line.strip()) + if line.startswith(_TAG_DIRECTORY): + raise ValueError(message) + _LOG.info(message) + continue id = _unquote(match.group('id')) tag = _unquote(match.group('tag')) yield (id, tag)