You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're setting up a repository to be served read-only over HTTP, the dumb protocol is likely what will be used.
9
-
This protocol is called ``dumb'' because it requires no Git-specific code on the server side during the transport process; the fetch process is a series of HTTP `GET` requests, where the client can assume the layout of the Git repository on the server.
Let's follow the `http-fetch` process for the simplegit library:
18
+
让我们通过 simplegit 版本库来看看 `http-fetch` 的过程:
19
19
20
20
[source,console]
21
21
----
22
22
$ git clone http://server/simplegit-progit.git
23
23
----
24
24
25
-
The first thing this command does is pull down the `info/refs` file.
26
-
This file is written by the `update-server-info` command, which is why you need to enable that as a `post-receive` hook in order for the HTTP transport to work properly:
Next, you have two more objects to retrieve – `cfda3b`, which is the tree of content that the commit we just retrieved points to; and `085bb3`, which is the parent commit:
If this comes back with a list of alternate URLs, Git checks for loose files and packfiles there – this is a nice mechanism for projects that are forks of one another to share objects on disk.
95
-
However, because no alternates are listed in this case, your object must be in a packfile.
96
-
To see what packfiles are available on this server, you need to get the `objects/info/packs` file, which contains a listing of them (also generated by `update-server-info`):
P pack-816a9b2334da9953e530f27bcac22082a9f5b835.pack
102
102
----
103
103
104
-
There is only one packfile on the server, so your object is obviously in there, but you'll check the index file to make sure.
105
-
This is also useful if you have multiple packfiles on the server, so you can see which packfile contains the object you need:
104
+
服务端只有一个包文件,所以你要的对象显然就在里面。但是你要先检查它的索引文件以确认。
105
+
即使服务端有多个包文件,这也是很有用的,因为这样你就可以知道你所需要的对象是在哪一个包文件里面:
106
106
107
107
[source]
108
108
----
109
109
=> GET objects/pack/pack-816a9b2334da9953e530f27bcac22082a9f5b835.idx
110
110
(4k of binary data)
111
111
----
112
112
113
-
Now that you have the packfile index, you can see if your object is in it – because the index lists the SHAs of the objects contained in the packfile and the offsets to those objects.
114
-
Your object is there, so go ahead and get the whole packfile:
=> GET objects/pack/pack-816a9b2334da9953e530f27bcac22082a9f5b835.pack
119
119
(13k of binary data)
120
120
----
121
121
122
-
You have your tree object, so you continue walking your commits.
123
-
They're all also within the packfile you just downloaded, so you don't have to do any more requests to your server.
124
-
Git checks out a working copy of the `master` branch that was pointed to by the HEAD reference you downloaded at the beginning.
122
+
现在你也有了你的树对象,你可以继续在提交记录上漫游。
123
+
它们全部都在这个你刚下载的包文件里面,所以你不用继续向服务端请求更多下载了。
124
+
Git 会将开始时下载的 HEAD 引用所指向的 `master` 分支检出到工作目录。
125
125
126
-
==== The Smart Protocol
126
+
==== 智能协议
127
127
128
-
The dumb protocol is simple but a bit inefficient, and it can't handle writing of data from the client to the server.
129
-
The smart protocol is a more common method of transferring data, but it requires a process on the remote end that is intelligent about Git – it can read local data, figure out what the client has and needs, and generate a custom packfile for it.
130
-
There are two sets of processes for transferring data: a pair for uploading data and a pair for downloading data.
The `git-receive-pack` command immediately responds with one line for each reference it currently has – in this case, just the `master` branch and its SHA.
155
-
The first line also has a list of the server's capabilities (here, `report-status`, `delete-refs`, and some others, including the client identifier).
When you download data, the `fetch-pack` and `upload-pack` processes are involved.
218
-
The client initiates a `fetch-pack` process that connects to an `upload-pack` process on the remote side to negotiate what data will be transferred down.
After `fetch-pack` connects, `upload-pack` sends back something like this:
229
+
在 `fetch-pack` 连接后,`upload-pack` 会返回类似下面的内容:
230
230
231
231
[source]
232
232
----
@@ -238,12 +238,12 @@ After `fetch-pack` connects, `upload-pack` sends back something like this:
238
238
0000
239
239
----
240
240
241
-
This is very similar to what `receive-pack` responds with, but the capabilities are different.
242
-
In addition, it sends back what HEAD points to (`symref=HEAD:refs/heads/master`) so the client knows what to check out if this is a clone.
241
+
这与 `receive-pack` 的响应很相似,但是这里所包含的能力是不同的。
242
+
而且它还包含 HEAD 引用所指向内容(`symref=HEAD:refs/heads/master`),这样如果客户端执行的是克隆,它就会知道要检出什么。
243
243
244
-
At this point, the `fetch-pack` process looks at what objects it has and responds with the objects that it needs by sending ``want'' and then the SHA it wants.
245
-
It sends all the objects it already has with ``have'' and then the SHA.
246
-
At the end of this list, it writes ``done'' to initiate the `upload-pack` process to begin sending the packfile of the data it needs:
@@ -280,11 +280,11 @@ This is very similar to invoking `git-upload-pack` over an SSH connection, but t
280
280
0000
281
281
----
282
282
283
-
Again, this is the same format as above.
284
-
The response to this request indicates success or failure, and includes the packfile.
283
+
这个输出格式还是和前面一样的。
284
+
这个请求的响应包含了所需要的包文件,并指明成功或失败。
285
285
286
-
==== Protocols Summary
286
+
==== 协议总结
287
287
288
-
This section contains a very basic overview of the transfer protocols.
289
-
The protocol includes many other features, such as `multi_ack` or `side-band` capabilities, but covering them is outside the scope of this book.
290
-
We've tried to give you a sense of the general back-and-forth between client and server; if you need more knowledge than this, you'll probably want to take a look at the Git source code.
0 commit comments