在命令行中,如果我输入
git tag --contains {commit}
Run Code Online (Sandbox Code Playgroud)
要获取包含给定提交的版本列表,每次提交大约需要11到20秒.由于目标代码库存在超过300,000次提交,因此为所有提交检索此信息需要很多时间.
但是,gitk显然设法检索这些数据做得很好.从我搜索的内容来看,它为此目的使用缓存.
我有两个问题:
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]; }
Run Code Online (Sandbox Code Playgroud)
示例命令:
git rev-list --date-order --children --format=%d --all | awk -f latest.awk
Run Code Online (Sandbox Code Playgroud)
你也可以使用--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]; }
Run Code Online (Sandbox Code Playgroud)
all.awk 花了几分钟做了322K linux内核repo提交,大约一千秒或类似的东西(许多重复的字符串和冗余处理)所以你可能想要用C++重写它,如果你真的在完成之后跨产品...但我不认为gitk表明,只有最近的邻居,对吗?
| 归档时间: |
|
| 查看次数: |
225 次 |
| 最近记录: |