git-receive-pack / git-upload-pack和git-http-backend之间的区别

时间:2020-05-28 13:22:41

标签: git git-http-backend

要了解有关git的更多信息,我尝试使用Python和Flask编写一个非常简单的Git服务器。我注册了一个端点并将呼叫重定向到git-http-backend。到目前为止,简单的拉动就可以了。也可以进行简单/小的推动。

现在我偶然发现了git-upload-packgit-receive-pack,我想知道为什么或何时需要它们? git-http-backend在后​​台使用它们吗?我不确定是否还要额外支持这些命令。

P.S。我试着把头放在SmartHTTP上。这是否意味着全双工?还是SmartHTTP vs Dumb是什么意思?我不完全了解如果它也只是接收和发送/推送文件,那该怎么办?

1 个答案:

答案 0 :(得分:3)

我在smart http protocol中展示了2011 with Git 1.6.6

但是git-receive-packgit-upload-pack甚至在没有HTTP的情况下也会涉及,例如SSH URL。

我必须了解它们,因为我经常在非root用户的服务器上安装Git。
这意味着可执行文件git不在/usr/bin中,而在/my/path/to/git/usr/bin

每当我从该服务器(或git clone)在PC上执行git ls-remote时,我都会得到:

bash: git-upload-pack: command not found

如果我尝试从PC到服务器的git push

bash: git-receive-pack: command not found

这是因为,当您查看Git安装的usr/bin文件夹时,会看到:

-rwxr-xr-x. 1 <auser> <agroup> 3.0M Dec 13  2019 git*
drwxr-xr-x. 5 <auser> <agroup>   45 Jun  8 14:35 ../
drwxr-xr-x. 2 <auser> <agroup>  107 Jun  8 14:35 ./
lrwxrwxrwx. 1 <auser> <agroup>    3 Jun  8 14:35 git-receive-pack -> git*
lrwxrwxrwx. 1 <auser> <agroup>    3 Jun  8 14:35 git-upload-pack -> git*
lrwxrwxrwx. 1 <auser> <agroup>    3 Jun  8 14:35 git-upload-archive -> git*

含义git-receive-packgit-upload-pack只是与git本身的符号链接(!)

但是,由于它们的命名约定(git-xxx),他们实际上是使用命令gitreceive-pack来调用upload-pack
(顺便说一句,它适用于您的git-xxx中的任何脚本$PATH:然后您可以输入git xxx,它将调用您的git-xxx脚本)

为使自定义Git安装正常工作,我必须实现git-xxx包装器:

示例:

/my/path/to/git/git-receive-pack:

#!/bin/bash

source "setenv"
"/my/path/to/git/usr/bin/git" receive-pack "$@"

使用setenv设置正确的PATH:

export PERLLIB=/my/path/to/git/usr/share/perl5/vendor_perl:/my/path/to/git/opt/endpoint/perl-5.22.0/share/perl5/vendor_perl
export PATH=/my/path/to/git/usr/bin:/my/path/to/git/usr/libexec/git-core:$PATH
export LD_LIBRARY_PATH=/project/${USER}/refer/pcres/current/usr/lib64

在客户端(PC)端,我需要使用带有自定义Git安装的服务器进行远程添加:

git config --global remote.origin.uploadpack /my/path/to/git/git-upload-pack
git config --global remote.origin.receivepack=/my/path/to/git/git-receive-pack