Artifactspublic-v0

curl

master
ply4 git calls45 ms289 KiB2 cachedprotocol v2
185 lines5.8 KiBexecutableRaw
1#!/usr/bin/env perl
2#***************************************************************************
3# _ _ ____ _
4# Project ___| | | | _ \| |
5# / __| | | | |_) | |
6# | (__| |_| | _ <| |___
7# \___|\___/|_| \_\_____|
8#
9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at https://curl.se/docs/copyright.html.
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
22# SPDX-License-Identifier: curl
24###########################################################################
26use strict;
27use warnings;
28use Getopt::Long();
29use Pod::Usage();
31my $opts_dir = '../docs/cmdline-opts';
32my $shell = 'zsh';
33my $help = 0;
34Getopt::Long::GetOptions(
35 'opts-dir=s' => \$opts_dir,
36 'shell=s' => \$shell,
37 'help' => \$help,
38) or Pod::Usage::pod2usage();
39Pod::Usage::pod2usage() if $help;
41my @opts = parse_main_opts($opts_dir);
43if($shell eq 'fish') {
44 print "# curl fish completion\n\n";
45 print "# Complete file paths after @\n";
46 print q(complete -c curl -n 'string match -qr "^@" -- (commandline -ct)' -k -xa "(printf '%s\n' -- @(__fish_complete_suffix --complete=(commandline -ct | string replace -r '^@' '') ''))");
47 print "\n\n";
48 print qq{$_ \n} foreach (@opts);
50elsif($shell eq 'zsh') {
51 my $opts_str;
53 $opts_str .= qq{ $_ \\\n} foreach (@opts);
54 chomp $opts_str;
56 my $tmpl = <<"EOS";
57#compdef curl
59# curl zsh completion
61local curcontext="\$curcontext" state state_descr line
62typeset -A opt_args
64local rc=1
66_arguments -C -S \\
67$opts_str
68 '*:URL:_urls' && rc=0
70return rc
71EOS
73 print $tmpl;
75else {
76 die("Unsupported shell: $shell");
79sub parse_main_opts {
80 my ($opts_dir) = @_;
82 my (@files, @list);
83 my ($dir_handle, $file_content);
85 opendir($dir_handle, $opts_dir) or die "Unable to open dir: $opts_dir due to error: $!";
86 @files = readdir($dir_handle);
87 closedir($dir_handle) or die "Unable to close handle on dir: $opts_dir due to error: $!";
89 # We want regular files that end with .md and do not start with an underscore
90 # Edge case: MANPAGE.md does not start with an underscore but also is not documentation for an option
91 @files = grep { $_ =~ /\.md$/i && !/^_/ && -f "$opts_dir/$_" && $_ ne "MANPAGE.md" } @files;
93 for my $file (@files) {
94 open(my $doc_handle, '<', "$opts_dir/$file") or die "Unable to open file: $file due to error: $!";
95 $file_content = join('', <$doc_handle>);
96 close($doc_handle) or die "Unable to close file: $file due to error: $!";
98 # Extract the curldown header section demarcated by ---
99 $file_content =~ /^---\s*\n(.*?)\n---\s*\n/s or die "Unable to parse file $file";
101 $file_content = $1;
102 my ($short, $long, $arg, $desc);
104 if($file_content =~ /^Short:\s+(.*)\s*$/im) {$short = "-$1";}
105 if($file_content =~ /^Long:\s+(.*)\s*$/im) {$long = "--$1";}
106 if($file_content =~ /^Arg:\s+(.*)\s*$/im) {$arg = $1;}
107 if($file_content =~ /^Help:\s+(.*)\s*$/im) {$desc = $1;}
109 $arg =~ s/\:/\\\:/g if defined $arg;
110 $desc =~ s/'/'\\''/g if defined $desc;
111 $desc =~ s/\[/\\\[/g if defined $desc;
112 $desc =~ s/\]/\\\]/g if defined $desc;
113 $desc =~ s/\:/\\\:/g if defined $desc;
115 my $option = '';
117 if($shell eq 'fish') {
118 $option .= "complete --command curl";
119 $option .= " --short-option '" . strip_dash(trim($short)) . "'"
120 if defined $short;
121 $option .= " --long-option '" . strip_dash(trim($long)) . "'"
122 if defined $long;
123 $option .= " --description '" . strip_dash(trim($desc)) . "'"
124 if defined $desc;
125 }
126 elsif($shell eq 'zsh') {
127 $option .= '{' . trim($short) . ',' if defined $short;
128 $option .= trim($long) if defined $long;
129 $option .= '}' if defined $short;
130 $option .= '\'[' . trim($desc) . ']\'' if defined $desc;
132 if(defined $arg) {
133 $option .= ":'$arg'";
134 if($arg =~ /<file ?(name)?>|<path>/) {
135 $option .= ':_files';
136 }
137 elsif($arg =~ /<dir>/) {
138 $option .= ":'_path_files -/'";
139 }
140 elsif($arg =~ /<url>/i) {
141 $option .= ':_urls';
142 }
143 elsif($long =~ /ftp/ && $arg =~ /<method>/) {
144 $option .= ":'(multicwd nocwd singlecwd)'";
145 }
146 elsif($arg =~ /<method>/) {
147 $option .= ":'(DELETE GET HEAD POST PUT)'";
148 }
149 }
150 }
152 push(@list, $option);
153 }
155 # Sort longest first, because zsh does not complete an option listed
156 # after one that is a prefix of it. When length is equal, fall back
157 # to stringwise cmp.
158 @list = sort {
159 $a =~ /([^=]*)/; my $ma = $1;
160 $b =~ /([^=]*)/; my $mb = $1;
162 length($mb) <=> length($ma) || $ma cmp $mb
163 } @list;
165 return @list;
168sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
169sub strip_dash { my $s = shift; $s =~ s/^-+//g; return $s };
171__END__
173=head1 NAME
175completion.pl - Generates tab-completion files for various shells
177=head1 SYNOPSIS
179completion.pl [options...]
181 --opts-dir path to cmdline-opts directory
182 --shell zsh/fish
183 --help prints this help
185=cut
Diagnostics4 git calls · 45 ms
CallStatusSizeTime045 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 B3 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=UPDATING
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=4
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.3 KiB · hit38 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=38
git.response.bytes=2349
git.response.cache=HIT
git.response.duration_ms=38
git.fetch.wants=1807a9fcc4db5cb67c900097a59dc88fb51588f7
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=2349
git.pkt.payload.max=2328
git.sideband.band1.bytes=2327
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
a5e15bdb4b53cf6a
Request
2c65717f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format