gpt4 book ai didi

git - 高效检索包含提交的版本

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

在命令行中,如果我输入

git tag --contains {commit}

要获取包含给定提交的版本列表,每次提交大约需要 11 到 20 秒。由于那里的目标代码库存在超过 300,000 个提交,因此检索所有提交的此信息将花费很多时间。

但是,gitk 显然设法很好地检索了这些数据。根据我的搜索,它为此目的使用了缓存。

我有两个问题:

  1. 我如何解释该缓存格式?
  2. 有没有办法从 git 命令行工具获取转储以生成相同的信息?

最佳答案

你几乎可以直接从 git rev-list 得到这个.

latest.awk :

BEGIN { thiscommit=""; }
$1 == "commit" {
if ( thiscommit != "" )
print thiscommit, tags[thiscommit]
thiscommit=$2
line[$2]=NR
latest = 0;
for ( i = 3 ; i <= NF ; ++i ) if ( line[$i] > latest ) {
latest = line[$i];
tags[$2] = tags[$i];
}
next;
}
$1 != "commit" { tags[thiscommit] = $0; }
END { if ( thiscommit != "" ) print thiscommit, tags[thiscommit]; }

示例命令:

git rev-list --date-order --children --format=%d --all | awk -f latest.awk

你也可以使用--topo-order ,并且您可能必须清除 $1!="commit" 中不需要的引用逻辑。

根据您想要的传递性类型以及列表的明确程度,累积标签可能需要字典。这是一个获取所有提交的所有引用的明确列表的方法:

all.awk :

BEGIN {
thiscommit="";
}
$1 == "commit" {
if ( thiscommit != "" )
print thiscommit, tags[thiscommit]
thiscommit=$2
line[$2]=NR
split("",seen);
for ( i = 3 ; i <= NF ; ++i ) {
nnew=split(tags[$i],new);
for ( n = 1 ; n <= nnew ; ++n ) {
if ( !seen[new[n]] ) {
tags[$2]= tags[$2]" "new[n]
seen[new[n]] = 1
}
}
}
next;
}
$1 != "commit" {
nnew=split($0,new,", ");
new[1]=substr(new[1],3);
new[nnew]=substr(new[nnew],1,length(new[nnew])-1);
for ( n = 1; n <= nnew ; ++n )
tags[thiscommit] = tags[thiscommit]" "new[n]

}
END { if ( thiscommit != "" ) print thiscommit, tags[thiscommit]; }

all.awk花了几分钟做 322K linux 内核 repo 提交,大约每秒一千次或类似的东西(很多重复的字符串和冗余处理)所以如果你真的在完成之后你可能想用 C++ 重写它叉积...但我认为 gitk 不会显示,只有最近的邻居,对吧?

关于git - 高效检索包含提交的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10890011/

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