diff options
author | David Bremner <bremner@debian.org> | 2013-02-20 18:24:34 -0400 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2013-03-02 10:42:06 -0400 |
commit | 2ec4ea610c2f4202f36b4267173e3cff2ec1bd21 (patch) | |
tree | d1f68a40882a356b1b4622211144ae81d856fb45 /devel | |
parent | d6d3fa32f6b1491f84f44184c8c1e590656a2001 (diff) |
nmbug: use dump --format=batch-tag
This should make nmbug tolerate tags with whitespace and other special
characters it. At the moment this relies on _not_ passing calls to
notmuch tag through the shell, which is a documented feature of perl's
system function.
Diffstat (limited to 'devel')
-rwxr-xr-x | devel/nmbug/nmbug | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index fe103b3b..befc3d90 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -39,6 +39,11 @@ my %command = ( status => \&do_status, ); +# Convert prefix into form suitable for literal matching against +# notmuch dump --format=batch-tag output. +my $ENCPREFIX = encode_for_fs ($TAGPREFIX); +$ENCPREFIX =~ s/:/%3a/g; + my $subcommand = shift || usage (); if (!exists $command{$subcommand}) { @@ -203,9 +208,9 @@ sub index_tags { my $index = $NMBGIT.'/nmbug.index'; - my $query = join ' ', map ("tag:$_", get_tags ($TAGPREFIX)); + my $query = join ' ', map ("tag:\"$_\"", get_tags ($TAGPREFIX)); - my $fh = spawn ('-|', qw/notmuch dump --/, $query) + my $fh = spawn ('-|', qw/notmuch dump --format=batch-tag --/, $query) or die "notmuch dump: $!"; git ('read-tree', '--empty'); @@ -214,22 +219,30 @@ sub index_tags { or die 'git update-index'; while (<$fh>) { - m/ ( [^ ]* ) \s+ \( ([^\)]* ) \) /x || die 'syntax error in dump'; - my ($id,$rest) = ($1,$2); - #strip prefixes before writing - my @tags = grep { s/^$TAGPREFIX//; } split (' ', $rest); + chomp(); + my ($rest,$id) = split(/ -- id:/); + + if ($id =~ s/^"(.*)"\s*$/$1/) { + # xapian quoted string, dequote. + $id =~ s/""/"/g; + } + + #strip prefixes from tags before writing + my @tags = grep { s/^[+]$ENCPREFIX//; } split (' ', $rest); index_tags_for_msg ($git,$id, 'A', @tags); } unless (close $git) { die "'git update-index --index-info' exited with nonzero value\n"; } unless (close $fh) { - die "'notmuch dump -- $query' exited with nonzero value\n"; + die "'notmuch dump --format=batch-tag -- $query' exited with nonzero value\n"; } return $index; } +# update the git index to either create or delete an empty file. +# Neither argument should be encoded/escaped. sub index_tags_for_msg { my $fh = shift; my $msgid = shift; |