Artifactspublic-v0

curl

master
ply4 git calls41 ms289 KiB3 cachedprotocol v2
336 lines7.3 KiBexecutableRaw
1#!/usr/bin/env perl
2# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3#
4# SPDX-License-Identifier: curl
5#
6# bad[:=]correct
7#
8# If separator is '=', the string is compared case sensitively.
9# If separator is ':', the check is done case insensitively.
11# To add white listed uses of bad words that are removed before checking for
12# the bad ones:
14# ---(accepted word)
15# ---:[path]:(accepted word)
18use strict;
19use warnings;
21use File::Basename;
24## States
26# 0 - default, initial state
27# 1 - there was a slash
28# 2 - quoted string
29# 3 - // comment
30# 4 - /* comment
31# 5 - asterisk found within a /* comment
32# 6 - #include line
33# 7 - backslash in a string
35## Flags
37# 1 - include preprocessor line, ignore strings
39sub srcline {
40 my ($state, $flags, $l) = @_;
41 my $line = "";
43 if(($state == 0) && ($l =~ /^ *\# *include/)) {
44 # preprocessor include line
45 $flags |= 1;
46 }
47 else {
48 # not preprocessor
49 $flags &= ~1;
50 }
52 if($state == 3) {
53 # // ended on the prev line, go back to init
54 $state = 0;
55 }
57 my @c = split(//, $l);
59 # state machine this line
60 for my $c (@c) {
61 if($state == 1) {
62 # we had a slash
63 if($c eq "/") {
64 # // confirmed, the rest of the line is a comment
65 $line .= "//";
66 $state = 3;
67 }
68 elsif($c eq "*") {
69 # /* confirmed
70 $state = 4;
71 $line .= "/*";
72 }
73 else {
74 # back to normal
75 $line .= " ";
76 $state = 0;
77 }
78 }
79 elsif($state == 2) {
80 # a string
81 if($c eq "\\") {
82 $line .= "\\";
83 $state = 7;
84 }
85 elsif($c eq "\"") {
86 # end of the string
87 $line .= "\"";
88 $state = 0;
89 }
90 else {
91 $line .= $c;
92 }
93 }
94 elsif($state == 3) {
95 # a // comment
96 $line .= $c;
97 }
98 elsif($state == 4) {
99 # a /* comment
100 if($c eq "*") {
101 # could be a comment close
102 $state = 5;
103 }
104 else {
105 $line .= $c;
106 }
107 }
108 elsif($state == 5) {
109 if($c eq "/") {
110 # a /* */ comment ended here */
111 $line .= "*/";
112 $state = 0;
113 }
114 else {
115 # the /* comment continues
116 $line .= "*$c";
117 $state = 4;
118 }
119 }
120 elsif($state == 7) {
121 # the prev was a backslash in a string
122 $line .= $c;
123 # switch back to normal string
124 $state = 2;
125 }
126 else {
127 if($c eq "/") {
128 $state = 1; # got a slash
129 }
130 elsif(($c eq "\"") && !($flags & 1)) {
131 # start of a string, not within a preprocessor line
132 $line .= "\"";
133 $state = 2;
134 }
135 elsif($c eq "\n") {
136 $line .= "\n";
137 }
138 else {
139 $line .= " ";
140 }
141 }
142 }
143 return $state, $flags, $line;
146sub sourcecode {
147 my ($f) = @_;
148 my $state = 0;
149 my $flags = 0;
150 my @lines;
151 my $line;
152 open(F, "<", $f);
153 while(<F>) {
154 my $l = $_;
155 ($state, $flags, $line) = srcline($state, $flags, $l);
156 push @lines, $line;
157 }
158 close(F);
159 return @lines;
162my @whitelist = (
163 # ignore what looks like URLs
164 '(^|\W)((https|http|ftp):\/\/[a-z0-9\-._~%:\/?\#\[\]\@!\$&\'\(\)*+,;=]+)',
165 # remove bolded sections
166 '\*\*.*?\*\*',
167 # remove backticked texts
168 '\`.*?\`'
169 );
170my %alt;
171my %exactcase;
173my %wl;
175my @w;
176my @exact;
177my $file = shift @ARGV;
178open(CONFIG, "<", $file) or die "Cannot open '$file': $!";
179while(<CONFIG>) {
180 chomp;
181 if($_ =~ /^#/) {
182 next;
183 }
184 if(/^---:([^:]*):(.*)/) {
185 # whitelist file + word
186 my $word = lc($2);
187 $wl{"$1:$word"} = 1;
188 }
189 elsif($_ =~ /^---(.+)/) {
190 # whitelist word
191 push @whitelist, $1;
192 }
193 elsif($_ =~ /^(.*)([:=])(.*)/) {
194 my ($bad, $sep, $better) = ($1, $2, $3);
195 if($sep eq "=") {
196 $alt{$bad} = $better;
197 push @exact, $bad;
198 }
199 else {
200 $alt{lc($bad)} = $better;
201 push @w, $bad;
202 }
203 }
205close(CONFIG);
207# Build a single combined regex for case-insensitive words
208my $re_ci;
209if(@w) {
210 my $pat = join('|', map { quotemeta($_) } @w);
211 $re_ci = qr/\b($pat)\b/i;
214# Build a single combined regex for case-sensitive (exact) words
215my $re_cs;
216if(@exact) {
217 my $pat = join('|', map { quotemeta($_) } @exact);
218 $re_cs = qr/\b($pat)\b/;
221# Build a single combined regex for removing whitelisted content
222my $pat = join('|', map { $_ } @whitelist);
223my $re_wl = qr/($pat)/;
225my $errors = 0;
227sub highlight {
228 my ($p, $w, $in, $f, $l, $lookup) = @_;
230 my $c = length($p)+1;
231 my $ch;
233 my $dir = dirname($f);
234 $ch = $dir . "/" . ":" . lc($w);
235 if($wl{$ch}) {
236 # whitelisted dirname + word
237 return;
238 }
239 my $updir = dirname($dir);
240 if($dir ne $updir) {
241 $ch = $updir . "/" . ":" . lc($w);
242 if($wl{$ch}) {
243 # whitelisted upper dirname + word
244 return;
245 }
246 }
247 $ch = $f . ":" . lc($w);
248 if($wl{$ch}) {
249 # whitelisted filename + word
250 return;
251 }
253 print STDERR "$f:$l:$c: error: found bad word \"$w\"\n";
254 printf STDERR " %4d | %s\n", $l, $in;
255 printf STDERR " | %*s^%s\n", length($p), " ",
256 "~" x (length($w)-1);
257 printf STDERR " maybe use \"%s\" instead?\n", $alt{$lookup};
258 $errors++;
261sub document {
262 my ($f) = @_;
263 my @lines;
264 open(F, "<", $f);
265 while(<F>) {
266 push @lines, $_;
267 }
268 close(F);
269 return @lines;
272sub file {
273 my ($f) = @_;
274 my $l = 0;
276 my $skip_indented = 0;
277 my $source_code = 0;
278 if($f =~ /\.[ch]$/) {
279 $source_code = 1;
280 }
281 else {
282 # markdown
283 $skip_indented = 1;
284 }
286 my @lines;
287 if($source_code) {
288 @lines = sourcecode($f);
289 }
290 else {
291 @lines = document($f);
292 }
293 for my $in (@lines) {
294 $l++;
295 chomp $in;
296 if($skip_indented && $in =~ /^ /) {
297 next;
298 }
299 # remove the link part
300 $in =~ s/(\[.*\])\(.*\)/$1/g;
301 # remove whitelisted patterns (pre-compiled)
302 if($re_wl) {
303 $in =~ s/${re_wl}//ig;
304 }
305 # case-insensitive bad words
306 if($re_ci) {
307 if($in =~ /^(.*)$re_ci/i) {
308 highlight($1, $2, $in, $f, $l, lc($2));
309 }
310 }
311 # case-sensitive (exact) bad words
312 if($re_cs) {
313 if($in =~ /^(.*)$re_cs/) {
314 highlight($1, $2, $in, $f, $l, $2);
315 }
316 }
317 }
320my @filemasks = @ARGV;
321open(my $git_ls_files, '-|', 'git', 'ls-files', '--end-of-options', ":!:$file", @filemasks) or die "Failed running git ls-files: $!";
322my @files;
323while(my $each = <$git_ls_files>) {
324 chomp $each;
325 push @files, $each;
327close $git_ls_files;
329my $onum = scalar(@files);
330my $num;
331for my $e (@files) {
332 #printf STDERR "Complete: %d%%\r", $num++ * 100 / $onum;
333 file($e);
336exit $errors;
Diagnostics4 git calls · 41 ms
CallStatusSizeTime041 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
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=35
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=86
Open pack map
fetch2002.6 KiB · hit35 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2650
git.response.cache=HIT
git.response.duration_ms=35
git.fetch.wants=53c93f40318a1f85cc0c4150be5115ffd064891c
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=2650
git.pkt.payload.max=2629
git.sideband.band1.bytes=2628
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
a5e207673d8dc69c
Request
7d4bb024…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format