X-Git-Url: http://rtime.felk.cvut.cz/gitweb/notmuch.git/blobdiff_plain/2ec4ea610c2f4202f36b4267173e3cff2ec1bd21..f7a7f78aebd7f0571cad7f4813ef18dac5247c73:/devel/nmbug/nmbug diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index befc3d90..b9c70e4b 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -15,9 +15,6 @@ $NMBGIT .= '/.git' if (-d $NMBGIT.'/.git'); my $TAGPREFIX = $ENV{NMBPREFIX} || 'notmuch::'; -# magic hash for git -my $EMPTYBLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'; - # for encoding my $ESCAPE_CHAR = '%'; @@ -50,6 +47,9 @@ if (!exists $command{$subcommand}) { usage (); } +# magic hash for git +my $EMPTYBLOB = git (qw{hash-object -t blob /dev/null}); + &{$command{$subcommand}}(@ARGV); sub git_pipe { @@ -267,6 +267,20 @@ sub do_checkout { do_sync (action => 'checkout'); } +sub quote_for_xapian { + my $str = shift; + $str =~ s/"/""/g; + return '"' . $str . '"'; +} + +sub pair_to_batch_line { + my ($action, $pair) = @_; + + # the tag should already be suitably encoded + + return $action . $ENCPREFIX . $pair->{tag} . + ' -- id:' . quote_for_xapian ($pair->{id})."\n"; +} sub do_sync { @@ -283,17 +297,20 @@ sub do_sync { $D_action = '-'; } - foreach my $pair (@{$status->{added}}) { + my $notmuch = spawn ({}, '|-', qw/notmuch tag --batch/) + or die 'notmuch tag --batch'; - notmuch ('tag', $A_action.$TAGPREFIX.$pair->{tag}, - 'id:'.$pair->{id}); + foreach my $pair (@{$status->{added}}) { + print $notmuch pair_to_batch_line ($A_action, $pair); } foreach my $pair (@{$status->{deleted}}) { - notmuch ('tag', $D_action.$TAGPREFIX.$pair->{tag}, - 'id:'.$pair->{id}); + print $notmuch pair_to_batch_line ($D_action, $pair); } + unless (close $notmuch) { + die "'notmuch tag --batch' exited with nonzero value\n"; + } }