Skip to content

Commit 905bf77

Browse files
committed
Merge branch 'sp/smart-http'
* sp/smart-http: (37 commits) http-backend: Let gcc check the format of more printf-type functions. http-backend: Fix access beyond end of string. http-backend: Fix bad treatment of uintmax_t in Content-Length t5551-http-fetch: Work around broken Accept header in libcurl t5551-http-fetch: Work around some libcurl versions http-backend: Protect GIT_PROJECT_ROOT from /../ requests Git-aware CGI to provide dumb HTTP transport http-backend: Test configuration options http-backend: Use http.getanyfile to disable dumb HTTP serving test smart http fetch and push http tests: use /dumb/ URL prefix set httpd port before sourcing lib-httpd t5540-http-push: remove redundant fetches Smart HTTP fetch: gzip requests Smart fetch over HTTP: client side Smart push over HTTP: client side Discover refs via smart HTTP server when available http-backend: more explict LocationMatch http-backend: add example for gitweb on same URL http-backend: use mod_alias instead of mod_rewrite ... Conflicts: .gitignore remote-curl.c
2 parents 7dacc6c + 3548701 commit 905bf77

35 files changed

+2937
-283
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
/git-grep
5656
/git-hash-object
5757
/git-help
58+
/git-http-backend
5859
/git-http-fetch
5960
/git-http-push
6061
/git-imap-send

Documentation/config.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,14 @@ http.maxRequests::
10911091
How many HTTP requests to launch in parallel. Can be overridden
10921092
by the 'GIT_HTTP_MAX_REQUESTS' environment variable. Default is 5.
10931093

1094+
http.postBuffer::
1095+
Maximum size in bytes of the buffer used by smart HTTP
1096+
transports when POSTing data to the remote system.
1097+
For requests larger than this buffer size, HTTP/1.1 and
1098+
Transfer-Encoding: chunked is used to avoid creating a
1099+
massive pack file locally. Default is 1 MiB, which is
1100+
sufficient for most requests.
1101+
10941102
http.lowSpeedLimit, http.lowSpeedTime::
10951103
If the HTTP transfer speed is less than 'http.lowSpeedLimit'
10961104
for longer than 'http.lowSpeedTime' seconds, the transfer is aborted.

Documentation/git-http-backend.txt

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
git-http-backend(1)
2+
===================
3+
4+
NAME
5+
----
6+
git-http-backend - Server side implementation of Git over HTTP
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
'git-http-backend'
12+
13+
DESCRIPTION
14+
-----------
15+
A simple CGI program to serve the contents of a Git repository to Git
16+
clients accessing the repository over http:// and https:// protocols.
17+
The program supports clients fetching using both the smart HTTP protcol
18+
and the backwards-compatible dumb HTTP protocol, as well as clients
19+
pushing using the smart HTTP protocol.
20+
21+
By default, only the `upload-pack` service is enabled, which serves
22+
'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
23+
'git-fetch', 'git-pull', and 'git-clone'. If the client is authenticated,
24+
the `receive-pack` service is enabled, which serves 'git-send-pack'
25+
clients, which is invoked from 'git-push'.
26+
27+
SERVICES
28+
--------
29+
These services can be enabled/disabled using the per-repository
30+
configuration file:
31+
32+
http.getanyfile::
33+
This serves older Git clients which are unable to use the
34+
upload pack service. When enabled, clients are able to read
35+
any file within the repository, including objects that are
36+
no longer reachable from a branch but are still present.
37+
It is enabled by default, but a repository can disable it
38+
by setting this configuration item to `false`.
39+
40+
http.uploadpack::
41+
This serves 'git-fetch-pack' and 'git-ls-remote' clients.
42+
It is enabled by default, but a repository can disable it
43+
by setting this configuration item to `false`.
44+
45+
http.receivepack::
46+
This serves 'git-send-pack' clients, allowing push. It is
47+
disabled by default for anonymous users, and enabled by
48+
default for users authenticated by the web server. It can be
49+
disabled by setting this item to `false`, or enabled for all
50+
users, including anonymous users, by setting it to `true`.
51+
52+
URL TRANSLATION
53+
---------------
54+
To determine the location of the repository on disk, 'git-http-backend'
55+
concatenates the environment variables PATH_INFO, which is set
56+
automatically by the web server, and GIT_PROJECT_ROOT, which must be set
57+
manually in the web server configuration. If GIT_PROJECT_ROOT is not
58+
set, 'git-http-backend' reads PATH_TRANSLATED, which is also set
59+
automatically by the web server.
60+
61+
EXAMPLES
62+
--------
63+
All of the following examples map 'http://$hostname/git/foo/bar.git'
64+
to '/var/www/git/foo/bar.git'.
65+
66+
Apache 2.x::
67+
Ensure mod_cgi, mod_alias, and mod_env are enabled, set
68+
GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and
69+
create a ScriptAlias to the CGI:
70+
+
71+
----------------------------------------------------------------
72+
SetEnv GIT_PROJECT_ROOT /var/www/git
73+
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
74+
----------------------------------------------------------------
75+
+
76+
To enable anonymous read access but authenticated write access,
77+
require authorization with a LocationMatch directive:
78+
+
79+
----------------------------------------------------------------
80+
<LocationMatch "^/git/.*/git-receive-pack$">
81+
AuthType Basic
82+
AuthName "Git Access"
83+
Require group committers
84+
...
85+
</LocationMatch>
86+
----------------------------------------------------------------
87+
+
88+
To require authentication for both reads and writes, use a Location
89+
directive around the repository, or one of its parent directories:
90+
+
91+
----------------------------------------------------------------
92+
<Location /git/private>
93+
AuthType Basic
94+
AuthName "Private Git Access"
95+
Require group committers
96+
...
97+
</Location>
98+
----------------------------------------------------------------
99+
+
100+
To serve gitweb at the same url, use a ScriptAliasMatch to only
101+
those URLs that 'git-http-backend' can handle, and forward the
102+
rest to gitweb:
103+
+
104+
----------------------------------------------------------------
105+
ScriptAliasMatch \
106+
"(?x)^/git/(.*/(HEAD | \
107+
info/refs | \
108+
objects/(info/[^/]+ | \
109+
[0-9a-f]{2}/[0-9a-f]{38} | \
110+
pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
111+
git-(upload|receive)-pack))$" \
112+
/usr/libexec/git-core/git-http-backend/$1
113+
114+
ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
115+
----------------------------------------------------------------
116+
117+
Accelerated static Apache 2.x::
118+
Similar to the above, but Apache can be used to return static
119+
files that are stored on disk. On many systems this may
120+
be more efficient as Apache can ask the kernel to copy the
121+
file contents from the file system directly to the network:
122+
+
123+
----------------------------------------------------------------
124+
SetEnv GIT_PROJECT_ROOT /var/www/git
125+
126+
AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
127+
AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
128+
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
129+
----------------------------------------------------------------
130+
+
131+
This can be combined with the gitweb configuration:
132+
+
133+
----------------------------------------------------------------
134+
SetEnv GIT_PROJECT_ROOT /var/www/git
135+
136+
AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
137+
AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
138+
ScriptAliasMatch \
139+
"(?x)^/git/(.*/(HEAD | \
140+
info/refs | \
141+
objects/info/[^/]+ | \
142+
git-(upload|receive)-pack))$" \
143+
/usr/libexec/git-core/git-http-backend/$1
144+
ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
145+
----------------------------------------------------------------
146+
147+
148+
ENVIRONMENT
149+
-----------
150+
'git-http-backend' relies upon the CGI environment variables set
151+
by the invoking web server, including:
152+
153+
* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
154+
* REMOTE_USER
155+
* REMOTE_ADDR
156+
* CONTENT_TYPE
157+
* QUERY_STRING
158+
* REQUEST_METHOD
159+
160+
The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
161+
GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
162+
ensuring that any reflogs created by 'git-receive-pack' contain some
163+
identifying information of the remote user who performed the push.
164+
165+
All CGI environment variables are available to each of the hooks
166+
invoked by the 'git-receive-pack'.
167+
168+
Author
169+
------
170+
Written by Shawn O. Pearce <[email protected]>.
171+
172+
Documentation
173+
--------------
174+
Documentation by Shawn O. Pearce <[email protected]>.
175+
176+
GIT
177+
---
178+
Part of the linkgit:git[1] suite

Documentation/git-remote-helpers.txt

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,51 @@ Commands are given by the caller on the helper's standard input, one per line.
3434
value of the ref. A space-separated list of attributes follows
3535
the name; unrecognized attributes are ignored. After the
3636
complete list, outputs a blank line.
37+
+
38+
If 'push' is supported this may be called as 'list for-push'
39+
to obtain the current refs prior to sending one or more 'push'
40+
commands to the helper.
41+
42+
'option' <name> <value>::
43+
Set the transport helper option <name> to <value>. Outputs a
44+
single line containing one of 'ok' (option successfully set),
45+
'unsupported' (option not recognized) or 'error <msg>'
46+
(option <name> is supported but <value> is not correct
47+
for it). Options should be set before other commands,
48+
and may how those commands behave.
49+
+
50+
Supported if the helper has the "option" capability.
3751

3852
'fetch' <sha1> <name>::
39-
Fetches the given object, writing the necessary objects to the
40-
database. Outputs a blank line when the fetch is
41-
complete. Only objects which were reported in the ref list
42-
with a sha1 may be fetched this way.
53+
Fetches the given object, writing the necessary objects
54+
to the database. Fetch commands are sent in a batch, one
55+
per line, and the batch is terminated with a blank line.
56+
Outputs a single blank line when all fetch commands in the
57+
same batch are complete. Only objects which were reported
58+
in the ref list with a sha1 may be fetched this way.
59+
+
60+
Optionally may output a 'lock <file>' line indicating a file under
61+
GIT_DIR/objects/pack which is keeping a pack until refs can be
62+
suitably updated.
4363
+
4464
Supported if the helper has the "fetch" capability.
4565

66+
'push' +<src>:<dst>::
67+
Pushes the given <src> commit or branch locally to the
68+
remote branch described by <dst>. A batch sequence of
69+
one or more push commands is terminated with a blank line.
70+
+
71+
Zero or more protocol options may be entered after the last 'push'
72+
command, before the batch's terminating blank line.
73+
+
74+
When the push is complete, outputs one or more 'ok <dst>' or
75+
'error <dst> <why>?' lines to indicate success or failure of
76+
each pushed ref. The status report output is terminated by
77+
a blank line. The option field <why> may be quoted in a C
78+
style string if it contains an LF.
79+
+
80+
Supported if the helper has the "push" capability.
81+
4682
If a fatal error occurs, the program writes the error message to
4783
stderr and exits. The caller should expect that a suitable error
4884
message has been printed if the child closes the connection without
@@ -57,10 +93,49 @@ CAPABILITIES
5793
'fetch'::
5894
This helper supports the 'fetch' command.
5995

96+
'option'::
97+
This helper supports the option command.
98+
99+
'push'::
100+
This helper supports the 'push' command.
101+
60102
REF LIST ATTRIBUTES
61103
-------------------
62104

63-
None are defined yet, but the caller must accept any which are supplied.
105+
'for-push'::
106+
The caller wants to use the ref list to prepare push
107+
commands. A helper might chose to acquire the ref list by
108+
opening a different type of connection to the destination.
109+
110+
OPTIONS
111+
-------
112+
'option verbosity' <N>::
113+
Change the level of messages displayed by the helper.
114+
When N is 0 the end-user has asked the process to be
115+
quiet, and the helper should produce only error output.
116+
N of 1 is the default level of verbosity, higher values
117+
of N correspond to the number of -v flags passed on the
118+
command line.
119+
120+
'option progress' \{'true'|'false'\}::
121+
Enable (or disable) progress messages displayed by the
122+
transport helper during a command.
123+
124+
'option depth' <depth>::
125+
Deepen the history of a shallow repository.
126+
127+
'option followtags' \{'true'|'false'\}::
128+
If enabled the helper should automatically fetch annotated
129+
tag objects if the object the tag points at was transferred
130+
during the fetch command. If the tag is not fetched by
131+
the helper a second fetch command will usually be sent to
132+
ask for the tag specifically. Some helpers may be able to
133+
use this option to avoid a second network connection.
134+
135+
'option dry-run' \{'true'|'false'\}:
136+
If true, pretend the operation completed successfully,
137+
but don't actually change any repository data. For most
138+
helpers this only applies to the 'push', if supported.
64139

65140
Documentation
66141
-------------

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ PROGRAMS += git-show-index$X
388388
PROGRAMS += git-unpack-file$X
389389
PROGRAMS += git-upload-pack$X
390390
PROGRAMS += git-var$X
391+
PROGRAMS += git-http-backend$X
391392

392393
# List built-in command $C whose implementation cmd_$C() is not in
393394
# builtin-$C.o but is linked in as part of some other command.

0 commit comments

Comments
 (0)