unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: david@tethera.net, notmuch@notmuchmail.org
Cc: David Bremner <bremner@debian.org>
Subject: Re: [Patch v2 1/4] nmbug: use dump --format=batch-tag
Date: Thu, 21 Feb 2013 10:30:47 +0200	[thread overview]
Message-ID: <m27gm2ax1k.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <1361399077-7737-2-git-send-email-david@tethera.net>

On Thu, Feb 21 2013, david@tethera.net wrote:

> From: David Bremner <bremner@debian.org>
>
> 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

  reply	other threads:[~2013-02-21  8:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-20 22:24 Update for nmbug, round 2 david
2013-02-20 22:24 ` [Patch v2 1/4] nmbug: use dump --format=batch-tag david
2013-02-21  8:30   ` Tomi Ollila [this message]
2013-02-21 11:52     ` David Bremner
2013-02-21 12:22       ` Tomi Ollila
2013-02-20 22:24 ` [Patch v2 2/4] nmbug: use 'notmuch tag --batch' david
2013-02-20 22:24 ` [Patch v2 3/4] nmbug: replace hard-coded magic hash with git-hash-object david
2013-02-20 22:24 ` [Patch v2 4/4] nmbug: allow empty prefix david
2013-02-27  8:53 ` Update for nmbug, round 2 Tomi Ollila
2013-02-27 11:59   ` David Bremner
2013-03-02 14:51     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m27gm2ax1k.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=bremner@debian.org \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).