nmbug: Only error for invalid diff lines in tags/

Avoid:

  Traceback (most recent call last):
    File "/home/nmbug/bin/nmbug", line 834, in <module>
      args.func(**kwargs)
    File "/home/nmbug/bin/nmbug", line 385, in checkout
      status = get_status()
    File "/home/nmbug/bin/nmbug", line 580, in get_status
      maybe_deleted = _diff_index(index=index, filter='D')
    File "/home/nmbug/bin/nmbug", line 658, in _diff_index
      for id, tag in _unpack_diff_lines(stream=p.stdout):
    File "/home/nmbug/bin/nmbug", line 678, in _unpack_diff_lines
      'Invalid line in diff: {!r}'.format(line.strip()))
  ValueError: Invalid line in diff: u'.mailmap'

With this commit, folks can commit READMEs, .mailmap, etc. to their
nmbug repositories, and 'nmbug diff' and 'status' won't choke on them.
If you want to check for this sort of thing, you can set --log-level
to info or greater.  nmbug will still error if the unrecognized path
is under tags/, since that's more likely to be a user error.
This commit is contained in:
W. Trevor King 2017-10-16 11:01:47 -07:00 committed by David Bremner
parent 7354d6d8f6
commit 572259885a

View file

@ -65,7 +65,8 @@ if _os.path.isdir(_NMBGIT):
TAG_PREFIX = _os.getenv('NMBPREFIX', 'notmuch::') TAG_PREFIX = _os.getenv('NMBPREFIX', 'notmuch::')
_HEX_ESCAPE_REGEX = _re.compile('%[0-9A-F]{2}') _HEX_ESCAPE_REGEX = _re.compile('%[0-9A-F]{2}')
_TAG_FILE_REGEX = _re.compile('tags/(?P<id>[^/]*)/(?P<tag>[^/]*)') _TAG_DIRECTORY = 'tags/'
_TAG_FILE_REGEX = _re.compile(_TAG_DIRECTORY + '(?P<id>[^/]*)/(?P<tag>[^/]*)')
# magic hash for Git (git hash-object -t blob /dev/null) # magic hash for Git (git hash-object -t blob /dev/null)
_EMPTYBLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' _EMPTYBLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
@ -683,8 +684,11 @@ def _unpack_diff_lines(stream):
for line in stream: for line in stream:
match = _TAG_FILE_REGEX.match(line.strip()) match = _TAG_FILE_REGEX.match(line.strip())
if not match: if not match:
raise ValueError( message = 'non-tag line in diff: {!r}'.format(line.strip())
'Invalid line in diff: {!r}'.format(line.strip())) if line.startswith(_TAG_DIRECTORY):
raise ValueError(message)
_LOG.info(message)
continue
id = _unquote(match.group('id')) id = _unquote(match.group('id'))
tag = _unquote(match.group('tag')) tag = _unquote(match.group('tag'))
yield (id, tag) yield (id, tag)