parallel: added --tagstring + man + test.

parallel.pod: Elaborated on problems with -u.
This commit is contained in:
Ole Tange 2012-05-06 12:43:40 +02:00
parent 944cfd0026
commit 29726eee6e
5 changed files with 78 additions and 15 deletions

View file

@ -705,6 +705,9 @@ sub parse_options {
$Global::replace{$_} = ::maybe_quote($Global::replace{$_}); $Global::replace{$_} = ::maybe_quote($Global::replace{$_});
} }
%Global::replace_rev = reverse %Global::replace; %Global::replace_rev = reverse %Global::replace;
if(defined $::opt_tag and not defined $::opt_tagstring) {
$::opt_tagstring = $Global::replace{'{}'};
}
if(grep /^$Global::arg_sep$|^$Global::arg_file_sep$/o, @ARGV) { if(grep /^$Global::arg_sep$|^$Global::arg_file_sep$/o, @ARGV) {
# Deal with ::: and :::: # Deal with ::: and ::::
@ -3728,13 +3731,8 @@ sub print {
sub tag { sub tag {
my $self = shift; my $self = shift;
if(not defined $self->{'tag'}) { if(not defined $self->{'tag'}) {
$self->{'tag'} = ""; $self->{'tag'} = $self->{'commandline'}->
if(defined $::opt_tagstring) { replace_placeholders($::opt_tagstring,0)."\t";
$self->{'tag'} .= $::opt_tagstring."\t";
}
if(defined $::opt_tag) {
$self->{'tag'} .= $self->{'commandline'}->args_as_string()."\t";
}
} }
return $self->{'tag'}; return $self->{'tag'};
} }
@ -3798,9 +3796,20 @@ sub new {
# Add {} to the command if there are no {...}'s # Add {} to the command if there are no {...}'s
$command .=" ".$Global::replace{'{}'}; $command .=" ".$Global::replace{'{}'};
} }
}
($sum,$len->{'no_args'},$len->{'context'},$len->{'contextgroups'}, ($sum,$len->{'no_args'},$len->{'context'},$len->{'contextgroups'},
%replacecount) = number_of_replacements($command,$context_replace); %replacecount) = number_of_replacements($command,$context_replace);
}
if(defined $::opt_tagstring) {
my ($dummy1,$dummy2,$dummy3,$dummy4,%repcount) =
number_of_replacements($::opt_tagstring,$context_replace);
# Merge %repcount with %replacecount to get the keys
# for replacing replacement strings in $::opt_tagstring
# The number, however, does not matter.
for (keys %repcount) {
$replacecount{$_} ||= 0;
}
}
my %positional_replace; my %positional_replace;
my %multi_replace; my %multi_replace;
for my $used (keys %replacecount) { for my $used (keys %replacecount) {

View file

@ -1200,6 +1200,15 @@ the lines will be prepended with the sshlogin instead.
B<--tag> is ignored when using B<-u>. B<--tag> is ignored when using B<-u>.
=item B<--tagstring> I<str>
Tag lines with a string. Each output line will be prepended with
I<str> and TAB (\t). I<str> can contain replacement strings such as
{}.
B<--tagstring> is ignored when using B<-u>, B<--onall>, and B<--nonall>.
=item B<--tmpdir> I<dirname> =item B<--tmpdir> I<dirname>
Directory for temporary files. GNU B<parallel> normally buffers output Directory for temporary files. GNU B<parallel> normally buffers output
@ -1295,9 +1304,16 @@ a bc " -> "a bc". This is the default if B<--colsep> is used.
=item B<-u> =item B<-u>
Ungroup output. Output is printed as soon as possible. This may cause Ungroup output. Output is printed as soon as possible and by passes
output from different commands to be mixed. GNU B<parallel> runs GNU B<parallel> internal processing. This may cause
faster with B<-u>. Can be reversed with B<--group>. output from different commands to be mixed. Compare these:
B<parallel -j0 'sleep {};echo -n start{};sleep {};echo {}end' ::: 1 2 3 4>
B<parallel -u -j0 'sleep {};echo -n start{};sleep {};echo {}end' ::: 1 2 3 4>
It also disables B<--tag>. GNU B<parallel> runs faster with B<-u>. Can
be reversed with B<--group>.
=item B<--extensionreplace> I<replace-str> =item B<--extensionreplace> I<replace-str>

View file

@ -1279,6 +1279,15 @@ the lines will be prepended with the sshlogin instead.
@strong{--tag} is ignored when using @strong{-u}. @strong{--tag} is ignored when using @strong{-u}.
@item @strong{--tagstring} @emph{str}
@anchor{@strong{--tagstring} @emph{str}}
Tag lines with a string. Each output line will be prepended with
@emph{str} and TAB (\t). @emph{str} can contain replacement strings such as
@{@}.
@strong{--tagstring} is ignored when using @strong{-u}, @strong{--onall}, and @strong{--nonall}.
@item @strong{--tmpdir} @emph{dirname} @item @strong{--tmpdir} @emph{dirname}
@anchor{@strong{--tmpdir} @emph{dirname}} @anchor{@strong{--tmpdir} @emph{dirname}}
@ -1385,9 +1394,16 @@ a bc " -> "a bc". This is the default if @strong{--colsep} is used.
@item @strong{-u} @item @strong{-u}
@anchor{@strong{-u}} @anchor{@strong{-u}}
Ungroup output. Output is printed as soon as possible. This may cause Ungroup output. Output is printed as soon as possible and by passes
output from different commands to be mixed. GNU @strong{parallel} runs GNU @strong{parallel} internal processing. This may cause
faster with @strong{-u}. Can be reversed with @strong{--group}. output from different commands to be mixed. Compare these:
@strong{parallel -j0 'sleep @{@};echo -n start@{@};sleep @{@};echo @{@}end' ::: 1 2 3 4}
@strong{parallel -u -j0 'sleep @{@};echo -n start@{@};sleep @{@};echo @{@}end' ::: 1 2 3 4}
It also disables @strong{--tag}. GNU @strong{parallel} runs faster with @strong{-u}. Can
be reversed with @strong{--group}.
@item @strong{--extensionreplace} @emph{replace-str} @item @strong{--extensionreplace} @emph{replace-str}
@anchor{@strong{--extensionreplace} @emph{replace-str}} @anchor{@strong{--extensionreplace} @emph{replace-str}}

View file

@ -2,3 +2,10 @@
echo '### Test fix #32191' echo '### Test fix #32191'
seq 1 150 | parallel -j9 --retries 2 -S localhost,: "/bin/non-existant 2>/dev/null" seq 1 150 | parallel -j9 --retries 2 -S localhost,: "/bin/non-existant 2>/dev/null"
echo '### Test --tagstring'
parallel -j1 -X -v --tagstring a{}b echo ::: 3 4
parallel -j1 -k -v --tagstring a{}b echo ::: 3 4
parallel -j1 -k -v --tagstring a{}b echo job{#} ::: 3 4
parallel -j1 -k -v --tagstring ajob{#}b echo job{#} ::: 3 4

View file

@ -1 +1,16 @@
### Test fix #32191 ### Test fix #32191
### Test --tagstring
echo 3 4
a3b a4b 3 4
echo 3
a3b 3
echo 4
a4b 4
echo job1
a3b job1
echo job2
a4b job2
echo job1
ajob1b job1
echo job2
ajob2b job2