mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-28 21:54:10 +01:00
nmbug: use 'notmuch tag --batch'
This should be more robust with respect to tags with whitespace and and other special characters. It also (hopefully) fixes a remaining bug handling message-ids with whitespace. It should also be noticeably faster for large sets of changes since it does one exec per change set as opposed to one exec per tag changed.
This commit is contained in:
parent
2ec4ea610c
commit
17b468ac9f
1 changed files with 22 additions and 5 deletions
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue