Return of smart HTTP
Subsystems (2)
v5 cover Return of smart HTTP
Hopefully the final spin of the smart HTTP series. I think we are down to bike shedding, which I take it means folks are otherwise reasonably happy with the code.
Because the series is so large I'll send an inter-diff relative to v4 after this cover letter.
Clemens Buchacher (2):
remote-helpers: return successfully if everything up-to-date set httpd port before sourcing lib-httpd
Mark Lodato (5):
http-backend: add GIT_PROJECT_ROOT environment var
http-backend: reword some documentation
http-backend: use mod_alias instead of mod_rewrite
http-backend: add example for gitweb on same URL
http-backend: more explict LocationMatch
Shawn O. Pearce (19):
pkt-line: Add strbuf based functions
pkt-line: Make packet_read_line easier to debug
fetch-pack: Use a strbuf to compose the want list Move "get_ack()" back to fetch-pack
Add multi_ack_detailed capability to fetch-pack/upload-pack
remote-curl: Refactor walker initialization
fetch: Allow transport -v -v -v to set verbosity to 3
remote-helpers: Fetch more than one ref in a batch
remote-helpers: Support custom transport options Move WebDAV HTTP push under remote-curl
Git-aware CGI to provide dumb HTTP transport
Add stateless RPC options to upload-pack, receive-pack Smart fetch and push over HTTP: server side Discover refs via smart HTTP server when available Smart push over HTTP: client side
Smart fetch over HTTP: client side
Smart HTTP fetch: gzip requests
http tests: use /dumb/ URL prefix
test smart http fetch and push
Tay Ray Chuan (2):
http-push: fix check condition on http.c::finish_http_pack_request()
t5540-http-push: remove redundant fetches
.gitignore | 1 + Documentation/config.txt | 8 + Documentation/git-http-backend.txt | 170 ++++++++ Documentation/git-remote-helpers.txt | 85 ++++- Makefile | 1 + builtin-fetch-pack.c | 210 ++++++++-- builtin-fetch.c | 2 +- builtin-receive-pack.c | 26 +- builtin-send-pack.c | 116 +++++- cache.h | 1 - commit.c | 10 +- commit.h | 2 +- connect.c | 21 - fetch-pack.h | 3 +- http-backend.c | 627 ++++++++++++++++++++++++++++ http-push.c | 31 ++- http.c | 13 +- http.h | 2 + pkt-line.c | 84 ++++- pkt-line.h | 4 + remote-curl.c | 759 ++++++++++++++++++++++++++++++++-- send-pack.h | 3 +- sideband.c | 11 +- t/lib-httpd/apache.conf | 24 +- t/t5540-http-push.sh | 35 +- t/t5541-http-push.sh | 92 ++++ t/t5550-http-fetch.sh | 12 +- t/t5551-http-fetch.sh | 102 +++++ transport-helper.c | 264 +++++++++++- transport.c | 32 +-- transport.h | 2 +- upload-pack.c | 71 +++- 32 files changed, 2589 insertions(+), 235 deletions(-) create mode 100644 Documentation/git-http-backend.txt create mode 100644 http-backend.c create mode 100755 t/t5541-http-push.sh create mode 100755 t/t5551-http-fetch.sh
PATCH v5 1/28 http-push: fix check condition on http.c::finish_http_pack_request()
From: Tay Ray Chuan <[email protected]>
Check that http.c::finish_http_pack_request() returns 0 (for success).
--- http-push.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
http-push.c +1 -1
@@ -604,7 +604,7 @@ static void finish_request(struct transfer_request *request) preq = (struct http_pack_request *)request->userData;if (preq) { -if (finish_http_pack_request (preq) >0 ) +if (finish_http_pack_request (preq) ==0 ) fail =0 ;release_http_pack_request (preq); }
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 2/28 pkt-line: Add strbuf based functions
In reply to Shawn O. PearceThese routines help to work with pkt-line values inside of a strbuf, permitting simple formatting of buffered network messages.
--- pkt-line.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- pkt-line.h | 4 +++ 2 files changed, 76 insertions(+), 12 deletions(-)
pkt-line.c +72 -12
@@ -42,17 +42,19 @@ void packet_flush(int fd)safe_write (fd,"0000" ,4 ); } +void packet_buf_flush (struct strbuf *buf) +{ +strbuf_add (buf,"0000" ,4 ); +} +#define hex (a) (hexchar[(a) & 15]) -void packet_write (int fd,const char *fmt, ...) +static char buffer[1000 ]; +static unsigned format_packet (const char *fmt,va_list args) { -static char buffer[1000 ];static char hexchar[] ="0123456789abcdef" ; -va_list args;unsigned n; -va_start (args, fmt); n =vsnprintf (buffer +4 ,sizeof (buffer) -4 , fmt, args); -va_end (args);if (n >=sizeof (buffer)-4 )die ("protocol error: impossibly long line" ); n +=4 ;
@@ -60,9 +62,31 @@ void packet_write(int fd, const char *fmt, ...) buffer[1 ] =hex (n >>8 ); buffer[2 ] =hex (n >>4 ); buffer[3 ] =hex (n); +return n; +} + +void packet_write (int fd,const char *fmt, ...) +{ +va_list args; +unsigned n; + +va_start (args, fmt); + n =format_packet (fmt, args); +va_end (args);safe_write (fd, buffer, n); } +void packet_buf_write (struct strbuf *buf,const char *fmt, ...) +{ +va_list args; +unsigned n; + +va_start (args, fmt); + n =format_packet (fmt, args); +va_end (args); +strbuf_add (buf, buffer, n); +} +static void safe_read (int fd,void *buffer,unsigned size) {ssize_t ret =read_in_full (fd, buffer, size);
@@ -72,15 +96,11 @@ static void safe_read(int fd, void *buffer, unsigned size)die ("The remote end hung up unexpectedly" ); } -int packet_read_line (int fd,char *buffer,unsigned size) +static int packet_length (const char *linelen) {int n; -unsigned len; -char linelen[4 ]; - -safe_read (fd, linelen,4 ); +int len =0 ; - len =0 ;for (n =0 ; n <4 ; n++) {unsigned char c = linelen[n]; len <<=4 ;
@@ -96,8 +116,20 @@ int packet_read_line(int fd, char *buffer, unsigned size) len += c -'A' +10 ;continue ; } -die ("protocol error: bad line length character" ); +return -1 ; } +return len; +} + +int packet_read_line (int fd,char *buffer,unsigned size) +{ +int len; +char linelen[4 ]; + +safe_read (fd, linelen,4 ); + len =packet_length (linelen); +if (len <0 ) +die ("protocol error: bad line length character" );if (!len)return 0 ; len -=4 ;
@@ -107,3 +139,31 @@ int packet_read_line(int fd, char *buffer, unsigned size) buffer[len] =0 ;return len; } + +int packet_get_line (struct strbuf *out, +char **src_buf,size_t *src_len) +{ +int len; + +if (*src_len <4 ) +return -1 ; + len =packet_length (*src_buf); +if (len <0 ) +return -1 ; +if (!len) { + *src_buf +=4 ; + *src_len -=4 ; +return 0 ; + } +if (*src_len < len) +return -2 ; + + *src_buf +=4 ; + *src_len -=4 ; + len -=4 ; + +strbuf_add (out, *src_buf, len); + *src_buf += len; + *src_len -= len; +return len; +}
pkt-line.h +4 -0
@@ -2,14 +2,18 @@#define PKTLINE_H #include "git-compat-util.h" +#include "strbuf.h" /* * Silly packetized line writing interface */ void packet_flush (int fd);void packet_write (int fd,const char *fmt, ...) __attribute__((format (printf,2 ,3 ))); +void packet_buf_flush (struct strbuf *buf); +void packet_buf_write (struct strbuf *buf,const char *fmt, ...) __attribute__((format (printf,2 ,3 )));int packet_read_line (int fd,char *buffer,unsigned size); +int packet_get_line (struct strbuf *out,char **src_buf,size_t *src_len);ssize_t safe_write (int ,const void *,ssize_t );#endif
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 3/28 pkt-line: Make packet_read_line easier to debug
In reply to Shawn O. PearceWhen there is an error parsing the 4 byte length component we now display it as part of the die message, this may hint as to what data was misunderstood by the application.
--- pkt-line.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
pkt-line.c +1 -1
@@ -129,7 +129,7 @@ int packet_read_line(int fd, char *buffer, unsigned size)safe_read (fd, linelen,4 ); len =packet_length (linelen);if (len <0 ) -die ("protocol error: bad line length character" ); +die ("protocol error: bad line length character: %.4s" , linelen);if (!len)return 0 ; len -=4 ;
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 4/28 fetch-pack: Use a strbuf to compose the want list
In reply to Shawn O. PearceThis change is being offered as a refactoring to make later commits in the smart HTTP series easier.
By changing the enabled capabilities to be formatted in a strbuf it is easier to add a new capability to the set of supported capabilities.
By formatting the want portion of the request into a strbuf and writing it as a whole block we can later decide to hold onto the req_buf (instead of releasing it) to recycle in stateless communications.
--- builtin-fetch-pack.c | 52 ++++++++++++++++++++++++++++++++----------------- commit.c | 10 +++----- commit.h | 2 +- 3 files changed, 39 insertions(+), 25 deletions(-)
builtin-fetch-pack.c +34 -18
@@ -165,6 +165,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,const unsigned char *sha1;unsigned in_vain =0 ;int got_continue =0 ; +struct strbuf req_buf =STRBUF_INIT ;if (marked)for_each_ref (clear_marks,NULL );
@@ -175,6 +176,7 @@ static int find_common(int fd[2], unsigned char *result_sha1, fetching =0 ;for ( ; refs ; refs = refs->next) {unsigned char *remote = refs->old_sha1; +const char *remote_hex;struct object *o;/*
@@ -192,27 +194,36 @@ static int find_common(int fd[2], unsigned char *result_sha1,continue ; } -if (!fetching) -packet_write (fd[1 ],"want %s%s%s%s%s%s%s%s\n" , -sha1_to_hex (remote), - (multi_ack ?" multi_ack" :"" ), - (use_sideband ==2 ?" side-band-64k" :"" ), - (use_sideband ==1 ?" side-band" :"" ), - (args.use_thin_pack ?" thin-pack" :"" ), - (args.no_progress ?" no-progress" :"" ), - (args.include_tag ?" include-tag" :"" ), - (prefer_ofs_delta ?" ofs-delta" :"" )); -else -packet_write (fd[1 ],"want %s\n" ,sha1_to_hex (remote)); + remote_hex =sha1_to_hex (remote); +if (!fetching) { +struct strbuf c =STRBUF_INIT ; +if (multi_ack)strbuf_addstr (&c," multi_ack" ); +if (use_sideband ==2 )strbuf_addstr (&c," side-band-64k" ); +if (use_sideband ==1 )strbuf_addstr (&c," side-band" ); +if (args.use_thin_pack)strbuf_addstr (&c," thin-pack" ); +if (args.no_progress)strbuf_addstr (&c," no-progress" ); +if (args.include_tag)strbuf_addstr (&c," include-tag" ); +if (prefer_ofs_delta)strbuf_addstr (&c," ofs-delta" ); +packet_buf_write (&req_buf,"want %s%s\n" , remote_hex, c.buf); +strbuf_release (&c); + }else +packet_buf_write (&req_buf,"want %s\n" , remote_hex); fetching++; } + +if (!fetching) { +strbuf_release (&req_buf); +packet_flush (fd[1 ]); +return 1 ; + } +if (is_repository_shallow ()) -write_shallow_commits (fd[1 ],1 ); +write_shallow_commits (&req_buf,1 );if (args.depth >0 ) -packet_write (fd[1 ],"deepen %d" , args.depth); -packet_flush (fd[1 ]); -if (!fetching) -return 1 ; +packet_buf_write (&req_buf,"deepen %d" , args.depth); +packet_buf_flush (&req_buf); + +safe_write (fd[1 ], req_buf.buf, req_buf.len);if (args.depth >0 ) {char line[1024 ];
@@ -296,6 +307,8 @@ done: multi_ack =0 ; flushes++; } +strbuf_release (&req_buf); +while (flushes || multi_ack) {int ack =get_ack (fd[0 ], result_sha1);if (ack) {
@@ -809,6 +822,7 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args,if (args.depth >0 ) {struct cache_time mtime; +struct strbuf sb =STRBUF_INIT ;char *shallow =git_path ("shallow" );int fd;
@@ -826,12 +840,14 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args, fd =hold_lock_file_for_update (&lock, shallow,LOCK_DIE_ON_ERROR ); -if (!write_shallow_commits (fd,0 )) { +if (!write_shallow_commits (&sb,0 ) + ||write_in_full (fd, sb.buf, sb.len) != sb.len) {unlink_or_warn (shallow);rollback_lock_file (&lock); }else {commit_lock_file (&lock); } +strbuf_release (&sb); }reprepare_packed_git ();
commit.c +4 -6
@@ -199,7 +199,7 @@ struct commit_graft *lookup_commit_graft(const unsigned char *sha1)return commit_graft[pos]; } -int write_shallow_commits (int fd,int use_pack_protocol) +int write_shallow_commits (struct strbuf *out,int use_pack_protocol) {int i, count =0 ;for (i =0 ; i < commit_graft_nr; i++)
@@ -208,12 +208,10 @@ int write_shallow_commits(int fd, int use_pack_protocol)sha1_to_hex (commit_graft[i]->sha1); count++;if (use_pack_protocol) -packet_write (fd,"shallow %s" , hex); +packet_buf_write (out,"shallow %s" , hex);else { -if (write_in_full (fd, hex,40 ) !=40 ) -break ; -if (write_str_in_full (fd,"\n" ) !=1 ) -break ; +strbuf_addstr (out, hex); +strbuf_addch (out,'\n' ); } }return count;
commit.h +1 -1
@@ -131,7 +131,7 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);extern int register_shallow (const unsigned char *sha1);extern int unregister_shallow (const unsigned char *sha1); -extern int write_shallow_commits (int fd,int use_pack_protocol); +extern int write_shallow_commits (struct strbuf *out,int use_pack_protocol);extern int is_repository_shallow (void );extern struct commit_list *get_shallow_commits (struct object_array *heads,int depth,int shallow_flag,int not_shallow_flag);
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 5/28 Move "get_ack()" back to fetch-pack
In reply to Shawn O. PearceIn 41cb7488 Linus moved this function to connect.c for reuse inside of the git-clone-pack command. That was 2005, but in 2006 Junio retired git-clone-pack in commit efc7fa53. Since then the only caller has been fetch-pack. Since this ACK/NAK exchange is only used by the fetch-pack/upload-pack protocol we should move it back to be a private detail of fetch-pack.
--- builtin-fetch-pack.c | 21 +++++++++++++++++++++ cache.h | 1 - connect.c | 21 --------------------- 3 files changed, 21 insertions(+), 22 deletions(-)
builtin-fetch-pack.c +21 -0
@@ -157,6 +157,27 @@ static const unsigned char *get_rev(void)return commit->object.sha1; } +static int get_ack (int fd,unsigned char *result_sha1) +{ +static char line[1000 ]; +int len =packet_read_line (fd, line,sizeof (line)); + +if (!len) +die ("git fetch-pack: expected ACK/NAK, got EOF" ); +if (line[len-1 ] =='\n' ) + line[--len] =0 ; +if (!strcmp (line,"NAK" )) +return 0 ; +if (!prefixcmp (line,"ACK " )) { +if (!get_sha1_hex (line+4 , result_sha1)) { +if (strstr (line+45 ,"continue" )) +return 2 ; +return 1 ; + } + } +die ("git fetch_pack: expected ACK/NAK, got '%s'" , line); +} +static int find_common (int fd[2 ],unsigned char *result_sha1,struct ref *refs) {
cache.h +0 -1
@@ -856,7 +856,6 @@ extern struct ref *find_ref_by_name(const struct ref *list, const char *name);extern struct child_process *git_connect (int fd[2 ],const char *url,const char *prog,int flags);extern int finish_connect (struct child_process *conn);extern int path_match (const char *path,int nr,char **match); -extern int get_ack (int fd,unsigned char *result_sha1);struct extra_have_objects {int nr, alloc;unsigned char (*array)[20 ];
connect.c +0 -21
@@ -107,27 +107,6 @@ int server_supports(const char *feature)strstr (server_capabilities, feature) !=NULL ; } -int get_ack (int fd,unsigned char *result_sha1) -{ -static char line[1000 ]; -int len =packet_read_line (fd, line,sizeof (line)); - -if (!len) -die ("git fetch-pack: expected ACK/NAK, got EOF" ); -if (line[len-1 ] =='\n' ) - line[--len] =0 ; -if (!strcmp (line,"NAK" )) -return 0 ; -if (!prefixcmp (line,"ACK " )) { -if (!get_sha1_hex (line+4 , result_sha1)) { -if (strstr (line+45 ,"continue" )) -return 2 ; -return 1 ; - } - } -die ("git fetch_pack: expected ACK/NAK, got '%s'" , line); -} -int path_match (const char *path,int nr,char **match) {int i;
Signature · 1 line
1.6.5.2.181.gd6f41
Shawn O. Pearce
NAKPATCH v5 6/28 Add multi_ack_detailed capability to fetch-pack/upload-pack
In reply to Shawn O. PearceWhen multi_ack_detailed is enabled the ACK continue messages returned by the remote upload-pack are broken out to describe the different states within the peer. This permits the client to better understand the server's in-memory state.
The fetch-pack/upload-pack protocol now looks like:
NAK
---------------------------------
Always sent in response to "done" if there was no common base selected from the "have" lines (or no have lines were sent).
* no multi_ack or multi_ack_detailed:
Sent when the client has sent a pkt-line flush ("0000") and the server has not yet found a common base object.
* either multi_ack or multi_ack_detailed:
Always sent in response to a pkt-line flush.
ACK %s
-----------------------------------
* no multi_ack or multi_ack_detailed:
Sent in response to "have" when the object exists on the remote side and is therefore an object in common between the peers. The argument is the SHA-1 of the common object.
* either multi_ack or multi_ack_detailed:
Sent in response to "done" if there are common objects. The argument is the last SHA-1 determined to be common.
ACK %s continue
-----------------------------------
* multi_ack only:
Sent in response to "have".
The remote side wants the client to consider this object as common, and immediately stop transmitting additional "have" lines for objects that are reachable from it. The reason the client should stop is not given, but is one of the two cases below available under multi_ack_detailed.
ACK %s common
-----------------------------------
* multi_ack_detailed only:
Sent in response to "have". Both sides have this object. Like with "ACK %s continue" above the client should stop sending have lines reachable for objects from the argument.
ACK %s ready
-----------------------------------
* multi_ack_detailed only:
Sent in response to "have".
The client should stop transmitting objects which are reachable from the argument, and send "done" soon to get the objects.
If the remote side has the specified object, it should first send an "ACK %s common" message prior to sending "ACK %s ready".
Clients may still submit additional "have" lines if there are more side branches for the client to explore that might be added to the common set and reduce the number of objects to transfer.
--- builtin-fetch-pack.c | 41 ++++++++++++++++++++++++++++++++--------- upload-pack.c | 31 ++++++++++++++++++------------- 2 files changed, 50 insertions(+), 22 deletions(-)
builtin-fetch-pack.c +32 -9
@@ -157,7 +157,15 @@ static const unsigned char *get_rev(void)return commit->object.sha1; } -static int get_ack (int fd,unsigned char *result_sha1) +enum ack_type { +NAK =0 , +ACK , + ACK_continue, + ACK_common, + ACK_ready +}; + +static enum ack_type get_ack (int fd,unsigned char *result_sha1) {static char line[1000 ];int len =packet_read_line (fd, line,sizeof (line));
@@ -167,12 +175,16 @@ static int get_ack(int fd, unsigned char *result_sha1)if (line[len-1 ] =='\n' ) line[--len] =0 ;if (!strcmp (line,"NAK" )) -return 0 ; +return NAK ;if (!prefixcmp (line,"ACK " )) {if (!get_sha1_hex (line+4 , result_sha1)) {if (strstr (line+45 ,"continue" )) -return 2 ; -return 1 ; +return ACK_continue; +if (strstr (line+45 ,"common" )) +return ACK_common; +if (strstr (line+45 ,"ready" )) +return ACK_ready; +return ACK ; } }die ("git fetch_pack: expected ACK/NAK, got '%s'" , line);
@@ -218,7 +230,8 @@ static int find_common(int fd[2], unsigned char *result_sha1, remote_hex =sha1_to_hex (remote);if (!fetching) {struct strbuf c =STRBUF_INIT ; -if (multi_ack)strbuf_addstr (&c," multi_ack" ); +if (multi_ack ==2 )strbuf_addstr (&c," multi_ack_detailed" ); +if (multi_ack ==1 )strbuf_addstr (&c," multi_ack" );if (use_sideband ==2 )strbuf_addstr (&c," side-band-64k" );if (use_sideband ==1 )strbuf_addstr (&c," side-band" );if (args.use_thin_pack)strbuf_addstr (&c," thin-pack" );
@@ -298,18 +311,23 @@ static int find_common(int fd[2], unsigned char *result_sha1,if (args.verbose && ack)fprintf (stderr,"got ack %d %s\n" , ack,sha1_to_hex (result_sha1)); -if (ack ==1 ) { +switch (ack) { +case ACK : flushes =0 ; multi_ack =0 ; retval =0 ; goto done; - }else if (ack ==2 ) { +case ACK_common: +case ACK_ready: +case ACK_continue: {struct commit *commit =lookup_commit (result_sha1);mark_common (commit,0 ,1 ); retval =0 ; in_vain =0 ; got_continue =1 ; +break ; + } } }while (ack); flushes--;
@@ -336,7 +354,7 @@ done:if (args.verbose)fprintf (stderr,"got ack (%d) %s\n" , ack,sha1_to_hex (result_sha1)); -if (ack ==1 ) +if (ack ==ACK )return 0 ; multi_ack =1 ;continue ;
@@ -618,7 +636,12 @@ static struct ref *do_fetch_pack(int fd[2],if (is_repository_shallow () && !server_supports ("shallow" ))die ("Server does not support shallow clients" ); -if (server_supports ("multi_ack" )) { +if (server_supports ("multi_ack_detailed" )) { +if (args.verbose) +fprintf (stderr,"Server supports multi_ack_detailed\n" ); + multi_ack =2 ; + } +else if (server_supports ("multi_ack" )) {if (args.verbose)fprintf (stderr,"Server supports multi_ack\n" ); multi_ack =1 ;
upload-pack.c +18 -13
@@ -498,7 +498,7 @@ static int get_common_commits(void) {static char line[1000 ];unsigned char sha1[20 ]; -char hex[41 ], last_hex[41 ]; +char last_hex[41 ]; save_commit_buffer =0 ;
@@ -515,19 +515,22 @@ static int get_common_commits(void)if (!prefixcmp (line,"have " )) {switch (got_sha1 (line+5 , sha1)) {case -1 :/* they have what we do not */ -if (multi_ack &&ok_to_give_up ()) -packet_write (1 ,"ACK %s continue\n" , -sha1_to_hex (sha1)); +if (multi_ack &&ok_to_give_up ()) { +const char *hex =sha1_to_hex (sha1); +if (multi_ack ==2 ) +packet_write (1 ,"ACK %s ready\n" , hex); +else +packet_write (1 ,"ACK %s continue\n" , hex); + }break ;default : -memcpy (hex,sha1_to_hex (sha1),41 ); -if (multi_ack) { -const char *msg ="ACK %s continue\n" ; -packet_write (1 , msg, hex); -memcpy (last_hex, hex,41 ); - } +memcpy (last_hex,sha1_to_hex (sha1),41 ); +if (multi_ack ==2 ) +packet_write (1 ,"ACK %s common\n" , last_hex); +else if (multi_ack) +packet_write (1 ,"ACK %s continue\n" , last_hex);else if (have_obj.nr ==1 ) -packet_write (1 ,"ACK %s\n" , hex); +packet_write (1 ,"ACK %s\n" , last_hex);break ; }continue ;
@@ -587,7 +590,9 @@ static void receive_needs(void) get_sha1_hex(line+5, sha1_buf))die ("git upload-pack: protocol error, " "expected to get sha, not '%s'" , line); -if (strstr (line+45 ,"multi_ack" )) +if (strstr (line+45 ,"multi_ack_detailed" )) + multi_ack =2 ; +else if (strstr (line+45 ,"multi_ack" )) multi_ack =1 ;if (strstr (line+45 ,"thin-pack" )) use_thin_pack =1 ;
@@ -681,7 +686,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo {static const char *capabilities ="multi_ack thin-pack side-band" " side-band-64k ofs-delta shallow no-progress" -" include-tag" ; +" include-tag multi_ack_detailed" ;struct object *o =parse_object (sha1);if (!o)
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 7/28 remote-curl: Refactor walker initialization
In reply to Shawn O. PearceWe will need the walker, url and remote in other functions as the code grows larger to support smart HTTP. Extract this out into a set of globals we can easily reference once configured.
--- remote-curl.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
remote-curl.c +14 -10
@@ -5,7 +5,17 @@#include "http.h" #include "exec_cmd.h" -static struct ref *get_refs (struct walker *walker,const char *url) +static struct remote *remote; +static const char *url; +static struct walker *walker; + +static void init_walker (void ) +{ +if (!walker) + walker =get_http_walker (url, remote); +} + +static struct ref *get_refs (void ) {struct strbuf buffer =STRBUF_INIT ;char *data, *start, *mid;
@@ -21,6 +31,7 @@ static struct ref *get_refs(struct walker *walker, const char *url) refs_url =xmalloc (strlen (url) +11 );sprintf (refs_url,"%s/info/refs" , url); +init_walker (); http_ret =http_get_strbuf (refs_url, &buffer,HTTP_NO_CACHE );switch (http_ret) {case HTTP_OK :
@@ -78,10 +89,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)int main (int argc,const char **argv) { -struct remote *remote;struct strbuf buf =STRBUF_INIT ; -const char *url; -struct walker *walker =NULL ;git_extract_argv0_path (argv[0 ]);setup_git_directory ();
@@ -103,8 +111,7 @@ int main(int argc, const char **argv)break ;if (!prefixcmp (buf.buf,"fetch " )) {char *obj = buf.buf +strlen ("fetch " ); -if (!walker) - walker =get_http_walker (url, remote); +init_walker (); walker->get_all =1 ; walker->get_tree =1 ; walker->get_history =1 ;
@@ -115,11 +122,8 @@ int main(int argc, const char **argv)printf ("\n" );fflush (stdout); }else if (!strcmp (buf.buf,"list" )) { -struct ref *refs; +struct ref *refs =get_refs ();struct ref *posn; -if (!walker) - walker =get_http_walker (url, remote); - refs =get_refs (walker, url);for (posn = refs; posn; posn = posn->next) {if (posn->symref)printf ("@%s %s\n" , posn->symref, posn->name);
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 8/28 fetch: Allow transport -v -v -v to set verbosity to 3
In reply to Shawn O. PearceHelpers might want a higher level of verbosity than just +1 (the porcelain default setting) and +2 (-v -v). Expand the field to allow verbosity in the range -1..3.
--- builtin-fetch.c | 2 +- transport.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
builtin-fetch.c +1 -1
@@ -665,7 +665,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) transport =transport_get (remote, remote->url[0 ]);if (verbosity >=2 ) - transport->verbose =1 ; + transport->verbose = verbosity <=3 ? verbosity :3 ;if (verbosity <0 ) transport->verbose =-1 ;if (upload_pack)
transport.h +1 -1
@@ -25,7 +25,7 @@ struct transport {int (*disconnect)(struct transport *connection);char *pack_lockfile; - signed verbose : 2; + signed verbose : 3;/* Force progress even if the output is not a tty */ unsigned progress : 1; };
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 9/28 remote-helpers: Fetch more than one ref in a batch
In reply to Shawn O. PearceSome network protocols (e.g. native git://) are able to fetch more than one ref at a time and reduce the overall transfer cost by combining the requests into a single exchange. Instead of feeding each fetch request one at a time to the helper, feed all of them at once so the helper can decide whether or not it should batch them.
--- Documentation/git-remote-helpers.txt | 14 ++++-- remote-curl.c | 88 +++++++++++++++++++++++++++++---- transport-helper.c | 39 +++++++++++---- 3 files changed, 115 insertions(+), 26 deletions(-)
Documentation/git-remote-helpers.txt +10 -4
@@ -36,10 +36,16 @@ Commands are given by the caller on the helper's standard input, one per line. complete list, outputs a blank line. 'fetch' <sha1> <name>:: - Fetches the given object, writing the necessary objects to the - database. Outputs a blank line when the fetch is - complete. Only objects which were reported in the ref list - with a sha1 may be fetched this way. + Fetches the given object, writing the necessary objects + to the database. Fetch commands are sent in a batch, one + per line, and the batch is terminated with a blank line. + Outputs a single blank line when all fetch commands in the + same batch are complete. Only objects which were reported + in the ref list with a sha1 may be fetched this way. ++ +Optionally may output a 'lock <file>' line indicating a file under +GIT_DIR/objects/pack which is keeping a pack until refs can be +suitably updated. + Supported if the helper has the "fetch" capability.
remote-curl.c +77 -11
100 lines not on this page · raw message
transport-helper.c +28 -11
@@ -10,6 +10,7 @@ struct helper_data {const char *name;struct child_process *helper; +FILE *out; unsigned fetch : 1; };
@@ -18,7 +19,6 @@ static struct child_process *get_helper(struct transport *transport)struct helper_data *data = transport->data;struct strbuf buf =STRBUF_INIT ;struct child_process *helper; -FILE *file;if (data->helper)return data->helper;
@@ -39,9 +39,9 @@ static struct child_process *get_helper(struct transport *transport)write_str_in_full (helper->in,"capabilities\n" ); - file =xfdopen (helper->out,"r" ); + data->out =xfdopen (helper->out,"r" );while (1 ) { -if (strbuf_getline (&buf, file,'\n' ) ==EOF ) +if (strbuf_getline (&buf, data->out,'\n' ) ==EOF )exit (128 );/* child died, message supplied already */ if (!*buf.buf)
@@ -58,6 +58,7 @@ static int disconnect_helper(struct transport *transport)if (data->helper) {write_str_in_full (data->helper->in,"\n" );close (data->helper->in); +fclose (data->out);finish_command (data->helper);free ((char *)data->helper->argv[0 ]);free (data->helper->argv);
@@ -70,8 +71,7 @@ static int disconnect_helper(struct transport *transport)static int fetch_with_fetch (struct transport *transport,int nr_heads,const struct ref **to_fetch) { -struct child_process *helper =get_helper (transport); -FILE *file =xfdopen (helper->out,"r" ); +struct helper_data *data = transport->data;int i;struct strbuf buf =STRBUF_INIT ;
@@ -82,12 +82,30 @@ static int fetch_with_fetch(struct transport *transport,strbuf_addf (&buf,"fetch %s %s\n" ,sha1_to_hex (posn->old_sha1), posn->name); -write_in_full (helper->in, buf.buf, buf.len); -strbuf_reset (&buf); + } -if (strbuf_getline (&buf, file,'\n' ) ==EOF ) +strbuf_addch (&buf,'\n' ); +if (write_in_full (data->helper->in, buf.buf, buf.len) != buf.len) +die_errno ("cannot send fetch to %s" , data->name); + +while (1 ) { +strbuf_reset (&buf); +if (strbuf_getline (&buf, data->out,'\n' ) ==EOF )exit (128 );/* child died, message supplied already */ + +if (!prefixcmp (buf.buf,"lock " )) { +const char *name = buf.buf +5 ; +if (transport->pack_lockfile) +warning ("%s also locked %s" , data->name, name); +else + transport->pack_lockfile =xstrdup (name); + } +else if (!buf.len) +break ; +else +warning ("%s unexpectedly said: '%s'" , data->name, buf.buf); } +strbuf_release (&buf);return 0 ; }
@@ -113,21 +131,20 @@ static int fetch(struct transport *transport,static struct ref *get_refs_list (struct transport *transport,int for_push) { +struct helper_data *data = transport->data;struct child_process *helper;struct ref *ret =NULL ;struct ref **tail = &ret;struct ref *posn;struct strbuf buf =STRBUF_INIT ; -FILE *file; helper =get_helper (transport);write_str_in_full (helper->in,"list\n" ); - file =xfdopen (helper->out,"r" );while (1 ) {char *eov, *eon; -if (strbuf_getline (&buf, file,'\n' ) ==EOF ) +if (strbuf_getline (&buf, data->out,'\n' ) ==EOF )exit (128 );/* child died, message supplied already */ if (!*buf.buf)
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 10/28 remote-helpers: Support custom transport options
In reply to Shawn O. PearceSome transports, like the native pack transport implemented by fetch-pack, support useful features like depth or include tags. These should be exposed if the underlying helper knows how to use them.
--- Documentation/git-remote-helpers.txt | 38 +++++++++++++++ remote-curl.c | 74 ++++++++++++++++++++++++++++- transport-helper.c | 88 +++++++++++++++++++++++++++++++++- 3 files changed, 198 insertions(+), 2 deletions(-)
Documentation/git-remote-helpers.txt +38 -0
@@ -35,6 +35,16 @@ Commands are given by the caller on the helper's standard input, one per line. the name; unrecognized attributes are ignored. After the complete list, outputs a blank line. +'option' <name> <value>:: + Set the transport helper option <name> to <value>. Outputs a + single line containing one of 'ok' (option successfully set), + 'unsupported' (option not recognized) or 'error <msg>' + (option <name> is supported but <value> is not correct + for it). Options should be set before other commands, + and may how those commands behave. ++ +Supported if the helper has the "option" capability. + 'fetch' <sha1> <name>:: Fetches the given object, writing the necessary objects to the database. Fetch commands are sent in a batch, one
@@ -63,11 +73,39 @@ CAPABILITIES 'fetch':: This helper supports the 'fetch' command. +'option':: + This helper supports the option command. + REF LIST ATTRIBUTES ------------------- None are defined yet, but the caller must accept any which are supplied. +OPTIONS +------- +'option verbosity' <N>:: + Change the level of messages displayed by the helper. + When N is 0 the end-user has asked the process to be + quiet, and the helper should produce only error output. + N of 1 is the default level of verbosity, higher values + of N correspond to the number of -v flags passed on the + command line. + +'option progress' \{'true'|'false'\}:: + Enable (or disable) progress messages displayed by the + transport helper during a command. + +'option depth' <depth>:: + Deepen the history of a shallow repository. + +'option followtags' \{'true'|'false'\}:: + If enabled the helper should automatically fetch annotated + tag objects if the object the tag points at was transferred + during the fetch command. If the tag is not fetched by + the helper a second fetch command will usually be sent to + ask for the tag specifically. Some helpers may be able to + use this option to avoid a second network connection. + Documentation ------------- Documentation by Daniel Barkalow.
remote-curl.c +73 -1
106 lines not on this page · raw message
transport-helper.c +87 -1
127 lines not on this page · raw message
Signature · 1 line
1.6.5.2.181.gd6f41
v5 cover interdiff to v4
In reply to Shawn O. Pearcepkt-line.c +3 -5
@@ -124,14 +124,12 @@ static int packet_length(const char *linelen)int packet_read_line (int fd,char *buffer,unsigned size) {int len; -char linelen[5 ]; +char linelen[4 ];safe_read (fd, linelen,4 ); len =packet_length (linelen); -if (len <0 ) { - linelen[4 ] ='\0' ; -die ("protocol error: bad line length character: %s" , linelen); - } +if (len <0 ) +die ("protocol error: bad line length character: %.4s" , linelen);if (!len)return 0 ; len -=4 ;
t/lib-httpd/apache.conf +8 -6
@@ -8,20 +8,22 @@ ErrorLog error.log <IfModule !mod_log_config.c> LoadModule log_config_module modules/mod_log_config.so </IfModule> -<IfModule !mod_cgi.c> - LoadModule cgi_module modules/mod_cgi.so -</IfModule> <IfModule !mod_alias.c> LoadModule alias_module modules/mod_alias.so </IfModule> +<IfModule !mod_cgi.c> + LoadModule cgi_module modules/mod_cgi.so +</IfModule> <IfModule !mod_env.c> LoadModule env_module modules/mod_env.so </IfModule> -<Location /git/> +Alias /dumb/ www/ + +<Location /smart/> SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} </Location> -ScriptAlias /git/ ${GIT_EXEC_PATH}/git-http-backend/ +ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/ <Directory ${GIT_EXEC_PATH}> Options None </Directory>
@@ -46,7 +48,7 @@ SSLEngine On LoadModule dav_fs_module modules/mod_dav_fs.so DAVLockDB DAVLock - <Location /> + <Location /dumb/> Dav on </Location> </IfDefine>
t/t5540-http-push.sh +8 -9
@@ -9,17 +9,16 @@ This test runs various sanity checks on http-push.' . ./test-lib.sh -ROOT_PATH="$PWD" -LIB_HTTPD_DAV=t -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'} - if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] then say "skipping test, USE_CURL_MULTI is not defined" test_done fi +LIB_HTTPD_DAV=t +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'} . "$TEST_DIRECTORY"/lib-httpd.sh +ROOT_PATH="$PWD" start_httpd test_expect_success 'setup remote repository' '
@@ -43,7 +42,7 @@ test_expect_success 'setup remote repository' ' test_expect_success 'clone remote repository' ' cd "$ROOT_PATH" && - git clone $HTTPD_URL/test_repo.git test_repo_clone + git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone ' test_expect_success 'push to remote repository with packed refs' '
@@ -76,7 +75,7 @@ test_expect_success 'http-push fetches unpacked objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && - git clone $HTTPD_URL/test_repo_unpacked.git \ + git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ "$ROOT_PATH"/fetch_unpacked && # By reset, we force git to retrieve the object
@@ -85,14 +84,14 @@ test_expect_success 'http-push fetches unpacked objects' ' git remote rm origin && git reflog expire --expire=0 --all && git prune && - git push -f -v $HTTPD_URL/test_repo_unpacked.git master) + git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master) ' test_expect_success 'http-push fetches packed objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && - git clone $HTTPD_URL/test_repo_packed.git \ + git clone $HTTPD_URL/dumb/test_repo_packed.git \ "$ROOT_PATH"/test_repo_clone_packed && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
@@ -105,7 +104,7 @@ test_expect_success 'http-push fetches packed objects' ' git remote rm origin && git reflog expire --expire=0 --all && git prune && - git push -f -v $HTTPD_URL/test_repo_packed.git master) + git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master) ' test_expect_success 'create and delete remote branch' '
t/t5541-http-push.sh +12 -23
@@ -12,7 +12,7 @@ if test -n "$NO_CURL"; then fi ROOT_PATH="$PWD" -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'} +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'} . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd
@@ -36,10 +36,10 @@ test_expect_success 'setup remote repository' ' test_expect_success 'clone remote repository' ' cd "$ROOT_PATH" && - git clone $HTTPD_URL/git/test_repo.git test_repo_clone + git clone $HTTPD_URL/smart/test_repo.git test_repo_clone ' -test_expect_success 'push to remote repository with packed refs' ' +test_expect_success 'push to remote repository' ' cd "$ROOT_PATH"/test_repo_clone && : >path2 && git add path2 &&
@@ -55,15 +55,6 @@ test_expect_success 'push already up-to-date' ' git push ' -test_expect_success 'push to remote repository with unpacked refs' ' - (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - rm packed-refs && - git update-ref refs/heads/master $ORIG_HEAD) && - git push && - (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && - test $HEAD = $(git rev-parse --verify HEAD)) -' - test_expect_success 'create and delete remote branch' ' cd "$ROOT_PATH"/test_repo_clone && git checkout -b dev &&
@@ -77,17 +68,15 @@ test_expect_success 'create and delete remote branch' ' ' cat >exp <<EOF -GET /git/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 -POST /git/test_repo.git/git-upload-pack HTTP/1.1 200 -GET /git/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 -POST /git/test_repo.git/git-receive-pack HTTP/1.1 200 -GET /git/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 -GET /git/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 -POST /git/test_repo.git/git-receive-pack HTTP/1.1 200 -GET /git/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 -POST /git/test_repo.git/git-receive-pack HTTP/1.1 200 -GET /git/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 -POST /git/test_repo.git/git-receive-pack HTTP/1.1 200 +GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 +POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200 +GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 +POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 +GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 +GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 +POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 +GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200 +POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200 EOF test_expect_success 'used receive-pack service' ' sed -e "
t/t5550-http-fetch.sh +2 -2
@@ -30,7 +30,7 @@ test_expect_success 'create http-accessible bare repository' ' ' test_expect_success 'clone http repository' ' - git clone $HTTPD_URL/repo.git clone && + git clone $HTTPD_URL/dumb/repo.git clone && test_cmp file clone/file '
@@ -58,7 +58,7 @@ test_expect_success 'fetch packed objects' ' cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && git --bare repack && git --bare prune-packed && - git clone $HTTPD_URL/repo_pack.git + git clone $HTTPD_URL/dumb/repo_pack.git ' test_expect_success 'did not use upload-pack service' '
t/t5551-http-fetch.sh +13 -13
@@ -8,7 +8,7 @@ if test -n "$NO_CURL"; then test_done fi -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'} +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'} . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd
@@ -28,19 +28,21 @@ test_expect_success 'create http-accessible bare repository' ' ' cat >exp <<EOF -> GET /git/repo.git/info/refs?service=git-upload-pack HTTP/1.1 -Accept: */* -Pragma: no-cache +> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 +> Accept: */* +> Pragma: no-cache + < HTTP/1.1 200 OK < Pragma: no-cache < Cache-Control: no-cache, max-age=0, must-revalidate < Content-Type: application/x-git-upload-pack-advertisement < -> POST /git/repo.git/git-upload-pack HTTP/1.1 -Accept-Encoding: deflate, gzip -Content-Type: application/x-git-upload-pack-request -Accept: application/x-git-upload-pack-response -Content-Length: xxxx +> POST /smart/repo.git/git-upload-pack HTTP/1.1 +> Accept-Encoding: deflate, gzip +> Content-Type: application/x-git-upload-pack-request +> Accept: application/x-git-upload-pack-response +> Content-Length: xxx + < HTTP/1.1 200 OK < Pragma: no-cache < Cache-Control: no-cache, max-age=0, must-revalidate
@@ -48,13 +50,26 @@ Content-Length: xxxx < EOF test_expect_success 'clone http repository' ' - GIT_CURL_VERBOSE=1 git clone $HTTPD_URL/git/repo.git clone 2>err && + GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err && test_cmp file clone/file && - egrep "^([<>]|Pragma|Accept|Content-|Transfer-)" err | - egrep -v "^< (Server|Expires|Date|Content-Length:|Transfer-Encoding: chunked)" | + tr '\''\015'\'' Q <err | sed -e " - s/
//
- s/^Content-Length: .*$/Content-Length: xxxx/
+ s/Q\$//
+ /^[*] /d
+
+ /^[^><]/{
+ s/^/> /
+ }
+
+ /^> User-Agent: /d
+ /^> Host: /d
+ s/^> Content-Length: .*/> Content-Length: xxx/
+
+ /^< Server: /d
+ /^< Expires: /d
+ /^< Date: /d
+ /^< Content-Length: /d
+ /^< Transfer-Encoding: /d
" >act &&
test_cmp exp act
'
@@ -68,10 +83,10 @@ test_expect_success 'fetch changes via http' '
'
cat >exp <<EOF
-GET /git/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 -POST /git/repo.git/git-upload-pack HTTP/1.1 200
-GET /git/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 -POST /git/repo.git/git-upload-pack HTTP/1.1 200
+GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 +POST /smart/repo.git/git-upload-pack HTTP/1.1 200
+GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200 +POST /smart/repo.git/git-upload-pack HTTP/1.1 200
EOF
test_expect_success 'used upload-pack service' '
sed -e "
PATCH v5 11/28 Move WebDAV HTTP push under remote-curl
In reply to Shawn O. PearceThe remote helper interface now supports the push capability, which can be used to ask the implementation to push one or more specs to the remote repository. For remote-curl we implement this by calling the existing WebDAV based git-http-push executable.
Internally the helper interface uses the push_refs transport hook so that the complexity of the refspec parsing and matching can be reused between remote implementations. When possible however the helper protocol uses source ref name rather than the source SHA-1, thereby allowing the helper to access this name if it is useful.
Quoted 1 line
From Clemens Buchacher <[email protected]>:
update http tests according to remote-curl capabilities
o Pushing packed refs is now fixed.
o The transport helper fails if refs are already up-to-date. Add a test for that.
o The transport helper will notice if refs are already up-to-date. We therefore need to update server info in the unpacked-refs test.
o The transport helper will purge deleted branches automatically.
o Use a variable ($ORIG_HEAD) instead of full SHA-1 name.
--- Documentation/git-remote-helpers.txt | 33 ++++++++- http-push.c | 29 +++++++- remote-curl.c | 97 +++++++++++++++++++++--- t/t5540-http-push.sh | 14 ++- transport-helper.c | 137 +++++++++++++++++++++++++++++++++- transport.c | 31 -------- 6 files changed, 287 insertions(+), 54 deletions(-)
Documentation/git-remote-helpers.txt +32 -1
@@ -34,6 +34,10 @@ Commands are given by the caller on the helper's standard input, one per line. value of the ref. A space-separated list of attributes follows the name; unrecognized attributes are ignored. After the complete list, outputs a blank line. ++ +If 'push' is supported this may be called as 'list for-push' +to obtain the current refs prior to sending one or more 'push' +commands to the helper. 'option' <name> <value>:: Set the transport helper option <name> to <value>. Outputs a
@@ -59,6 +63,22 @@ suitably updated. + Supported if the helper has the "fetch" capability. +'push' +<src>:<dst>:: + Pushes the given <src> commit or branch locally to the + remote branch described by <dst>. A batch sequence of + one or more push commands is terminated with a blank line. ++ +Zero or more protocol options may be entered after the last 'push' +command, before the batch's terminating blank line. ++ +When the push is complete, outputs one or more 'ok <dst>' or +'error <dst> <why>?' lines to indicate success or failure of +each pushed ref. The status report output is terminated by +a blank line. The option field <why> may be quoted in a C +style string if it contains an LF. ++ +Supported if the helper has the "push" capability. + If a fatal error occurs, the program writes the error message to stderr and exits. The caller should expect that a suitable error message has been printed if the child closes the connection without
@@ -76,10 +96,16 @@ CAPABILITIES 'option':: This helper supports the option command. +'push':: + This helper supports the 'push' command. + REF LIST ATTRIBUTES ------------------- -None are defined yet, but the caller must accept any which are supplied. +'for-push':: + The caller wants to use the ref list to prepare push + commands. A helper might chose to acquire the ref list by + opening a different type of connection to the destination. OPTIONS -------
@@ -106,6 +132,11 @@ OPTIONS ask for the tag specifically. Some helpers may be able to use this option to avoid a second network connection. +'option dry-run' \{'true'|'false'\}: + If true, pretend the operation completed successfully, + but don't actually change any repository data. For most + helpers this only applies to the 'push', if supported. + Documentation ------------- Documentation by Daniel Barkalow.
http-push.c +27 -2
@@ -78,6 +78,7 @@ static int push_verbosely;static int push_all =MATCH_REFS_NONE ;static int force_all;static int dry_run; +static int helper_status;static struct object_list *objects;
@@ -1813,6 +1814,10 @@ int main(int argc, char **argv) dry_run =1 ;continue ; } +if (!strcmp (arg,"--helper-status" )) { + helper_status =1 ; +continue ; + }if (!strcmp (arg,"--verbose" )) { push_verbosely =1 ; http_is_verbose =1 ;
@@ -1911,9 +1916,12 @@ int main(int argc, char **argv)/* Remove a remote branch if -d or -D was specified */ if (delete_branch) { -if (delete_remote_branch (refspec[0 ], force_delete) ==-1 ) +if (delete_remote_branch (refspec[0 ], force_delete) ==-1 ) {fprintf (stderr,"Unable to delete remote branch %s\n" , refspec[0 ]); +if (helper_status) +printf ("error %s cannot remove\n" , refspec[0 ]); + } goto cleanup; }
@@ -1925,6 +1933,8 @@ int main(int argc, char **argv) }if (!remote_refs) {fprintf (stderr,"No refs in common and none specified; doing nothing.\n" ); +if (helper_status) +printf ("error null no match\n" ); rc =0 ; goto cleanup; }
@@ -1942,8 +1952,12 @@ int main(int argc, char **argv)if (is_null_sha1 (ref->peer_ref->new_sha1)) {if (delete_remote_branch (ref->name,1 ) ==-1 ) {error ("Could not remove %s" , ref->name); +if (helper_status) +printf ("error %s cannot remove\n" , ref->name); rc =-4 ; } +else if (helper_status) +printf ("ok %s\n" , ref->name); new_refs++;continue ; }
@@ -1951,6 +1965,8 @@ int main(int argc, char **argv)if (!hashcmp (ref->old_sha1, ref->peer_ref->new_sha1)) {if (push_verbosely ||1 )fprintf (stderr,"'%s': up-to-date\n" , ref->name); +if (helper_status) +printf ("ok %s up to date\n" , ref->name);continue ; }
@@ -1974,6 +1990,8 @@ int main(int argc, char **argv)"need to pull first?" , ref->name, ref->peer_ref->name); +if (helper_status) +printf ("error %s non-fast forward\n" , ref->name); rc =-2 ;continue ; }
@@ -1987,14 +2005,19 @@ int main(int argc, char **argv)if (strcmp (ref->name, ref->peer_ref->name))fprintf (stderr," using '%s'" , ref->peer_ref->name);fprintf (stderr,"\n from %s\n to %s\n" , old_hex, new_hex); -if (dry_run) +if (dry_run) { +if (helper_status) +printf ("ok %s\n" , ref->name);continue ; + }/* Lock remote branch ref */ ref_lock =lock_remote (ref->name,LOCK_TIME );if (ref_lock ==NULL ) {fprintf (stderr,"Unable to lock remote branch %s\n" , ref->name); +if (helper_status) +printf ("error %s lock error\n" , ref->name); rc =1 ;continue ; }
@@ -2045,6 +2068,8 @@ int main(int argc, char **argv)if (!rc)fprintf (stderr," done\n" ); +if (helper_status) +printf ("%s %s\n" , !rc ?"ok" :"error" , ref->name);unlock_remote (ref_lock);check_locks (); }
remote-curl.c +85 -12
139 lines not on this page · raw message
t/t5540-http-push.sh +9 -5
@@ -36,6 +36,7 @@ test_expect_success 'setup remote repository' ' cd test_repo.git && git --bare update-server-info && mv hooks/post-update.sample hooks/post-update && + ORIG_HEAD=$(git rev-parse --verify HEAD) && cd - && mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" '
@@ -45,7 +46,7 @@ test_expect_success 'clone remote repository' ' git clone $HTTPD_URL/test_repo.git test_repo_clone ' -test_expect_failure 'push to remote repository with packed refs' ' +test_expect_success 'push to remote repository with packed refs' ' cd "$ROOT_PATH"/test_repo_clone && : >path2 && git add path2 &&
@@ -57,11 +58,15 @@ test_expect_failure 'push to remote repository with packed refs' ' test $HEAD = $(git rev-parse --verify HEAD)) ' -test_expect_success ' push to remote repository with unpacked refs' ' +test_expect_failure 'push already up-to-date' ' + git push +' + +test_expect_success 'push to remote repository with unpacked refs' ' (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && rm packed-refs && - git update-ref refs/heads/master \ - 0c973ae9bd51902a28466f3850b543fa66a6aaf4) && + git update-ref refs/heads/master $ORIG_HEAD && + git --bare update-server-info) && git push && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && test $HEAD = $(git rev-parse --verify HEAD))
@@ -113,7 +118,6 @@ test_expect_success 'create and delete remote branch' ' git push origin dev && git fetch && git push origin :dev && - git branch -d -r origin/dev && git fetch && test_must_fail git show-ref --verify refs/remotes/origin/dev '
transport-helper.c +134 -3
172 lines not on this page · raw message
transport.c +0 -31
@@ -349,35 +349,6 @@ static int rsync_transport_push(struct transport *transport,return result; } -#ifndef NO_CURL -static int curl_transport_push (struct transport *transport,int refspec_nr,const char **refspec,int flags) -{ -const char **argv; -int argc; - -if (flags &TRANSPORT_PUSH_MIRROR ) -return error ("http transport does not support mirror mode" ); - - argv =xmalloc ((refspec_nr +12 ) *sizeof (char *)); - argv[0 ] ="http-push" ; - argc =1 ; -if (flags &TRANSPORT_PUSH_ALL ) - argv[argc++] ="--all" ; -if (flags &TRANSPORT_PUSH_FORCE ) - argv[argc++] ="--force" ; -if (flags &TRANSPORT_PUSH_DRY_RUN ) - argv[argc++] ="--dry-run" ; -if (flags &TRANSPORT_PUSH_VERBOSE ) - argv[argc++] ="--verbose" ; - argv[argc++] = transport->url; -while (refspec_nr--) - argv[argc++] = *refspec++; - argv[argc] =NULL ; -return !!run_command_v_opt (argv,RUN_GIT_CMD ); -} - -#endif -struct bundle_transport_data {int fd;struct bundle_header header;
@@ -826,8 +797,6 @@ struct transport *transport_get(struct remote *remote, const char *url)transport_helper_init (ret,"curl" );#ifdef NO_CURL error ("git was compiled without libcurl support." ); -#else - ret->push = curl_transport_push;#endif }else if (is_local (url) &&is_file (url)) {
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 12/28 remote-helpers: return successfully if everything up-to-date
In reply to Shawn O. PearceFrom: Clemens Buchacher <[email protected]>
--- t/t5540-http-push.sh | 2 +- transport-helper.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletions(-)
t/t5540-http-push.sh +1 -1
@@ -58,7 +58,7 @@ test_expect_success 'push to remote repository with packed refs' ' test $HEAD = $(git rev-parse --verify HEAD)) ' -test_expect_failure 'push already up-to-date' ' +test_expect_success 'push already up-to-date' ' git push '
transport-helper.c +2 -0
@@ -263,6 +263,8 @@ static int push_refs(struct transport *transport,strbuf_addstr (&buf, ref->name);strbuf_addch (&buf,'\n' ); } +if (buf.len ==0 ) +return 0 ; transport->verbose = flags &TRANSPORT_PUSH_VERBOSE ?1 :0 ;standard_options (transport);
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 13/28 Git-aware CGI to provide dumb HTTP transport
In reply to Shawn O. PearceThe git-http-backend CGI can be configured into any Apache server using ScriptAlias, such as with the following configuration:
LoadModule cgi_module /usr/libexec/apache2/mod_cgi.so LoadModule alias_module /usr/libexec/apache2/mod_alias.so ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
Repositories are accessed via the translated PATH_INFO.
The CGI is backwards compatible with the dumb client, allowing all older HTTP clients to continue to download repositories which are managed by the CGI.
--- .gitignore | 1 + Documentation/git-http-backend.txt | 105 +++++++++++++ Makefile | 1 + http-backend.c | 290 ++++++++++++++++++++++++++++++++++++ 4 files changed, 397 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-http-backend.txt create mode 100644 http-backend.c
.gitignore +1 -0
@@ -55,6 +55,7 @@ git-get-tar-commit-id git-grep git-hash-object git-help +git-http-backend git-http-fetch git-http-push git-imap-send
Documentation/git-http-backend.txt new file +105 -0
105 lines not on this page · raw message
Makefile +1 -0
@@ -365,6 +365,7 @@ PROGRAMS += git-show-index$X PROGRAMS += git-unpack-file$X PROGRAMS += git-upload-pack$X PROGRAMS += git-var$X +PROGRAMS += git-http-backend$X # List built-in command $C whose implementation cmd_$C() is not in # builtin-$C.o but is linked in as part of some other command.
http-backend.c new file +290 -0
290 lines not on this page · raw message
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 14/28 Add stateless RPC options to upload-pack, receive-pack
In reply to Shawn O. PearceWhen --stateless-rpc is passed as a command line parameter to upload-pack or receive-pack the programs now assume they may perform only a single read-write cycle with stdin and stdout. This fits with the HTTP POST request processing model where a program may read the request, write a response, and must exit.
When --advertise-refs is passed as a command line parameter only the initial ref advertisement is output, and the program exits immediately. This fits with the HTTP GET request model, where no request content is received but a response must be produced.
HTTP headers and/or environment are not processed here, but instead are assumed to be handled by the program invoking either service backend.
--- builtin-receive-pack.c | 26 ++++++++++++++++++++------ upload-pack.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-)
builtin-receive-pack.c +20 -6
@@ -615,6 +615,8 @@ static void add_alternate_refs(void)int cmd_receive_pack (int argc,const char **argv,const char *prefix) { +int advertise_refs =0 ; +int stateless_rpc =0 ;int i;char *dir =NULL ;
@@ -623,7 +625,15 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)const char *arg = *argv++;if (*arg =='-' ) { -/* Do flag handling here */ +if (!strcmp (arg,"--advertise-refs" )) { + advertise_refs =1 ; +continue ; + } +if (!strcmp (arg,"--stateless-rpc" )) { + stateless_rpc =1 ; +continue ; + } +usage (receive_pack_usage); }if (dir)
@@ -652,12 +662,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) " report-status delete-refs ofs-delta " :" report-status delete-refs " ; -add_alternate_refs (); -write_head_info (); -clear_extra_refs (); +if (advertise_refs || !stateless_rpc) { +add_alternate_refs (); +write_head_info (); +clear_extra_refs (); -/* EOF */ -packet_flush (1 ); +/* EOF */ +packet_flush (1 ); + } +if (advertise_refs) +return 0 ;read_head_info ();if (commands) {
upload-pack.c +36 -4
@@ -39,6 +39,8 @@ static unsigned int timeout;*/ static int use_sideband;static int debug_fd; +static int advertise_refs; +static int stateless_rpc;static void reset_timeout (void ) {
@@ -509,6 +511,8 @@ static int get_common_commits(void)if (!len) {if (have_obj.nr ==0 || multi_ack)packet_write (1 ,"NAK\n" ); +if (stateless_rpc) +exit (0 );continue ; }strip (line, len);
@@ -710,12 +714,32 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, voreturn 0 ; } +static int mark_our_ref (const char *refname,const unsigned char *sha1,int flag,void *cb_data) +{ +struct object *o =parse_object (sha1); +if (!o) +die ("git upload-pack: cannot find object %s:" ,sha1_to_hex (sha1)); +if (!(o->flags &OUR_REF )) { + o->flags |=OUR_REF ; + nr_our_refs++; + } +return 0 ; +} +static void upload_pack (void ) { -reset_timeout (); -head_ref (send_ref,NULL ); -for_each_ref (send_ref,NULL ); -packet_flush (1 ); +if (advertise_refs || !stateless_rpc) { +reset_timeout (); +head_ref (send_ref,NULL ); +for_each_ref (send_ref,NULL ); +packet_flush (1 ); + }else { +head_ref (mark_our_ref,NULL ); +for_each_ref (mark_our_ref,NULL ); + } +if (advertise_refs) +return ; +receive_needs ();if (want_obj.nr) {get_common_commits ();
@@ -737,6 +761,14 @@ int main(int argc, char **argv)if (arg[0 ] !='-' )break ; +if (!strcmp (arg,"--advertise-refs" )) { + advertise_refs =1 ; +continue ; + } +if (!strcmp (arg,"--stateless-rpc" )) { + stateless_rpc =1 ; +continue ; + }if (!strcmp (arg,"--strict" )) { strict =1 ;continue ;
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 15/28 Smart fetch and push over HTTP: server side
In reply to Shawn O. PearceRequests for $GIT_URL/git-receive-pack and $GIT_URL/git-upload-pack are forwarded to the corresponding backend process by directly executing it and leaving stdin and stdout connected to the invoking web server. Prior to starting the backend process the HTTP response headers are sent, thereby freeing the backend from needing to know about the HTTP protocol.
Requests that are encoded with Content-Encoding: gzip are automatically inflated before being streamed into the backend. This is primarily useful for the git-upload-pack backend, which receives highly repetitive text data from clients that easily compresses to 50% of its original size.
--- Documentation/git-http-backend.txt | 39 +++++- http-backend.c | 324 +++++++++++++++++++++++++++++++++++- 2 files changed, 359 insertions(+), 4 deletions(-)
Documentation/git-http-backend.txt +38 -1
@@ -22,6 +22,23 @@ By default, only the `upload-pack` service is enabled, which serves This is ideally suited for read-only updates, i.e., pulling from git repositories. +SERVICES +-------- +These services can be enabled/disabled using the per-repository +configuration file: + +http.uploadpack:: + This serves 'git-fetch-pack' and 'git-ls-remote' clients. + It is enabled by default, but a repository can disable it + by setting this configuration item to `false`. + +http.receivepack:: + This serves 'git-send-pack' clients, allowing push. It is + disabled by default for anonymous users, and enabled by + default for users authenticated by the web server. It can be + disabled by setting this item to `false`, or enabled for all + users, including anonymous users, by setting it to `true`. + URL TRANSLATION --------------- 'git-http-backend' relies on the invoking web server to perform
@@ -49,7 +66,19 @@ ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/ </Files> ---------------------------------------------------------------- + -To require authentication for reads, use a Directory +To enable anonymous read access but authenticated write access, +require authorization with a LocationMatch directive: ++ +---------------------------------------------------------------- +<LocationMatch ".*/git-receive-pack$"> + AuthType Basic + AuthName "Git Access" + Require group committers + ... +</LocationMatch> +---------------------------------------------------------------- ++ +To require authentication for both reads and writes, use a Directory directive around the repository, or one of its parent directories: + ----------------------------------------------------------------
@@ -92,6 +121,14 @@ by the invoking web server, including: * QUERY_STRING * REQUEST_METHOD +The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and +GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}', +ensuring that any reflogs created by 'git-receive-pack' contain some +identifying information of the remote user who performed the push. + +All CGI environment variables are available to each of the hooks +invoked by the 'git-receive-pack'. + Author ------ Written by Shawn O. Pearce <[email protected]>.
http-backend.c +321 -3
368 lines not on this page · raw message
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 16/28 http-backend: add GIT_PROJECT_ROOT environment var
In reply to Shawn O. PearceFrom: Mark Lodato <[email protected]>
Add a new environment variable, GIT_PROJECT_ROOT, to override the method of using PATH_TRANSLATED to find the git repository on disk. This makes it much easier to configure the web server, especially when the web server's DocumentRoot does not contain the git repositories, which is the usual case.
--- Documentation/git-http-backend.txt | 39 +++++++++++++++-------------------- http-backend.c | 25 ++++++++++++++++++++-- 2 files changed, 39 insertions(+), 25 deletions(-)
Documentation/git-http-backend.txt +17 -22
@@ -41,29 +41,24 @@ http.receivepack:: URL TRANSLATION --------------- -'git-http-backend' relies on the invoking web server to perform -URL to path translation, and store the repository path into the -PATH_TRANSLATED environment variable. Most web servers will do -this translation automatically, resolving the suffix after the -CGI name relative to the server's document root. +To determine the location of the repository on disk, 'git-http-backend' +concatenates the environment variables PATH_INFO, which is set +automatically by the web server, and GIT_PROJECT_ROOT, which must be set +manually in the web server configuration. If GIT_PROJECT_ROOT is not +set, 'git-http-backend' reads PATH_TRANSLATED, which is also set +automatically by the web server. EXAMPLES -------- Apache 2.x:: - To serve all Git repositories contained within the '/git/' - subdirectory of the DocumentRoot, ensure mod_cgi and - mod_alias are enabled, and create a ScriptAlias to the CGI: + Ensure mod_cgi, mod_alias, and mod_env are enabled, set + GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and + create a ScriptAlias to the CGI: + ---------------------------------------------------------------- -ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/ - -<Directory /usr/libexec/git-core> - Options None -</Directory> -<Files /usr/libexec/git-core/git-http-backend> - Options ExecCGI -</Files> +SetEnv GIT_PROJECT_ROOT /var/www/git +ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ ---------------------------------------------------------------- + To enable anonymous read access but authenticated write access,
@@ -78,16 +73,16 @@ require authorization with a LocationMatch directive: </LocationMatch> ---------------------------------------------------------------- + -To require authentication for both reads and writes, use a Directory +To require authentication for both reads and writes, use a Location directive around the repository, or one of its parent directories: + ---------------------------------------------------------------- -<Directory /var/www/git/private> +<Location /git/private> AuthType Basic AuthName "Private Git Access" Require group committers ... -</Directory> +</Location> ---------------------------------------------------------------- Accelerated static Apache 2.x::
@@ -97,9 +92,9 @@ Accelerated static Apache 2.x:: file contents from the file system directly to the network: + ---------------------------------------------------------------- -DocumentRoot /var/www +SetEnv GIT_PROJECT_ROOT /var/www/git -ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/git/ +ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ Alias /git_static/ /var/www/git/ RewriteEngine on
@@ -114,7 +109,7 @@ ENVIRONMENT 'git-http-backend' relies upon the CGI environment variables set by the invoking web server, including: -* PATH_TRANSLATED +* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED) * REMOTE_USER * REMOTE_ADDR * CONTENT_TYPE
http-backend.c +22 -3
@@ -528,6 +528,26 @@ static NORETURN void die_webcgi(const char *err, va_list params)exit (0 ); } +static char *getdir (void ) +{ +struct strbuf buf =STRBUF_INIT ; +char *pathinfo =getenv ("PATH_INFO" ); +char *root =getenv ("GIT_PROJECT_ROOT" ); +char *path =getenv ("PATH_TRANSLATED" ); + +if (root && *root) { +if (!pathinfo || !*pathinfo) +die ("GIT_PROJECT_ROOT is set but PATH_INFO is not" ); +strbuf_addstr (&buf, root); +strbuf_addstr (&buf, pathinfo); +return strbuf_detach (&buf,NULL ); + }else if (path && *path) { +return xstrdup (path); + }else +die ("No GIT_PROJECT_ROOT or PATH_TRANSLATED from server" ); +return NULL ; +} + static struct service_cmd { const char *method; const char *pattern;
@@ -550,7 +570,7 @@ static struct service_cmd {int main (int argc,char **argv) {char *method =getenv ("REQUEST_METHOD" ); -char *dir =getenv ("PATH_TRANSLATED" ); +char *dir;struct service_cmd *cmd =NULL ;char *cmd_arg =NULL ;int i;
@@ -562,8 +582,7 @@ int main(int argc, char **argv)die ("No REQUEST_METHOD from server" );if (!strcmp (method,"HEAD" )) method ="GET" ; -if (!dir) -die ("No PATH_TRANSLATED from server" ); + dir =getdir ();for (i =0 ; i <ARRAY_SIZE (services); i++) {struct service_cmd *c = &services[i];
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 17/28 http-backend: reword some documentation
In reply to Shawn O. PearceFrom: Mark Lodato <[email protected]>
Clarify some of the git-http-backend documentation, particularly:
* In the Description, state that smart/dumb HTTP fetch and smart HTTP push are supported, state that authenticated clients allow push, and remove the note that this is only suited for read-only updates.
* At the start of Examples, state explicitly what URL is mapping to what location on disk.
--- Documentation/git-http-backend.txt | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
Documentation/git-http-backend.txt +8 -4
@@ -14,13 +14,15 @@ DESCRIPTION ----------- A simple CGI program to serve the contents of a Git repository to Git clients accessing the repository over http:// and https:// protocols. +The program supports clients fetching using both the smart HTTP protcol +and the backwards-compatible dumb HTTP protocol, as well as clients +pushing using the smart HTTP protocol. By default, only the `upload-pack` service is enabled, which serves 'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from -'git-fetch', 'git-pull', and 'git-clone'. - -This is ideally suited for read-only updates, i.e., pulling from -git repositories. +'git-fetch', 'git-pull', and 'git-clone'. If the client is authenticated, +the `receive-pack` service is enabled, which serves 'git-send-pack' +clients, which is invoked from 'git-push'. SERVICES --------
@@ -50,6 +52,8 @@ automatically by the web server. EXAMPLES -------- +All of the following examples map 'http://$hostname/git/foo/bar.git' +to '/var/www/git/foo/bar.git'. Apache 2.x:: Ensure mod_cgi, mod_alias, and mod_env are enabled, set
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 18/28 http-backend: use mod_alias instead of mod_rewrite
In reply to Shawn O. PearceFrom: Mark Lodato <[email protected]>
In the git-http-backend documentation, use mod_alias exlusively, instead of using a combination of mod_alias and mod_rewrite. This makes the example slightly shorted and a bit more clear.
--- Documentation/git-http-backend.txt | 10 +++------- 1 files changed, 3 insertions(+), 7 deletions(-)
Documentation/git-http-backend.txt +3 -7
@@ -98,13 +98,9 @@ Accelerated static Apache 2.x:: ---------------------------------------------------------------- SetEnv GIT_PROJECT_ROOT /var/www/git -ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ -Alias /git_static/ /var/www/git/ - -RewriteEngine on -RewriteRule ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /git_static/$1 [PT] -RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.pack)$ /git_static/$1 [PT] -RewriteRule ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.idx)$ /git_static/$1 [PT] +AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1 +AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1 +ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ ----------------------------------------------------------------
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 19/28 http-backend: add example for gitweb on same URL
In reply to Shawn O. PearceFrom: Mark Lodato <[email protected]>
In the git-http-backend documentation, add an example of how to set up gitweb and git-http-backend on the same URL by using a series of mod_alias commands.
--- Documentation/git-http-backend.txt | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-)
Documentation/git-http-backend.txt +33 -0
@@ -88,6 +88,23 @@ directive around the repository, or one of its parent directories: ... </Location> ---------------------------------------------------------------- ++ +To serve gitweb at the same url, use a ScriptAliasMatch to only +those URLs that 'git-http-backend' can handle, and forward the +rest to gitweb: ++ +---------------------------------------------------------------- +ScriptAliasMatch \ + "(?x)^/git/(.*/(HEAD | \ + info/refs | \ + objects/(info/[^/]+ | \ + [0-9a-f]{2}/[0-9a-f]{38} | \ + pack/pack-[0-9a-f]{40}\.(pack|idx)) | \ + git-(upload|receive)-pack))$" \ + /usr/libexec/git-core/git-http-backend/$1 + +ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/ +---------------------------------------------------------------- Accelerated static Apache 2.x:: Similar to the above, but Apache can be used to return static
@@ -102,6 +119,22 @@ AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1 AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ ---------------------------------------------------------------- ++ +This can be combined with the gitweb configuration: ++ +---------------------------------------------------------------- +SetEnv GIT_PROJECT_ROOT /var/www/git + +AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1 +AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1 +ScriptAliasMatch \ + "(?x)^/git/(.*/(HEAD | \ + info/refs | \ + objects/info/[^/]+ | \ + git-(upload|receive)-pack))$" \ + /usr/libexec/git-core/git-http-backend/$1 +ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/ +---------------------------------------------------------------- ENVIRONMENT
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 20/28 http-backend: more explict LocationMatch
In reply to Shawn O. PearceFrom: Mark Lodato <[email protected]>
In the git-http-backend examples, only match git-receive-pack within /git/.
--- Documentation/git-http-backend.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/git-http-backend.txt +1 -1
@@ -69,7 +69,7 @@ To enable anonymous read access but authenticated write access, require authorization with a LocationMatch directive: + ---------------------------------------------------------------- -<LocationMatch ".*/git-receive-pack$"> +<LocationMatch "^/git/.*/git-receive-pack$"> AuthType Basic AuthName "Git Access" Require group committers
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 21/28 Discover refs via smart HTTP server when available
In reply to Shawn O. PearceInstead of loading the cached info/refs, try to use the smart HTTP version when the server supports it. Since the smart variant is actually the pkt-line stream from the start of either upload-pack or receive-pack we need to parse these through get_remote_heads, which requires a background thread to feed its pipe.
--- remote-curl.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 131 insertions(+), 17 deletions(-)
remote-curl.c +131 -17
@@ -5,6 +5,7 @@#include "http.h" #include "exec_cmd.h" #include "run-command.h" +#include "pkt-line.h" static struct remote *remote;static const char *url;
@@ -75,21 +76,46 @@ static int set_option(const char *name, const char *value) } } -static struct ref *get_refs (void ) +struct discovery { +const char *service; +char *buf_alloc; +char *buf; +size_t len; +unsigned proto_git :1 ; +}; +static struct discovery *last_discovery; + +static void free_discovery (struct discovery *d) +{ +if (d) { +if (d == last_discovery) + last_discovery =NULL ; +free (d->buf_alloc); +free (d); + } +} + +static struct discovery *discover_refs (const char *service) {struct strbuf buffer =STRBUF_INIT ; -char *data, *start, *mid; -char *ref_name; +struct discovery *last = last_discovery;char *refs_url; -int i =0 ; -int http_ret; +int http_ret, is_http =0 ; -struct ref *refs =NULL ; -struct ref *ref =NULL ; -struct ref *last_ref =NULL ; +if (last && !strcmp (service, last->service)) +return last; +free_discovery (last); - refs_url =xmalloc (strlen (url) +11 ); -sprintf (refs_url,"%s/info/refs" , url); +strbuf_addf (&buffer,"%s/info/refs" , url); +if (!prefixcmp (url,"http://" ) || !prefixcmp (url,"https://" )) { + is_http =1 ; +if (!strchr (url,'?' )) +strbuf_addch (&buffer,'?' ); +else +strbuf_addch (&buffer,'&' ); +strbuf_addf (&buffer,"service=%s" , service); + } + refs_url =strbuf_detach (&buffer,NULL );init_walker (); http_ret =http_get_strbuf (refs_url, &buffer,HTTP_NO_CACHE );
@@ -104,10 +130,86 @@ static struct ref *get_refs(void)die ("HTTP request failed" ); } - data = buffer.buf; + last=xcalloc (1 ,sizeof (*last_discovery)); + last->service = service; + last->buf_alloc =strbuf_detach (&buffer, &last->len); + last->buf = last->buf_alloc; + +if (is_http &&5 <= last->len && last->buf[4 ] =='#' ) { +/* smart HTTP response; validate that the service +* pkt-line matches our request. +*/ +struct strbuf exp =STRBUF_INIT ; + +if (packet_get_line (&buffer, &last->buf, &last->len) <=0 ) +die ("%s has invalid packet header" , refs_url); +if (buffer.len && buffer.buf[buffer.len -1 ] =='\n' ) +strbuf_setlen (&buffer, buffer.len -1 ); + +strbuf_addf (&exp,"# service=%s" , service); +if (strbuf_cmp (&exp, &buffer)) +die ("invalid server response; got '%s'" , buffer.buf); +strbuf_release (&exp); + +/* The header can include additional metadata lines, up +* until a packet flush marker. Ignore these now, but +* in the future we might start to scan them. +*/ +strbuf_reset (&buffer); +while (packet_get_line (&buffer, &last->buf, &last->len) >0 ) +strbuf_reset (&buffer); + + last->proto_git =1 ; + } + +free (refs_url); +strbuf_release (&buffer); + last_discovery = last; +return last; +} + +static int write_discovery (int fd,void *data) +{ +struct discovery *heads = data; +int err =0 ; +if (write_in_full (fd, heads->buf, heads->len) != heads->len) + err =1 ; +close (fd); +return err; +} + +static struct ref *parse_git_refs (struct discovery *heads) +{ +struct ref *list =NULL ; +struct async async; + +memset (&async,0 ,sizeof (async)); + async.proc = write_discovery; + async.data = heads; + +if (start_async (&async)) +die ("cannot start thread to parse advertised refs" ); +get_remote_heads (async.out, &list,0 ,NULL ,0 ,NULL ); +close (async.out); +if (finish_async (&async)) +die ("ref parsing thread failed" ); +return list; +} + +static struct ref *parse_info_refs (struct discovery *heads) +{ +char *data, *start, *mid; +char *ref_name; +int i =0 ; + +struct ref *refs =NULL ; +struct ref *ref =NULL ; +struct ref *last_ref =NULL ; + + data = heads->buf; start =NULL ; mid = data; -while (i < buffer.len) { +while (i < heads->len) {if (!start) { start = &data[i]; }
@@ -131,8 +233,7 @@ static struct ref *get_refs(void) i++; } -strbuf_release (&buffer); - +init_walker (); ref =alloc_ref ("HEAD" );if (!walker->fetch_ref (walker, ref) && !resolve_remote_symref (ref, refs)) {
@@ -142,11 +243,23 @@ static struct ref *get_refs(void)free (ref); } -strbuf_release (&buffer); -free (refs_url);return refs; } +static struct ref *get_refs (int for_push) +{ +struct discovery *heads; + +if (for_push) + heads =discover_refs ("git-receive-pack" ); +else + heads =discover_refs ("git-upload-pack" ); + +if (heads->proto_git) +return parse_git_refs (heads); +return parse_info_refs (heads); +} +static void output_refs (struct ref *refs) {struct ref *posn;
@@ -317,7 +430,8 @@ int main(int argc, const char **argv)parse_fetch (&buf); }else if (!strcmp (buf.buf,"list" ) || !prefixcmp (buf.buf,"list " )) { -output_refs (get_refs ()); +int for_push = !!strstr (buf.buf +4 ,"for-push" ); +output_refs (get_refs (for_push)); }else if (!prefixcmp (buf.buf,"push " )) {parse_push (&buf);
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 22/28 Smart push over HTTP: client side
In reply to Shawn O. PearceThe git-remote-curl backend detects if the remote server supports the git-receive-pack service, and if so, runs git-send-pack in a pipe to dump the command and pack data as a single POST request.
The advertisements from the server that were obtained during the discovery are passed into git-send-pack before the POST request starts. This permits git-send-pack to operate largely unmodified.
For smaller packs (those under 1 MiB) a HTTP/1.0 POST with a Content-Length is used, permitting interaction with any server. The 1 MiB limit is arbitrary, but is sufficent to fit most deltas created by human authors against text sources with the occasional small binary file (e.g. few KiB icon image). The configuration option http.postBuffer can be used to increase (or shink) this buffer if the default is not sufficient.
For larger packs which cannot be spooled entirely into the helper's memory space (due to http.postBuffer being too small), the POST request requires HTTP/1.1 and sets "Transfer-Encoding: chunked". This permits the client to upload an unknown amount of data in one HTTP transaction without needing to pregenerate the entire pack file locally.
--- Documentation/config.txt | 8 ++ builtin-send-pack.c | 116 +++++++++++++++++++++- http.c | 13 ++- http.h | 2 + remote-curl.c | 235 +++++++++++++++++++++++++++++++++++++++++++++- send-pack.h | 3 +- sideband.c | 11 ++- transport.c | 1 + 8 files changed, 374 insertions(+), 15 deletions(-)
Documentation/config.txt +8 -0
@@ -1089,6 +1089,14 @@ http.maxRequests:: How many HTTP requests to launch in parallel. Can be overridden by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5. +http.postBuffer:: + Maximum size in bytes of the buffer used by smart HTTP + transports when POSTing data to the remote system. + For requests larger than this buffer size, HTTP/1.1 and + Transfer-Encoding: chunked is used to avoid creating a + massive pack file locally. Default is 1 MiB, which is + sufficient for most requests. + http.lowSpeedLimit, http.lowSpeedTime:: If the HTTP transfer speed is less than 'http.lowSpeedLimit' for longer than 'http.lowSpeedTime' seconds, the transfer is aborted.
builtin-send-pack.c +110 -6
207 lines not on this page · raw message
http.c +10 -3
@@ -1,9 +1,11 @@#include "http.h" #include "pack.h" +#include "sideband.h" int data_received;int active_requests;int http_is_verbose; +size_t http_post_buffer =16 *LARGE_PACKET_MAX ;#ifdef USE_CURL_MULTI static int max_requests =-1 ;
@@ -97,8 +99,6 @@ size_t fwrite_null(const void *ptr, size_t eltsize, size_t nmemb, void *strbuf)return eltsize * nmemb; } -static void finish_active_slot (struct active_request_slot *slot); -#ifdef USE_CURL_MULTI static void process_curl_messages (void ) {
@@ -174,6 +174,13 @@ static int http_options(const char *var, const char *value, void *cb)if (!strcmp ("http.proxy" , var))return git_config_string (&curl_http_proxy, var, value); +if (!strcmp ("http.postbuffer" , var)) { + http_post_buffer =git_config_int (var, value); +if (http_post_buffer <LARGE_PACKET_MAX ) + http_post_buffer =LARGE_PACKET_MAX ; +return 0 ; + } +/* Fall back on the default ones */ return git_default_config (var, value, cb); }
@@ -638,7 +645,7 @@ void release_active_slot(struct active_request_slot *slot)#endif } -static void finish_active_slot (struct active_request_slot *slot) +void finish_active_slot (struct active_request_slot *slot) {closedown_active_slot (slot);curl_easy_getinfo (slot->curl,CURLINFO_HTTP_CODE , &slot->http_code);
http.h +2 -0
@@ -79,6 +79,7 @@ extern curlioerr ioctl_buffer(CURL *handle, int cmd, void *clientp);extern struct active_request_slot *get_active_slot (void );extern int start_active_slot (struct active_request_slot *slot);extern void run_active_slot (struct active_request_slot *slot); +extern void finish_active_slot (struct active_request_slot *slot);extern void finish_all_active_slots (void );extern void release_active_slot (struct active_request_slot *slot);
@@ -94,6 +95,7 @@ extern void http_cleanup(void);extern int data_received;extern int active_requests;extern int http_is_verbose; +extern size_t http_post_buffer;extern char curl_errorstr[CURL_ERROR_SIZE ];
remote-curl.c +233 -2
271 lines not on this page · raw message
send-pack.h +2 -1
@@ -8,7 +8,8 @@ struct send_pack_args { force_update:1, use_thin_pack:1, use_ofs_delta:1, - dry_run:1; + dry_run:1, + stateless_rpc:1; }; int send_pack(struct send_pack_args *args,
sideband.c +8 -3
@@ -135,9 +135,14 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet n = sz;if (packet_max -5 < n) n = packet_max -5 ; -sprintf (hdr,"%04x" , n +5 ); - hdr[4 ] = band; -safe_write (fd, hdr,5 ); +if (0 <= band) { +sprintf (hdr,"%04x" , n +5 ); + hdr[4 ] = band; +safe_write (fd, hdr,5 ); + }else { +sprintf (hdr,"%04x" , n +4 ); +safe_write (fd, hdr,4 ); + }safe_write (fd, p, n); p += n; sz -= n;
transport.c +1 -0
@@ -731,6 +731,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re NULL); } +memset (&args,0 ,sizeof (args)); args.send_mirror = !!(flags &TRANSPORT_PUSH_MIRROR ); args.force_update = !!(flags &TRANSPORT_PUSH_FORCE ); args.use_thin_pack = data->thin;
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 23/28 Smart fetch over HTTP: client side
In reply to Shawn O. PearceThe git-remote-curl backend detects if the remote server supports the git-upload-pack service, and if so, runs git-fetch-pack locally in a pipe to generate the want/have commands.
The advertisements from the server that were obtained during the discovery are passed into git-fetch-pack before the POST request starts, permitting server capability discovery and enablement.
Common objects that are discovered are appended onto the request as have lines and are sent again on the next request. This allows the remote side to reinitialize its in-memory list of common objects during the next request.
Because all requests are relatively short, below git-remote-curl's 1 MiB buffer limit, requests will use the standard Content-Length header and be valid HTTP/1.0 POST requests. This makes the fetch client more tolerant of proxy servers which don't support HTTP/1.1 or the chunked transfer encoding.
--- builtin-fetch-pack.c | 110 ++++++++++++++++++++++++++++++++++++++++++-------- fetch-pack.h | 3 +- remote-curl.c | 69 +++++++++++++++++++++++++++++-- 3 files changed, 160 insertions(+), 22 deletions(-)
builtin-fetch-pack.c +93 -17
@@ -165,6 +165,24 @@ enum ack_type { ACK_ready }; +static void consume_shallow_list (int fd) +{ +if (args.stateless_rpc && args.depth >0 ) { +/* If we sent a depth we will get back "duplicate" +* shallow and unshallow commands every time there +* is a block of have lines exchanged. +*/ +char line[1000 ]; +while (packet_read_line (fd, line,sizeof (line))) { +if (!prefixcmp (line,"shallow " )) +continue ; +if (!prefixcmp (line,"unshallow " )) +continue ; +die ("git fetch-pack: expected shallow list" ); + } + } +} +static enum ack_type get_ack (int fd,unsigned char *result_sha1) {static char line[1000 ];
@@ -190,6 +208,15 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)die ("git fetch_pack: expected ACK/NAK, got '%s'" , line); } +static void send_request (int fd,struct strbuf *buf) +{ +if (args.stateless_rpc) { +send_sideband (fd,-1 , buf->buf, buf->len,LARGE_PACKET_MAX ); +packet_flush (fd); + }else +safe_write (fd, buf->buf, buf->len); +} +static int find_common (int fd[2 ],unsigned char *result_sha1,struct ref *refs) {
@@ -199,7 +226,10 @@ static int find_common(int fd[2], unsigned char *result_sha1,unsigned in_vain =0 ;int got_continue =0 ;struct strbuf req_buf =STRBUF_INIT ; +size_t state_len =0 ; +if (args.stateless_rpc && multi_ack ==1 ) +die ("--stateless-rpc requires multi_ack_detailed" );if (marked)for_each_ref (clear_marks,NULL ); marked =1 ;
@@ -256,13 +286,13 @@ static int find_common(int fd[2], unsigned char *result_sha1,if (args.depth >0 )packet_buf_write (&req_buf,"deepen %d" , args.depth);packet_buf_flush (&req_buf); - -safe_write (fd[1 ], req_buf.buf, req_buf.len); + state_len = req_buf.len;if (args.depth >0 ) {char line[1024 ];unsigned char sha1[20 ]; +send_request (fd[1 ], &req_buf);while (packet_read_line (fd[0 ], line,sizeof (line))) {if (!prefixcmp (line,"shallow " )) {if (get_sha1_hex (line +8 , sha1))
@@ -284,28 +314,40 @@ static int find_common(int fd[2], unsigned char *result_sha1, }die ("expected shallow/unshallow, got %s" , line); } + }else if (!args.stateless_rpc) +send_request (fd[1 ], &req_buf); + +if (!args.stateless_rpc) { +/* If we aren't using the stateless-rpc interface +* we don't need to retain the headers. +*/ +strbuf_setlen (&req_buf,0 ); + state_len =0 ; } flushes =0 ; retval =-1 ;while ((sha1 =get_rev ())) { -packet_write (fd[1 ],"have %s\n" ,sha1_to_hex (sha1)); +packet_buf_write (&req_buf,"have %s\n" ,sha1_to_hex (sha1));if (args.verbose)fprintf (stderr,"have %s\n" ,sha1_to_hex (sha1)); in_vain++;if (!(31 & ++count)) {int ack; -packet_flush (fd[1 ]); +packet_buf_flush (&req_buf); +send_request (fd[1 ], &req_buf); +strbuf_setlen (&req_buf, state_len); flushes++;/* * We keep one window "ahead" of the other side, and * will wait for an ACK only on the next one */ -if (count ==32 ) +if (!args.stateless_rpc && count ==32 )continue ; +consume_shallow_list (fd[0 ]); do { ack = get_ack(fd[0], result_sha1); if (args.verbose && ack)
@@ -322,6 +364,17 @@ static int find_common(int fd[2], unsigned char *result_sha1,case ACK_continue: {struct commit *commit =lookup_commit (result_sha1); +if (args.stateless_rpc + && ack == ACK_common + && !(commit->object.flags &COMMON )) { +/* We need to replay the have for this object +* on the next RPC request so the peer knows +* it is in common with us. +*/ +const char *hex =sha1_to_hex (result_sha1); +packet_buf_write (&req_buf,"have %s\n" , hex); + state_len = req_buf.len; + }mark_common (commit,0 ,1 ); retval =0 ; in_vain =0 ;
@@ -339,7 +392,8 @@ static int find_common(int fd[2], unsigned char *result_sha1, } } done: -packet_write (fd[1 ],"done\n" ); +packet_buf_write (&req_buf,"done\n" ); +send_request (fd[1 ], &req_buf);if (args.verbose)fprintf (stderr,"done\n" );if (retval !=0 ) {
@@ -348,6 +402,7 @@ done: }strbuf_release (&req_buf); +consume_shallow_list (fd[0 ]);while (flushes || multi_ack) {int ack =get_ack (fd[0 ], result_sha1);if (ack) {
@@ -672,6 +727,8 @@ static struct ref *do_fetch_pack(int fd[2],*/ warning ("no common commits" ); +if (args.stateless_rpc) +packet_flush (fd[1 ]);if (get_pack (fd, pack_lockfile))die ("git fetch-pack: fetch failed." );
@@ -742,6 +799,8 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)struct ref *ref =NULL ;char *dest =NULL , **heads;int fd[2 ]; +char *pack_lockfile =NULL ; +char **pack_lockfile_ptr =NULL ;struct child_process *conn; nr_heads =0 ;
@@ -791,6 +850,15 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) args.no_progress =1 ;continue ; } +if (!strcmp ("--stateless-rpc" , arg)) { + args.stateless_rpc =1 ; +continue ; + } +if (!strcmp ("--lock-pack" , arg)) { + args.lock_pack =1 ; + pack_lockfile_ptr = &pack_lockfile; +continue ; + }usage (fetch_pack_usage); } dest = (char *)arg;
@@ -801,19 +869,27 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)if (!dest)usage (fetch_pack_usage); - conn =git_connect (fd, (char *)dest, args.uploadpack, - args.verbose ?CONNECT_VERBOSE :0 ); -if (conn) { -get_remote_heads (fd[0 ], &ref,0 ,NULL ,0 ,NULL ); - - ref =fetch_pack (&args, fd, conn, ref, dest, nr_heads, heads,NULL ); -close (fd[0 ]); -close (fd[1 ]); -if (finish_connect (conn)) - ref =NULL ; +if (args.stateless_rpc) { + conn =NULL ; + fd[0 ] =0 ; + fd[1 ] =1 ; }else { - ref =NULL ; + conn =git_connect (fd, (char *)dest, args.uploadpack, + args.verbose ?CONNECT_VERBOSE :0 ); + } + +get_remote_heads (fd[0 ], &ref,0 ,NULL ,0 ,NULL ); + + ref =fetch_pack (&args, fd, conn, ref, dest, + nr_heads, heads, pack_lockfile_ptr); +if (pack_lockfile) { +printf ("lock %s\n" , pack_lockfile); +fflush (stdout); } +close (fd[0 ]); +close (fd[1 ]); +if (finish_connect (conn)) + ref =NULL ; ret = !ref;if (!ret && nr_heads) {
fetch-pack.h +2 -1
@@ -13,7 +13,8 @@ struct fetch_pack_args fetch_all:1, verbose:1, no_progress:1, - include_tag:1; + include_tag:1, + stateless_rpc:1; }; struct ref *fetch_pack(struct fetch_pack_args *args,
remote-curl.c +65 -4
105 lines not on this page · raw message
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 24/28 Smart HTTP fetch: gzip requests
In reply to Shawn O. PearceThe upload-pack requests are mostly plain text and they compress rather well. Deflating them with Content-Encoding: gzip can easily drop the size of the request by 50%, reducing the amount of data to transfer as we negotiate the common commits.
--- remote-curl.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-)
remote-curl.c +50 -0
@@ -289,6 +289,7 @@ struct rpc_state {int in;int out;struct strbuf result; + unsigned gzip_request : 1; }; static size_t rpc_out(void *ptr, size_t eltsize,
@@ -327,6 +328,8 @@ static int post_rpc(struct rpc_state *rpc)struct active_request_slot *slot;struct slot_results results;struct curl_slist *headers =NULL ; +int use_gzip = rpc->gzip_request; +char *gzip_body =NULL ;int err =0 , large_request =0 ;/* Try to load the entire request, if we can fit it into the
@@ -340,6 +343,7 @@ static int post_rpc(struct rpc_state *rpc)if (left <LARGE_PACKET_MAX ) { large_request =1 ; + use_gzip =0 ;break ; }
@@ -355,6 +359,7 @@ static int post_rpc(struct rpc_state *rpc)curl_easy_setopt (slot->curl,CURLOPT_POST ,1 );curl_easy_setopt (slot->curl,CURLOPT_NOBODY ,0 );curl_easy_setopt (slot->curl,CURLOPT_URL , rpc->service_url); +curl_easy_setopt (slot->curl,CURLOPT_ENCODING ,"" ); headers =curl_slist_append (headers, rpc->hdr_content_type); headers =curl_slist_append (headers, rpc->hdr_accept);
@@ -372,6 +377,49 @@ static int post_rpc(struct rpc_state *rpc)fflush (stderr); } + }else if (use_gzip &&1024 < rpc->len) { +/* The client backend isn't giving us compressed data so +* we can try to deflate it ourselves, this may save on. +* the transfer time. +*/ +size_t size; +z_stream stream; +int ret; + +memset (&stream,0 ,sizeof (stream)); + ret =deflateInit2 (&stream,Z_BEST_COMPRESSION , +Z_DEFLATED , (15 +16 ), +8 ,Z_DEFAULT_STRATEGY ); +if (ret !=Z_OK ) +die ("cannot deflate request; zlib init error %d" , ret); + size =deflateBound (&stream, rpc->len); + gzip_body =xmalloc (size); + + stream.next_in = (unsigned char *)rpc->buf; + stream.avail_in = rpc->len; + stream.next_out = (unsigned char *)gzip_body; + stream.avail_out = size; + + ret =deflate (&stream,Z_FINISH ); +if (ret !=Z_STREAM_END ) +die ("cannot deflate request; zlib deflate error %d" , ret); + + ret =deflateEnd (&stream); +if (ret !=Z_OK ) +die ("cannot deflate request; zlib end error %d" , ret); + + size = stream.total_out; + + headers =curl_slist_append (headers,"Content-Encoding: gzip" ); +curl_easy_setopt (slot->curl,CURLOPT_POSTFIELDS , gzip_body); +curl_easy_setopt (slot->curl,CURLOPT_POSTFIELDSIZE , size); + +if (options.verbosity >1 ) { +fprintf (stderr,"POST %s (gzip %lu to %lu bytes)\n" , + rpc->service_name, + (unsigned long )rpc->len, (unsigned long )size); +fflush (stderr); + } }else {/* We know the complete request size in advance, use the * more normal Content-Length approach.
@@ -398,6 +446,7 @@ static int post_rpc(struct rpc_state *rpc) }curl_slist_free_all (headers); +free (gzip_body);return err; }
@@ -523,6 +572,7 @@ static int fetch_git(struct discovery *heads,memset (&rpc,0 ,sizeof (rpc)); rpc.service_name ="git-upload-pack" , rpc.argv = argv; + rpc.gzip_request =1 ; err =rpc_service (&rpc, heads);if (rpc.result.len)
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 25/28 t5540-http-push: remove redundant fetches
In reply to Shawn O. PearceFrom: Tay Ray Chuan <[email protected]>
--- t/t5540-http-push.sh | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
t/t5540-http-push.sh +0 -2
@@ -116,9 +116,7 @@ test_expect_success 'create and delete remote branch' ' test_tick && git commit -m dev && git push origin dev && - git fetch && git push origin :dev && - git fetch && test_must_fail git show-ref --verify refs/remotes/origin/dev '
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 26/28 set httpd port before sourcing lib-httpd
In reply to Shawn O. PearceFrom: Clemens Buchacher <[email protected]>
If LIB_HTTPD_PORT is not set already, lib-httpd will set it to the default 8111.
--- t/t5540-http-push.sh | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
t/t5540-http-push.sh +3 -4
@@ -9,17 +9,16 @@ This test runs various sanity checks on http-push.' . ./test-lib.sh -ROOT_PATH="$PWD" -LIB_HTTPD_DAV=t -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'} - if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] then say "skipping test, USE_CURL_MULTI is not defined" test_done fi +LIB_HTTPD_DAV=t +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'} . "$TEST_DIRECTORY"/lib-httpd.sh +ROOT_PATH="$PWD" start_httpd test_expect_success 'setup remote repository' '
Signature · 1 line
1.6.5.2.181.gd6f41
PATCH v5 27/28 http tests: use /dumb/ URL prefix
In reply to Shawn O. PearceTo clarify what part of the HTTP transprot is being tested we change the URLs used by existing tests to include /dumb/ at the start, indicating they use the non-Git aware code paths.
--- t/lib-httpd/apache.conf | 7 ++++++- t/t5540-http-push.sh | 10 +++++----- t/t5550-http-fetch.sh | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-)
t/lib-httpd/apache.conf +6 -1
@@ -8,6 +8,11 @@ ErrorLog error.log <IfModule !mod_log_config.c> LoadModule log_config_module modules/mod_log_config.so </IfModule> +<IfModule !mod_alias.c> + LoadModule alias_module modules/mod_alias.so +</IfModule> + +Alias /dumb/ www/ <IfDefine SSL> LoadModule ssl_module modules/mod_ssl.so
@@ -26,7 +31,7 @@ SSLEngine On LoadModule dav_fs_module modules/mod_dav_fs.so DAVLockDB DAVLock - <Location /> + <Location /dumb/> Dav on </Location> </IfDefine>
t/t5540-http-push.sh +5 -5
@@ -42,7 +42,7 @@ test_expect_success 'setup remote repository' ' test_expect_success 'clone remote repository' ' cd "$ROOT_PATH" && - git clone $HTTPD_URL/test_repo.git test_repo_clone + git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone ' test_expect_success 'push to remote repository with packed refs' '
@@ -75,7 +75,7 @@ test_expect_success 'http-push fetches unpacked objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && - git clone $HTTPD_URL/test_repo_unpacked.git \ + git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ "$ROOT_PATH"/fetch_unpacked && # By reset, we force git to retrieve the object
@@ -84,14 +84,14 @@ test_expect_success 'http-push fetches unpacked objects' ' git remote rm origin && git reflog expire --expire=0 --all && git prune && - git push -f -v $HTTPD_URL/test_repo_unpacked.git master) + git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master) ' test_expect_success 'http-push fetches packed objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && - git clone $HTTPD_URL/test_repo_packed.git \ + git clone $HTTPD_URL/dumb/test_repo_packed.git \ "$ROOT_PATH"/test_repo_clone_packed && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
@@ -104,7 +104,7 @@ test_expect_success 'http-push fetches packed objects' ' git remote rm origin && git reflog expire --expire=0 --all && git prune && - git push -f -v $HTTPD_URL/test_repo_packed.git master) + git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master) ' test_expect_success 'create and delete remote branch' '
t/t5550-http-fetch.sh +2 -2
@@ -30,7 +30,7 @@ test_expect_success 'create http-accessible bare repository' ' ' test_expect_success 'clone http repository' ' - git clone $HTTPD_URL/repo.git clone && + git clone $HTTPD_URL/dumb/repo.git clone && test_cmp file clone/file '
@@ -58,7 +58,7 @@ test_expect_success 'fetch packed objects' ' cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && git --bare repack && git --bare prune-packed && - git clone $HTTPD_URL/repo_pack.git + git clone $HTTPD_URL/dumb/repo_pack.git ' stop_httpd
Signature · 1 line
1.6.5.2.181.gd6f41
Re: [PATCH v5 27/28] http tests: use /dumb/ URL prefix
Hi,
Quoted 6 lines · Shawn O. Pearce
To clarify what part of the HTTP transprot is being tested we change the URLs used by existing tests to include /dumb/ at the start, indicating they use the non-Git aware code paths.
Signed-off-by Shawn O. Pearce <[email protected]>CC Tay Ray Chuan <[email protected]>
thanks.
Signature · 2 lines
Cheers, Ray Chuan
PATCH v5 28/28 test smart http fetch and push
In reply to Shawn O. PearceThe top level directory "/smart/" of the test Apache server is mapped through our git-http-backend CGI, but uses the same underlying repository space as the server's document root. This is the most simple installation possible.
Server logs are checked to verify the client has accessed only the smart URLs during the test. During fetch testing the headers are also logged from libcurl to ensure we are making a reasonably sane HTTP request, and getting back reasonably sane response headers from the CGI.
When validating the request headers used during smart fetch we munge away the actual Content-Length and replace it with the placeholder "xxx". This avoids unnecessary varability in the test caused by an unrelated change in the requested capabilities in the first want line of the request. However, we still want to look for and verify that Content-Length was used, because smaller payloads should be using Content-Length and not "Transfer-Encoding: chunked".
When validating the server response headers we must discard both Content-Length and Transfer-Encoding, as Apache2 can use either format to return our response.
During development of this test I observed Apache returning both forms, depending on when the processes got CPU time. If our CGI returned the pack data quickly, Apache just buffered the whole thing and returned a Content-Length. If our CGI took just a bit too long to complete, Apache flushed its buffer and instead used "Transfer-Encoding: chunked".
--- t/lib-httpd/apache.conf | 17 ++++++++ t/t5540-http-push.sh | 2 +- t/t5541-http-push.sh | 92 ++++++++++++++++++++++++++++++++++++++++++ t/t5550-http-fetch.sh | 8 +++- t/t5551-http-fetch.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 219 insertions(+), 2 deletions(-) create mode 100755 t/t5541-http-push.sh create mode 100755 t/t5551-http-fetch.sh
t/lib-httpd/apache.conf +17 -0
@@ -11,9 +11,26 @@ ErrorLog error.log <IfModule !mod_alias.c> LoadModule alias_module modules/mod_alias.so </IfModule> +<IfModule !mod_cgi.c> + LoadModule cgi_module modules/mod_cgi.so +</IfModule> +<IfModule !mod_env.c> + LoadModule env_module modules/mod_env.so +</IfModule> Alias /dumb/ www/ +<Location /smart/> + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} +</Location> +ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/ +<Directory ${GIT_EXEC_PATH}> + Options None +</Directory> +<Files ${GIT_EXEC_PATH}/git-http-backend> + Options ExecCGI +</Files> + <IfDefine SSL> LoadModule ssl_module modules/mod_ssl.so
t/t5540-http-push.sh +1 -1
@@ -3,7 +3,7 @@ # Copyright (c) 2008 Clemens Buchacher <[email protected]> # -test_description='test http-push +test_description='test WebDAV http-push This test runs various sanity checks on http-push.'
t/t5541-http-push.sh new file +92 -0
92 lines not on this page · raw message
t/t5550-http-fetch.sh +7 -1
@@ -1,6 +1,6 @@ #!/bin/sh -test_description='test fetching over http' +test_description='test dumb fetching over http via static file' . ./test-lib.sh if test -n "$NO_CURL"; then
@@ -61,5 +61,11 @@ test_expect_success 'fetch packed objects' ' git clone $HTTPD_URL/dumb/repo_pack.git ' +test_expect_success 'did not use upload-pack service' ' + grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act + : >exp + test_cmp exp act +' + stop_httpd test_done
t/t5551-http-fetch.sh new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.6.5.2.181.gd6f41