From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
Hi David,
here are my patches for a protocol v2.
("Negotiate capabilities before doing anything else", or as code:
static void upload_pack_version_2(void)
{
send_capabilities_version_2();
receive_capabilities_version_2();
/* The rest of the protocol stays the same, capabilities advertising
is disabled though. */
advertise_capabilities = 0;
upload_pack();
}
)
They are rough and unfinished as you can see by the tailing WIPs.
However the plumbing (upload-pack and fetch-pack) works and we'd need to
integrate that into user porcelains, i.e. fetch, clone, push.
Also we need to add tests for all the options again, so we'd need to be smart
about testing that.
I am not sure if it makes sense to integrate that with the http series, though.
Thanks,
Stefan
Nguyễn Thái Ngọc Duy (1):
upload-pack: make client capability parsing code a separate function
Stefan Beller (13):
upload-pack.c: Refactor capability advertising
upload-pack-2: Implement the version 2 of upload-pack
connect: rewrite feature parsing to work on string_list
transport: add infrastructure to support a protocol version number
remote.h: add get_remote_capabilities, request_capabilities
fetch-pack: move capability selection out of do_fetch_pack
fetch-pack: factor out get_selected_capabilities_list
fetch-pack: Add negotiate_capabilities
do_fetch_pack: select capabilities for transport version 1 only
builtin/fetch-pack: add argument for transport version
Add test for fetch-pack
WIP add test for git pull
WIP test git fetch
.gitignore | 1 +
Makefile | 4 ++
builtin/fetch-pack.c | 20 ++++++-
builtin/receive-pack.c | 15 +++--
connect.c | 141 +++++++++++++++++++++++++++++--------------
connect.h | 2 +-
fetch-pack.c | 102 ++++++++++++++++++++++++-------
fetch-pack.h | 7 +++
remote.c | 2 +
remote.h | 5 ++
t/t5500-fetch-pack.sh | 21 +++++++
t/t5510-fetch.sh | 5 ++
t/t5520-pull.sh | 6 ++
transport-helper.c | 1 +
transport.c | 20 ++++++-
transport.h | 8 +++
upload-pack-2.c | 1 +
upload-pack.c | 159 ++++++++++++++++++++++++++++++++++++-------------
18 files changed, 403 insertions(+), 117 deletions(-)
create mode 120000 upload-pack-2.c
--
2.8.0.32.g71f8beb.dirty
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
Instead of having the capabilities in a local string, keep them
in a struct outside the function. This will allow us in a later patch
to easily reuse the capabilities in version 2 of the protocol.
Signed-off-by: Stefan Beller <redacted>
---
upload-pack.c | 59 ++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 40 insertions(+), 19 deletions(-)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
In upload-pack-2 we send each capability in its own packet buffer.
The construction of upload-pack-2 is a bit unfortunate as I would like
it to not be depending on a symlink linking to upload-pack.c, but I did
not find another easy way to do it. I would like it to generate
upload-pack-2.o from upload-pack.c but with '-DTRANSPORT_VERSION=2' set.
Signed-off-by: Stefan Beller <redacted>
---
.gitignore | 1 +
Makefile | 4 ++++
upload-pack-2.c | 1 +
upload-pack.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 54 insertions(+), 1 deletion(-)
create mode 120000 upload-pack-2.c
@@ -580,6 +580,7 @@ PROGRAM_OBJS += sh-i18n--envsubst.oPROGRAM_OBJS+=shell.oPROGRAM_OBJS+=show-index.oPROGRAM_OBJS+=upload-pack.o+PROGRAM_OBJS+=upload-pack-2.oPROGRAM_OBJS+=remote-testsvn.o# Binary suffix, set to .exe for Windows builds
@@ -648,6 +649,7 @@ OTHER_PROGRAMS = git$X# what test wrappers are needed and 'install' will install, in bindirBINDIR_PROGRAMS_NEED_X+=gitBINDIR_PROGRAMS_NEED_X+=git-upload-pack+BINDIR_PROGRAMS_NEED_X+=git-upload-pack-2BINDIR_PROGRAMS_NEED_X+=git-receive-packBINDIR_PROGRAMS_NEED_X+=git-upload-archiveBINDIR_PROGRAMS_NEED_X+=git-shell
@@ -820,6 +820,45 @@ static void upload_pack(void)}}+#if (TRANSPORT_VERSION == 2)+staticvoidsend_capabilities_version_2(void)+{+inti;+for(i=0;i<ARRAY_SIZE(all_capabilities);i++){+constchar*cap=all_capabilities[i];+if(!strcmp(cap,"allow-tip-sha1-in-want")+&&!(allow_unadvertised_object_request&ALLOW_TIP_SHA1))+continue;+if(!strcmp(cap,"no-done")&&!stateless_rpc)+continue;+packet_write(1,"%s\n",cap);+}++packet_write(1,"agent=%s\n",git_user_agent_sanitized());+packet_flush(1);+}++staticvoidreceive_capabilities_version_2(void)+{+char*line=packet_read_line(0,NULL);+while(line){+parse_features(line);+line=packet_read_line(0,NULL);+}+}++staticvoidupload_pack_version_2(void)+{+send_capabilities_version_2();+receive_capabilities_version_2();++/* The rest of the protocol stays the same, capabilities advertising+isdisabledthough.*/+advertise_capabilities=0;+upload_pack();+}+#endif+staticintupload_pack_config(constchar*var,constchar*value,void*unused){if(!strcmp("uploadpack.allowtipsha1inwant",var)){
@@ -891,6 +933,11 @@ int main(int argc, char **argv)die("'%s' does not appear to be a git repository",dir);git_config(upload_pack_config,NULL);++#if TRANSPORT_VERSION == 2+upload_pack_version_2();+#elseupload_pack();+#endifreturn0;}
@@ -248,6 +248,7 @@ static int disconnect_helper(struct transport *transport)}staticconstchar*unsupported_options[]={+TRANS_OPT_TRANSPORTVERSION,TRANS_OPT_UPLOADPACK,TRANS_OPT_RECEIVEPACK,TRANS_OPT_THIN,
@@ -151,6 +151,16 @@ static int set_git_option(struct git_transport_options *opts,die("transport: invalid depth option '%s'",value);}return0;+}elseif(!strcmp(name,TRANS_OPT_TRANSPORTVERSION)){+if(!value)+opts->transport_version=DEFAULT_TRANSPORT_VERSION;+else{+char*end;+opts->transport_version=strtol(value,&end,0);+if(*end)+die("transport: invalid transport version option '%s'",value);+}+return0;}return1;}
@@ -203,6 +213,7 @@ static int fetch_refs_via_pack(struct transport *transport,memset(&args,0,sizeof(args));args.uploadpack=data->options.uploadpack;+args.transport_version=data->options.transport_version;args.keep_pack=data->options.keep;args.lock_pack=1;args.use_thin_pack=data->options.thin;
@@ -188,6 +189,13 @@ int transport_restrict_protocols(void);/* Send push certificates */#define TRANS_OPT_PUSH_CERT "pushcert"+/* Use a new version of the git protocol */+#define TRANS_OPT_TRANSPORTVERSION "transportversion"++#define DEFAULT_TRANSPORT_VERSION 1+#define DEFAULT_TRANSPORT_UPLOAD_PACK "git-upload-pack"+#define DEFAULT_TRANSPORT_RECEIVE_PACK "git-receive-pack"+/***Returns0iftheoptionwasused,non-zerootherwise.Printsa*messagetostderriftheoptionisnotused.
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
As in the pack protocol version 2 we want to
negotiate the capabilities before any other exchange
we will have a function which will take care of the
whole negotiation process.
It will be placed in fetch-pack.c for now as there
we have access to its internal variables and we'll
work on a `struct fetch_pack_args`. Eventually we
want to move it to a better place such as transport.c
Signed-off-by: Stefan Beller <redacted>
---
fetch-pack.c | 14 ++++++++++++++
fetch-pack.h | 6 ++++++
2 files changed, 20 insertions(+)
@@ -178,7 +184,19 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)if(!conn)returnargs.diag_url?0:1;}-get_remote_heads(fd[0],NULL,0,&ref,0,NULL,&shallow);++switch(args.transport_version){+case2:/* first talk about capabilities, then get the refs */+negotiate_capabilities(fd,&args);+/* fall through */+case1:+get_remote_heads(fd[0],NULL,0,&ref,0,NULL,&shallow);+break;+default:+die("BUG: Transport version %d not supported",+args.transport_version);+break;+}ref=fetch_pack(&args,fd,conn,ref,dest,sought,nr_sought,&shallow,pack_lockfile_ptr);
@@ -687,4 +687,9 @@ test_expect_success 'fetching with auto-gc does not lock up' ')'+test_expect_success'fetching with transport protocol 2 works''+test_pause+gitfetch--transport-protocol=2+'+ test_done
@@ -599,4 +599,10 @@ test_expect_success 'git pull --rebase against local branch' 'testfile="$(catfile2)"'+test_expect_success'git pull with protocol version 2''+test_pause&&+gitpull--transport-version=2++'+ test_done
@@ -519,6 +519,7 @@ test_expect_success 'test --all, --depth, and explicit tag' '' test_expect_success'shallow fetch with tags does not break the repository''+test_when_finished"rm -rf repo1"&&mkdirrepo1&&(cdrepo1&&
@@ -547,6 +548,26 @@ test_expect_success 'fetch-pack can fetch a raw sha1' 'gitfetch-packhidden$(git-Chiddenrev-parserefs/hidden/one)'+test_expect_success'fetch-pack with protocol version 2''+test_when_finished"rm -rf repo1"&&+mkdirrepo1&&+(+cdrepo1&&+gitinit&&+test_commit1&&+test_commit2&&+test_commit3&&+echo"$(gitrev-parsemaster) refs/heads/master">expected&&+mkdirrepo2&&+(+cdrepo2&&+gitinit&&+gitfetch-pack--transport-version=2--upload-pack=git-upload-pack-2../.gitrefs/heads/master>../actual+)&&+test_cmpexpectedactual+)+'+ check_prot_path(){cat>expected<<-EOF&&Diag:url=$1
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
`select_capabilities` would set local variables depending on the
user selection provided by `args` and the server advertisement which
is kept in a list in connect.c
When talking pack protocol version 2 however this has already happend
before during 'negotiate_capabilities'
Signed-off-by: Stefan Beller <redacted>
---
fetch-pack.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
Later on when we introduce the version 2 transport protocol, the
capabilities will not be transported in one lone string but each
capability will be carried in its own pkt line.
To reuse existing infrastructure we would either need to join the
capabilities into a single string again later or refactor the current
capability parsing to be using a data structure which fits both
versions of the transport protocol. We chose to implement the later.
Signed-off-by: Stefan Beller <redacted>
---
builtin/receive-pack.c | 15 ++++++---
connect.c | 82 +++++++++++++++++++++++---------------------------
connect.h | 2 +-
upload-pack.c | 13 ++++++--
4 files changed, 58 insertions(+), 54 deletions(-)
@@ -179,51 +182,40 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,returnlist;}-staticconstchar*parse_feature_value(constchar*feature_list,constchar*feature,int*lenp)+staticconstchar*parse_feature_value(structstring_list*feature_list,constchar*feature,int*lenp){-intlen;--if(!feature_list)-returnNULL;--len=strlen(feature);-while(*feature_list){-constchar*found=strstr(feature_list,feature);-if(!found)-returnNULL;-if(feature_list==found||isspace(found[-1])){-constchar*value=found+len;-/* feature with no value (e.g., "thin-pack") */-if(!*value||isspace(*value)){-if(lenp)-*lenp=0;-returnvalue;-}-/* feature with a value (e.g., "agent=git/1.2.3") */-elseif(*value=='='){-value++;-if(lenp)-*lenp=strcspn(value," \t\n");-returnvalue;-}-/*-*otherwisewematchedasubstringofanotherfeature;-*keeplooking-*/+constchar*value;+structstring_list_item*item;++for_each_string_list_item(item,feature_list){+if(!skip_prefix(item->string,feature,&value))+continue;++/* feature with no value (e.g., "thin-pack") */+if(!*value){+if(lenp)+*lenp=0;+returnvalue;+}+/* feature with a value (e.g., "agent=git/1.2.3") */+elseif(*value=='='){+value++;+if(lenp)+*lenp=strlen(value);+returnvalue;}-feature_list=found+1;}returnNULL;}-intparse_feature_request(constchar*feature_list,constchar*feature)+intparse_feature_request(structstring_list*feature_list,constchar*feature){return!!parse_feature_value(feature_list,feature,NULL);}constchar*server_feature_value(constchar*feature,int*len){-returnparse_feature_value(server_capabilities,feature,len);+returnparse_feature_value(&server_capabilities,feature,len);}intserver_supports(constchar*feature)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
This will be used later by both versions of the transport protocol.
Signed-off-by: Stefan Beller <redacted>
---
fetch-pack.c | 51 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 11 deletions(-)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
Instead of calling get_remote_heads as a first command during the
protocol exchange, we need to have fine grained control over the
capability negotiation in version 2 of the protocol.
Introduce get_remote_capabilities, which will just listen to
capabilities of the remote and request_capabilities which will
tell the selection of capabilities to the remote.
Signed-off-by: Stefan Beller <redacted>
---
connect.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
remote.h | 3 +++
2 files changed, 62 insertions(+)
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:05
Later in version 2 of the pack protocol the selection of capabilities
happens at another step of the protocol, so move out the current
capability selection, so we can reuse it later more easily.
Signed-off-by: Stefan Beller <redacted>
---
fetch-pack.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
@@ -796,21 +796,11 @@ static int cmp_ref_by_name(const void *a_, const void *b_)returnstrcmp(a->name,b->name);}-staticstructref*do_fetch_pack(structfetch_pack_args*args,-intfd[2],-conststructref*orig_ref,-structref**sought,intnr_sought,-structshallow_info*si,-char**pack_lockfile)+staticvoidselect_capabilities(structfetch_pack_args*args){-structref*ref=copy_ref_list(orig_ref);-unsignedcharsha1[20];constchar*agent_feature;intagent_len;-sort_ref_list(&ref,ref_compare_name);-qsort(sought,nr_sought,sizeof(*sought),cmp_ref_by_name);-if((args->depth>0||is_repository_shallow())&&!server_supports("shallow"))die("Server does not support shallow clients");if(server_supports("multi_ack_detailed")){
@@ -867,6 +857,22 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,fprintf(stderr,"Server version is %.*s\n",agent_len,agent_feature);}+}++staticstructref*do_fetch_pack(structfetch_pack_args*args,+intfd[2],+conststructref*orig_ref,+structref**sought,intnr_sought,+structshallow_info*si,+char**pack_lockfile)+{+structref*ref=copy_ref_list(orig_ref);+unsignedcharsha1[20];++sort_ref_list(&ref,ref_compare_name);+qsort(sought,nr_sought,sizeof(*sought),cmp_ref_by_name);++select_capabilities(args);if(everything_local(args,&ref,sought,nr_sought)){packet_flush(fd[1]);
From: David Turner <hidden> Date: 2016-06-16 02:19:07
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
In upload-pack-2 we send each capability in its own packet buffer.
The construction of upload-pack-2 is a bit unfortunate as I would
like
it to not be depending on a symlink linking to upload-pack.c, but I
did
not find another easy way to do it. I would like it to generate
upload-pack-2.o from upload-pack.c but with '-DTRANSPORT_VERSION=2'
set.
Couldn't we check argv[0] and use that to determine protocol? Then we
could symlink executables rather than source code.
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:07
On Mon, May 2, 2016 at 10:43 AM, David Turner [off-list ref] wrote:
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
quoted
In upload-pack-2 we send each capability in its own packet buffer.
The construction of upload-pack-2 is a bit unfortunate as I would
like
it to not be depending on a symlink linking to upload-pack.c, but I
did
not find another easy way to do it. I would like it to generate
upload-pack-2.o from upload-pack.c but with '-DTRANSPORT_VERSION=2'
set.
Couldn't we check argv[0] and use that to determine protocol? Then we
could symlink executables rather than source code.
IIRC I proposed a similar thing earlier, i.e.
if (argv[0] ends with 2)
do_protocol_v_2(...)
but that may break (and confuse a lot!) some use cases.
`git fetch` has the documented --upload-pack switch, so as a server-admin
you are free to have git-upload-pack linking to
"git-upload-pack-2.8" but additionally you still have
"git-upload-pack-1.7" or "git-upload-pack-custom-2".
so I think we should not do that :(
I do like to symlink the executables though.
From: David Turner <hidden> Date: 2016-06-16 02:19:07
On Mon, 2016-05-02 at 10:51 -0700, Stefan Beller wrote:
On Mon, May 2, 2016 at 10:43 AM, David Turner <
dturner@twopensource.com> wrote:
quoted
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
quoted
In upload-pack-2 we send each capability in its own packet
buffer.
The construction of upload-pack-2 is a bit unfortunate as I would
like
it to not be depending on a symlink linking to upload-pack.c, but
I
did
not find another easy way to do it. I would like it to generate
upload-pack-2.o from upload-pack.c but with '
-DTRANSPORT_VERSION=2'
set.
Couldn't we check argv[0] and use that to determine protocol? Then
we
could symlink executables rather than source code.
IIRC I proposed a similar thing earlier, i.e.
if (argv[0] ends with 2)
do_protocol_v_2(...)
but that may break (and confuse a lot!) some use cases.
`git fetch` has the documented --upload-pack switch, so as a server
-admin
you are free to have git-upload-pack linking to
"git-upload-pack-2.8" but additionally you still have
"git-upload-pack-1.7" or "git-upload-pack-custom-2".
so I think we should not do that :(
I do like to symlink the executables though.
I think it would probably not break anyone if the new executable name
were sufficiently distinctive -- e.g. starts_with (strrchr(argv[0],
'/'), "git-upload-pack-protocol-v2"). But it would make custom
executables a bit more complicated for the future.
I guess it is better to have silly source code but clean binaries than
clean source code but silly user-visible rules.
I wonder if it is possible to not repeat the list from upload-pack.c?
It seems unfortunate to have to add the same string in two places
whenever you add a capability.
+static int keep_capability(char *line)
s/keep_/is_known_/ ? Also it would be good to handle capabilities that
are prefixes of others correctly.
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(known_capabilities); i++)
+ if (starts_with(line, known_capabilities[i]))
+ return 1;
+ return 0;
+}
+
+void get_remote_capabilities(int in, char *src_buf, size_t src_len)
maybe rename "in" to "fd" or "in_fd"? I don't immediately know what
"in" is supposed to be when I just look at this signature.
This doesn't actually test that protocol v2 is in fact used (it just
tests that --transport-version=2 doesn't crash). It would be nice to
actually test the version in-use.
From: David Turner <hidden> Date: 2016-06-16 02:19:08
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
Hi David,
here are my patches for a protocol v2.
("Negotiate capabilities before doing anything else", or as code:
static void upload_pack_version_2(void)
{
send_capabilities_version_2();
receive_capabilities_version_2();
/* The rest of the protocol stays the same,
capabilities advertising
is disabled though. */
advertise_capabilities = 0;
upload_pack();
}
)
Overall, except for the comments I made, these patches seem sensible.
Would it be possible to add some docs on the new protocol when you re
-roll? (I know these are just the initial patches, but it really helps
me to see an explanation along with the code).
From: Stefan Beller <hidden> Date: 2016-06-16 02:19:08
On Mon, May 2, 2016 at 1:41 PM, David Turner [off-list ref] wrote:
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
quoted
Hi David,
here are my patches for a protocol v2.
("Negotiate capabilities before doing anything else", or as code:
static void upload_pack_version_2(void)
{
send_capabilities_version_2();
receive_capabilities_version_2();
/* The rest of the protocol stays the same,
capabilities advertising
is disabled though. */
advertise_capabilities = 0;
upload_pack();
}
)
Overall, except for the comments I made, these patches seem sensible.
Would it be possible to add some docs on the new protocol when you re
-roll? (I know these are just the initial patches, but it really helps
me to see an explanation along with the code).
Thanks for the review :) I'll fix the issues and add some docs, though
the reroll
may take some time. I really want to get the submodule groups stuff
done as well.
On Tue, May 3, 2016 at 1:56 AM, David Turner [off-list ref] wrote:
On Mon, 2016-05-02 at 10:51 -0700, Stefan Beller wrote:
quoted
On Mon, May 2, 2016 at 10:43 AM, David Turner <
dturner@twopensource.com> wrote:
quoted
On Fri, 2016-04-29 at 16:34 -0700, Stefan Beller wrote:
quoted
In upload-pack-2 we send each capability in its own packet
buffer.
The construction of upload-pack-2 is a bit unfortunate as I would
like
it to not be depending on a symlink linking to upload-pack.c, but
I
did
not find another easy way to do it. I would like it to generate
upload-pack-2.o from upload-pack.c but with '
-DTRANSPORT_VERSION=2'
set.
Couldn't we check argv[0] and use that to determine protocol? Then
we
could symlink executables rather than source code.
IIRC I proposed a similar thing earlier, i.e.
if (argv[0] ends with 2)
do_protocol_v_2(...)
but that may break (and confuse a lot!) some use cases.
`git fetch` has the documented --upload-pack switch, so as a server
-admin
you are free to have git-upload-pack linking to
"git-upload-pack-2.8" but additionally you still have
"git-upload-pack-1.7" or "git-upload-pack-custom-2".
so I think we should not do that :(
I do like to symlink the executables though.
I think it would probably not break anyone if the new executable name
were sufficiently distinctive -- e.g. starts_with (strrchr(argv[0],
'/'), "git-upload-pack-protocol-v2"). But it would make custom
executables a bit more complicated for the future.
I guess it is better to have silly source code but clean binaries than
clean source code but silly user-visible rules.
Maybe add --version to upload-pack? Then we can have a script
git-upload-pack-v2 that does "exec git upload-pack --version=2"
--
Duy
I wonder if it is possible to not repeat the list from upload-pack.c?
It seems unfortunate to have to add the same string in two places
whenever you add a capability.
I think that in general, we'd stop adding capabilities to v1. If you
have a client which speaks the new capability, then it should also be
speaking the new protocol. That's not strictly true if other non-git.git
implementations want to learn capability X but not protocol v2, but I
think in practice it's not an unreasonable world view.
I guess there may be a grey area for a while, though, where even
v2-capable clients don't end up speaking it, because they don't yet know
that a particular server can handle it. So any capabilities added in
that grey area may want to go to both v1 and v2.
-Peff
I wonder if it is possible to not repeat the list from upload
-pack.c?
It seems unfortunate to have to add the same string in two places
whenever you add a capability.
I think that in general, we'd stop adding capabilities to v1. If you
have a client which speaks the new capability, then it should also be
speaking the new protocol. That's not strictly true if other non
-git.git
implementations want to learn capability X but not protocol v2, but I
think in practice it's not an unreasonable world view.
I guess there may be a grey area for a while, though, where even
v2-capable clients don't end up speaking it, because they don't yet
know
that a particular server can handle it. So any capabilities added in
that grey area may want to go to both v1 and v2.
OK, but then there should be one list per protocol version rather than
two copies of the same list.
I wonder if it is possible to not repeat the list from upload
-pack.c?
It seems unfortunate to have to add the same string in two places
whenever you add a capability.
I think that in general, we'd stop adding capabilities to v1. If you
have a client which speaks the new capability, then it should also be
speaking the new protocol. That's not strictly true if other non
-git.git
implementations want to learn capability X but not protocol v2, but I
think in practice it's not an unreasonable world view.
I guess there may be a grey area for a while, though, where even
v2-capable clients don't end up speaking it, because they don't yet
know
that a particular server can handle it. So any capabilities added in
that grey area may want to go to both v1 and v2.
OK, but then there should be one list per protocol version rather than
two copies of the same list.
I thought this is by design as upload-pack is a different program, i.e. it
could be developed out of sync with the client, adding/removing
capabilities there but not in fetch-pack. That doesn't make sense though.
We could introduce known_capabilities_v1 and _v2 respectively in shared
header files, though.
From: David Turner <hidden> Date: 2016-06-16 02:19:35
I was looking at this again today, and noticed that it doesn't really
address the HTTP case.
The central problem is that protocol v2 goes like this:
server: I have capabilities w,x,y, and z
client: I want capabilities x and z.
But HTTP goes like this:
client: [request]
server: [response]
I tried to make libcurl do the receive-before-sending thing, but it
doesn't seem to be designed for it (even if you prime things by sending
a "hello" from the client first). My thought was to hook up
CURLOPT_READFUNCTION and CURLOPT_WRITEFUNCTION, and have the read
function return CURL_READFUNC_PAUSE and then have the write (=client
receiving data ) function unpause the reader (= client sending data)
once it gets the capabilities. But apparently pausing only works with
chunked encoding, which seems to cause Apache's mod_cgi to fail.
Maybe I'm missing something. Has anyone else ever made something like
this work?
Of course, I could always use CURLOPT_CONNECT_ONLY to write my own HTTP
client, but that seems pretty unreasonable.
I also looked to see if libcurl had websockets support, since that's
one kind of bidirectional conversation over HTTP, but it doesn't seem
to.
Another choice is to make a separate /capabilities endpoint that gets
hit before /info/refs. This is a bit bad because:
(a) it's another HTTP request
(b) it adds implicit state to the HTTP conversation. If multiple git
servers were behind a load balancer, you might end up getting server A
for /capabilities and server B for /info/refs, and those servers might
have different capabilities. This is not impossible when testing a git
server upgrade on one machine before rolling it out to a whole fleet.
Maybe the rule for clients re capabilities is that they can request
whatever capabilities they want, but the server is free to ignore that
request and send whatever data it feels like. That's not great, but it
should work (I think).
Does anyone else have any thoughts on how this ought to work?
On Wed, May 25, 2016 at 5:46 AM, David Turner [off-list ref] wrote:
I was looking at this again today, and noticed that it doesn't really
address the HTTP case.
The central problem is that protocol v2 goes like this:
server: I have capabilities w,x,y, and z
client: I want capabilities x and z.
But HTTP goes like this:
client: [request]
server: [response]
I tried to make libcurl do the receive-before-sending thing, but it
doesn't seem to be designed for it (even if you prime things by sending
a "hello" from the client first). My thought was to hook up
CURLOPT_READFUNCTION and CURLOPT_WRITEFUNCTION, and have the read
function return CURL_READFUNC_PAUSE and then have the write (=client
receiving data ) function unpause the reader (= client sending data)
once it gets the capabilities. But apparently pausing only works with
chunked encoding, which seems to cause Apache's mod_cgi to fail.
Maybe I'm missing something. Has anyone else ever made something like
this work?
It simply takes one more round-trip to negotiate. Not the best thing, but...
I also looked to see if libcurl had websockets support, since that's
one kind of bidirectional conversation over HTTP, but it doesn't seem
to.
Yeah. And libcurl probably will not support websockets even in long
run. I've been searching for a websocket implementation for git and
finally settled for netcat-like programs, sitting in front of git and
dealing with network just like ssh. It will be the simplest way to add
either websocket or http/2 support. If either protocol gets popular
enough, smart-http can become a fall-back mechanism where performance
does not matter much.
--
Duy
From: David Turner <hidden> Date: 2016-06-16 02:19:36
On Wed, 2016-05-25 at 06:03 +0700, Duy Nguyen wrote:
On Wed, May 25, 2016 at 5:46 AM, David Turner <
dturner@twopensource.com> wrote:
quoted
I was looking at this again today, and noticed that it doesn't
really
address the HTTP case.
The central problem is that protocol v2 goes like this:
server: I have capabilities w,x,y, and z
client: I want capabilities x and z.
But HTTP goes like this:
client: [request]
server: [response]
I tried to make libcurl do the receive-before-sending thing, but it
doesn't seem to be designed for it (even if you prime things by
sending
a "hello" from the client first). My thought was to hook up
CURLOPT_READFUNCTION and CURLOPT_WRITEFUNCTION, and have the read
function return CURL_READFUNC_PAUSE and then have the write
(=client
receiving data ) function unpause the reader (= client sending
data)
once it gets the capabilities. But apparently pausing only works
with
chunked encoding, which seems to cause Apache's mod_cgi to fail.
Maybe I'm missing something. Has anyone else ever made something
like
this work?
It simply takes one more round-trip to negotiate. Not the best thing,
but...
Do you mean that it can be done with libcurl? Or do you mean that I
should go with the /capabilities endpoint?
From: Jeff King <hidden> Date: 2016-06-16 02:19:36
On Tue, May 24, 2016 at 06:46:48PM -0400, David Turner wrote:
I tried to make libcurl do the receive-before-sending thing, but it
doesn't seem to be designed for it (even if you prime things by sending
a "hello" from the client first). My thought was to hook up
CURLOPT_READFUNCTION and CURLOPT_WRITEFUNCTION, and have the read
function return CURL_READFUNC_PAUSE and then have the write (=client
receiving data ) function unpause the reader (= client sending data)
once it gets the capabilities. But apparently pausing only works with
chunked encoding, which seems to cause Apache's mod_cgi to fail.
Maybe I'm missing something. Has anyone else ever made something like
this work?
I don't think it can work in the general case. HTTP is not full-duplex,
and you have to send off the request and wait for the response. Even if
you could convince the client and git-http-backend to do it, you're
going to get foiled by proxies, web server implementations, and other
middle-men.
Of course, I could always use CURLOPT_CONNECT_ONLY to write my own HTTP
client, but that seems pretty unreasonable.
I also looked to see if libcurl had websockets support, since that's
one kind of bidirectional conversation over HTTP, but it doesn't seem
to.
I would love to see us move to a true bidirectional HTTP-based protocol.
It would clear up all of the drawbacks that the current HTTP protocol
has, and I think we could generally recommend it entirely over using
git://. But like you, I haven't figured out an easy way to do it.
I hoped that maybe HTTP/2 would solve some of that if we waited long
enough for it to be adopted, but it doesn't look like there's anything
out of the box. It seems like the recommended solutions still involve
websockets. I might be wrong, though; this is very much outside my area
of expertise.
Another choice is to make a separate /capabilities endpoint that gets
hit before /info/refs. This is a bit bad because:
(a) it's another HTTP request
Right, this is the extra round-trip I mentioned in:
http://thread.gmane.org/gmane.comp.version-control.git/291640/focus=291951
I think you could get rid of it by making protocol v2 a true "client
speaks first" protocol, which aligns better with how HTTP works (but if
we do that, it would be nice to do it for _all_ of the transports, so
they stay closer to each other). But...
(b) it adds implicit state to the HTTP conversation. If multiple git
servers were behind a load balancer, you might end up getting server A
for /capabilities and server B for /info/refs, and those servers might
have different capabilities. This is not impossible when testing a git
server upgrade on one machine before rolling it out to a whole fleet.
Maybe the rule for clients re capabilities is that they can request
whatever capabilities they want, but the server is free to ignore that
request and send whatever data it feels like. That's not great, but it
should work (I think).
I think this is already the case today. Every non-trivial git-over-http
request requires at least two HTTP requests: one to receive the server
fetch advertisement, and the second to actually do the work (and in the
fetch case, the have/want negotiation in the second one may actually
span several requests).
The capabilities from the server come in the first request, and then the
client sends back its capabilities in the second one. So if you are
hitting multiple incompatible servers, the server may not understand
your request. Likewise, if an upload-pack request takes multiple hits,
we send up the client capabilities in each request.
I don't think quietly ignoring unknown capabilities is a good idea. The
results would range from confusing breakages (e.g., ignored multi-ack or
no-done capabilities) to subtly wrong behavior (e.g., a server which
ignores "atomic" and proceeds with a half-failed push anyway). Given
the rarity of the situation, it's probably better for the server to barf
with an appropriate error message. That sucks for the user, but it's
probably better than the alternatives.
-Peff