您几乎可以直接从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 提交,大约每秒 1000 次或类似的东西(大量重复的字符串和冗余处理)所以你可能想用 C++ 重写它,如果你'真的在追求完整的交叉产品......但我不认为 gitk 表明,只有最近的邻居,对吧?