master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
25package getpart;
27use strict;
28use warnings;
30BEGIN {
31 use base qw(Exporter);
33 our @EXPORT = qw(
34 compareparts
35 fulltest
36 checktest
37 getpart
38 getpartattr
39 loadarray
40 loadtest
41 partexists
42 striparray
43 writearray
44 );
45}
47use Memoize qw(memoize flush_cache);
49my @xml; # test data file contents
50my $xmlfile; # test data filename
52my $warning = 0;
53my $trace = 0;
55# Normalize the part function arguments for proper caching. This includes the
56# filename in the arguments since that is an implied parameter that affects the
57# return value. Any error messages are only displayed the first time, but
58# those are disabled by default anyway, so should never been seen outside
59# development.
60sub normalize_part {
61 push @_, $xmlfile;
62 return join("\t", @_);
63}
65sub testcaseattr {
66 my %hash;
67 for(@xml) {
68 if(($_ =~ /^ *\<testcase ([^>]*)/)) {
69 my $attr = $1;
70 while($attr =~ s/ *([^=]*)= *(\"([^\"]*)\"|\'([^\']*)\')//) {
71 my ($var, $cont) = ($1, $2);
72 $cont =~ s/^\"(.*)\"$/$1/;
73 $cont =~ s/^\'(.*)\'$/$1/;
74 $hash{$var} = $cont;
75 }
76 }
77 }
78 return %hash;
79}
81sub getpartattr {
82 # if $part is undefined (ie only one argument) then
83 # return the attributes of the section
85 my ($section, $part) = @_;
87 my %hash;
88 my $inside = 0;
90 # print "Section: $section, part: $part\n";
92 for(@xml) {
93 # print "$inside: $_";
94 if(!$inside && ($_ =~ /^ *\<$section/)) {
95 $inside++;
96 }
97 if((1 == $inside) && (($_ =~ /^ *\<$part ([^>]*)/) ||
98 !(defined($part)))
99 ) {
100 $inside++;
101 my $attr = $1;
103 while($attr =~ s/ *([^=]*)= *(\"([^\"]*)\"|\'([^\']*)\')//) {
104 my ($var, $cont) = ($1, $2);
105 $cont =~ s/^\"(.*)\"$/$1/;
106 $cont =~ s/^\'(.*)\'$/$1/;
107 $hash{$var} = $cont;
108 }
109 last;
110 }
111 # detect end of section when part was not found
112 elsif((1 == $inside) && ($_ =~ /^ *\<\/$section\>/)) {
113 last;
114 }
115 elsif((2 == $inside) && ($_ =~ /^ *\<\/$part/)) {
116 $inside--;
117 }
118 }
119 return %hash;
120}
121memoize('getpartattr', NORMALIZER => 'normalize_part'); # cache each result
123sub getpart {
124 my ($section, $part) = @_;
126 my @this;
127 my $inside = 0;
128 my $line;
130 for(@xml) {
131 $line++;
132 if(!$inside && ($_ =~ /^ *\<$section/)) {
133 $inside++;
134 }
135 elsif(($inside >= 1) && ($_ =~ /^ *\<$part[ \>]/)) {
136 if($inside > 1) {
137 push @this, $_;
138 }
139 $inside++;
140 }
141 elsif(($inside >= 2) && ($_ =~ /^ *\<\/$part[ \>]/)) {
142 if($inside > 2) {
143 push @this, $_;
144 }
145 $inside--;
146 }
147 elsif(($inside >= 1) && ($_ =~ /^ *\<\/$section/)) {
148 if($inside > 1) {
149 print STDERR "$xmlfile:$line:1: error: missing </$part> tag before </$section>\n";
150 @this = ("format error in $xmlfile");
151 }
152 if($trace && @this) {
153 print STDERR "*** getpart.pm: $section/$part returned data!\n";
154 }
155 if($warning && !@this) {
156 print STDERR "*** getpart.pm: $section/$part returned empty!\n";
157 }
158 return @this;
159 }
160 elsif($inside >= 2) {
161 push @this, $_;
162 }
163 }
164 if($trace && @this) {
165 # section/part has data but end of section not detected,
166 # end of file implies end of section.
167 print STDERR "*** getpart.pm: $section/$part returned data!\n";
168 }
169 if($warning && !@this) {
170 # section/part does not exist or has no data without an end of
171 # section; end of file implies end of section.
172 print STDERR "*** getpart.pm: $section/$part returned empty!\n";
173 }
174 return @this;
175}
176memoize('getpart', NORMALIZER => 'normalize_part'); # cache each result
178sub partexists {
179 my ($section, $part) = @_;
181 my $inside = 0;
183 for(@xml) {
184 if(!$inside && ($_ =~ /^ *\<$section/)) {
185 $inside++;
186 }
187 elsif((1 == $inside) && ($_ =~ /^ *\<$part[ \>]/)) {
188 return 1; # exists
189 }
190 elsif((1 == $inside) && ($_ =~ /^ *\<\/$section/)) {
191 return 0; # does not exist
192 }
193 }
194 return 0; # does not exist
195}
197# The code currently never calls this more than once per part per file, so
198# caching a result that is never used again only slows things down.
199# memoize('partexists', NORMALIZER => 'normalize_part'); # cache each result
201sub loadtest {
202 my ($file, $original, $force) = @_;
204 if(!$force && defined $xmlfile && $file eq $xmlfile) {
205 # This test is already loaded
206 return
207 }
209 undef @xml;
210 $xmlfile = "";
212 # flush results cached from an earlier load, the file may have been
213 # regenerated since with new variable substitutions
214 flush_cache('getpart');
215 flush_cache('getpartattr');
217 if(open(my $xmlh, "<", $file)) {
218 if($original) {
219 binmode $xmlh, ':crlf';
220 }
221 else {
222 binmode $xmlh; # for crapage systems, use binary
223 }
224 while(<$xmlh>) {
225 push @xml, $_;
226 }
227 close($xmlh);
228 if(!@xml) {
229 print STDERR "file $file is empty!\n";
230 return 1;
231 }
232 }
233 else {
234 # failure
235 if($warning) {
236 print STDERR "file $file would not open!\n";
237 }
238 return 1;
239 }
240 $xmlfile = $file;
241 return 0;
242}
244# Return entire document as list of lines
245sub fulltest {
246 return @xml;
247}
249sub eol_detect {
250 my ($content) = @_;
252 my $cr = () = $content =~ /\r/g;
253 my $lf = () = $content =~ /\n/g;
255 if($cr > 0 && $lf == 0) {
256 return "cr";
257 }
258 elsif($cr == 0 && $lf > 0) {
259 return "lf";
260 }
261 elsif($cr == 0 && $lf == 0) {
262 return "bin";
263 }
264 elsif($cr == $lf) {
265 return "crlf";
266 }
268 return "";
269}
271sub checktest {
272 my ($file) = @_;
274 if(open(my $xmlh, '<', $file)) {
275 binmode $xmlh; # we want the raw data to check original newlines
276 my $content = do { local $/; <$xmlh> };
277 close($xmlh);
279 if(index($content, '<?xml version="1.0" encoding="US-ASCII"?>') != 0) {
280 print STDERR "*** getpart.pm: $xmlfile is missing the XML prolog.\n";
281 return 1;
282 }
284 my $eol = eol_detect($content);
285 if($eol eq '') {
286 print STDERR "*** getpart.pm: $xmlfile has mixed newlines. Replace significant carriage return with %CR macro, or convert to consistent newlines.\n";
287 return 1;
288 }
289 }
291 return 0;
292}
294# write the test to the given file
295sub savetest {
296 my ($file) = @_;
298 if(open(my $xmlh, ">", $file)) {
299 binmode $xmlh; # for crapage systems, use binary
300 for(@xml) {
301 print $xmlh $_;
302 }
303 close($xmlh);
304 }
305 else {
306 # failure
307 if($warning) {
308 print STDERR "file $file would not open!\n";
309 }
310 return 1;
311 }
312 return 0;
313}
315#
316# Strip off all lines that match the specified pattern and return
317# the new array.
318#
319sub striparray {
320 my ($pattern, $arrayref) = @_;
322 my @array;
324 for(@$arrayref) {
325 if($_ !~ /$pattern/) {
326 push @array, $_;
327 }
328 }
329 return @array;
330}
332#
333# pass array *REFERENCES* !
334#
335sub compareparts {
336 my ($firstref, $secondref) = @_;
338 # we cannot compare arrays index per index since with data chunks,
339 # they may not be "evenly" distributed
340 my $first = join("", @$firstref);
341 my $second = join("", @$secondref);
343 if($first =~ /%alternatives\[/) {
344 die "bad use of compareparts\n";
345 }
347 if($second =~ /%alternatives\[([^,]*),([^\]]*)\]/) {
348 # there can be many %alternatives in this chunk, so we call
349 # this function recursively
350 my $alt = $second;
351 $alt =~ s/%alternatives\[([^,]*),([^\]]*)\]/$1/;
353 # check first alternative
354 {
355 my @f;
356 my @s;
357 push @f, $first;
358 push @s, $alt;
359 if(!compareparts(\@f, \@s)) {
360 return 0;
361 }
362 }
364 $alt = $second;
365 $alt =~ s/%alternatives\[([^,]*),([^\]]*)\]/$2/;
366 # check second alternative
367 {
368 my @f;
369 my @s;
370 push @f, $first;
371 push @s, $alt;
372 if(!compareparts(\@f, \@s)) {
373 return 0;
374 }
375 }
377 # neither matched
378 return 1;
379 }
381 if($first ne $second) {
382 return 1;
383 }
385 return 0;
386}
388#
389# Write a given array to the specified file
390#
391sub writearray {
392 my ($filename, $arrayref) = @_;
394 open(my $temp, ">", $filename) or die "Failure writing file";
395 binmode($temp, ":raw"); # Cygwin fix
396 for(@$arrayref) {
397 print $temp $_;
398 }
399 close($temp) or die "Failure writing file";
400}
402#
403# Load a specified file and return it as an array
404#
405sub loadarray {
406 my ($filename) = @_;
407 my @array;
409 if(open(my $temp, "<", $filename)) {
410 while(<$temp>) {
411 push @array, $_;
412 }
413 close($temp);
414 }
415 return @array;
416}
4181;
Diagnostics4 git calls · 213 ms
CallStatusSizeTime0213 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.3 KiB208 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=208 git.response.bytes=3378 git.response.cache=MISS git.response.duration_ms=208 git.fetch.wants=7bdf9817460d1289289e11d012d2e570c4a0e52e git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3378 git.pkt.payload.max=3357 git.sideband.band1.bytes=3356 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2d18dbabdcf3a
- Request
- 9fdeecb6…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format