gpt4 book ai didi

git - 'git ls-remote'命令参数限制返回的行数

转载 作者:太空狗 更新时间:2023-10-29 13:33:12 25 4
gpt4 key购买 nike

我们可以使用 git ls-remote 命令来获取给定 git 仓库的提交列表,例如this discussion

对于具有大量提交/标签的 repo ,此命令花费了我们相当长的时间 - 我们正在为其寻找参数和/或任何其他限制返回行数的命令,例如只读取返回列表中的前 3 行。

我们怎样才能做到这一点?

附:

我的 google searchour site search帮助不大。

最佳答案

git ls-remote 工作于 fetching the full list of refs from the remote and then filtering it locally :

int cmd_ls_remote(int argc, const char **argv, const char *prefix)
{
...

transport = transport_get(remote, NULL);
if (uploadpack != NULL)
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);

/* Get all refs from the remote */
ref = transport_get_remote_refs(transport);
if (transport_disconnect(transport))
return 1;

if (!dest && !quiet)
fprintf(stderr, "From %s\n", *remote->url);

/* Filter the list of all refs */
for ( ; ref; ref = ref->next) {
if (!check_ref_type(ref, flags))
continue;
if (!tail_match(pattern, ref->name))
continue;
if (show_symref_target && ref->symref)
printf("ref: %s\t%s\n", ref->symref, ref->name);
printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
status = 0; /* we found something */
}
return status;
}

更新

根据 this page, explaining git transfer protocols ,如果远程支持dumb协议(protocol),那么你可以直接获取远程refs/heads/branchname文件(例如使用curl)。

The Dumb Protocol

If you’re setting up a repository to be served read-only over HTTP, the dumb protocol is likely what will be used. 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.

...

否则,当使用智能协议(protocol)时,从远程发送的第一条数据总是所有远程引用的列表,即任何通过智能协议(protocol)连接到远程的 git 命令就像 git ls -remote 在内部运行(从技术上讲,所有此类命令都调用 transport_get_remote_refs() 函数)。不幸的是,在这种情况下,没有办法加快您的查询速度,甚至没有解决方法。

The Smart Protocol

...

Uploading Data

To upload data to a remote process, Git uses the send-pack and receive-pack processes. The send-pack process runs on the client and connects to a receive-pack process on the remote side.

...

The git-receive-pack command immediately responds with one line for each reference it currently has.

...

Downloading Data

When you download data, the fetch-pack and upload-pack processes are involved. 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: ... This is very similar to what receive-pack responds with, but the capabilities are different (i.e. the list of all refs + some additional data).

...

关于git - 'git ls-remote'命令参数限制返回的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45253392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com