From: Tomi Ollila Date: Thu, 21 Feb 2013 08:30:47 +0000 (+0200) Subject: Re: [Patch v2 1/4] nmbug: use dump --format=batch-tag X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=edcb322173af5c7b0e3615ffff17a4ec34c4119c;p=notmuch-archives.git Re: [Patch v2 1/4] nmbug: use dump --format=batch-tag --- diff --git a/b6/d8b4aa41ee645e49b9f44be2324416f88bcc7b b/b6/d8b4aa41ee645e49b9f44be2324416f88bcc7b new file mode 100644 index 000000000..f0479dd8d --- /dev/null +++ b/b6/d8b4aa41ee645e49b9f44be2324416f88bcc7b @@ -0,0 +1,166 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 7CC48431FB6 + for ; Thu, 21 Feb 2013 00:31:04 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id bX7j-rko0Q7g for ; + Thu, 21 Feb 2013 00:31:00 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 485F2431FAE + for ; Thu, 21 Feb 2013 00:31:00 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 9CD8510014F; + Thu, 21 Feb 2013 10:30:47 +0200 (EET) +From: Tomi Ollila +To: david@tethera.net, notmuch@notmuchmail.org +Subject: Re: [Patch v2 1/4] nmbug: use dump --format=batch-tag +In-Reply-To: <1361399077-7737-2-git-send-email-david@tethera.net> +References: <1361399077-7737-1-git-send-email-david@tethera.net> + <1361399077-7737-2-git-send-email-david@tethera.net> +User-Agent: Notmuch/0.15.2+41~g0ce9bd4 (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +Cc: David Bremner +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 21 Feb 2013 08:31:04 -0000 + +On Thu, Feb 21 2013, david@tethera.net wrote: + +> From: David Bremner +> +> 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. + +This patch series looks good to me (as far as I can understand, I did +not find the "silly bug" in your previous patch...) + +Instead of mentioning that "calls are _not_ passed to shell" here, +that could be briefly mentioned just before system() calls in the +script -- and that definitely should not be 'At the moment' feature. + +the system() function in perl(1) never pass execution through the +shell in case the args are list more than one arg: + +1 $ perl -e 'system( qw/echo |cat; echo second line ?/ )' +|cat; echo second line ? + +2 $ perl -le 'system( qw/echo| cat;/ ); print "system: ",$!' +system: No such file or directory + +3 $ perl -le 'system( qw/echo|/ ); print "system: ",$!' +sh: -c: line 1: syntax error: unexpected end of file +system: + +execve calls to the above could have been: + +1: execve( "/bin/echo" [ "echo" "|cat;" "echo" "second" "line" "?" ] ) + +2: no execve: perl(1) did not find 'echo|' in the PATH + +3: execve( "/bin/sh" [ "sh" "-c" "echo|" ] ) + +Tomi + +> --- +> devel/nmbug/nmbug | 27 ++++++++++++++++++++------- +> 1 file changed, 20 insertions(+), 7 deletions(-) +> +> diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug +> index fe103b3..befc3d9 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; +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch