Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

git communication over http

I want to have git commands (.i.e git clone, git push, ...) in http request format. without using git library. I dont want to use (for example) gitlab api for this type of requests. Request should be something like this (from this link):

GET http://root@localhost/root/app.git/info/refs?service=git-upload-pack

This will retuen something like this (branches)

001e# service=git-upload-pack

000000fafac36d407e123c2499149fcc8c1fc8ebe5ecd301 HEADmulti_ack thin-pack side-band side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag multi_ack_detailed no-done symref=HEAD:refs/heads/master agent=git/2.11.1
003ffac36d407e123c2499149fcc8c1fc8ebe5ecd301 refs/heads/master
0000

I couldnt find an appropriate doc or example for this job. It seems that a git request consist of multiple send/receive operation.

In summary I want to know how should I implement git operations in http request format.

Tnx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In general, you're going to want to use a Git library for this unless you're planning to write your own. Here's why:

Git supports two types of HTTP remotes: the DAV-based (dumb) protocol and the smart protocol. In addition, the smart protocol also supports protocols 0 and 1 (which are nearly identical) and protocol 2, which is quite different. So to implement this in a meaningful way, you're going to have to implement a lot of functionality.

In addition, the smart protocol performs negotiation of what data is present on both sides and sends only the data that differs. In such a case, you necessarily have to walk the history of the repository to determine what objects are common, which means you will also need to read loose and packed objects, read and write references, and fill out the missing objects in thin packs. All of these require basic Git primitives.

If you still want to do it nevertheless, you should look in the Documentation/technical directory in the Git source code at the http-protocol.txt and pack-protocol.txt files, plus the files starting with protocol-.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...