2017-06-02 56 views
0

我正在处理父级过滤器,并且需要(可能)重写当前修订版本父级的修订版本ID。我这个人的网页上看到,有一个地图功能可用,可以采取照顾:git filter-branch:如何使用map函数?

A map function is available that takes an "original sha1 id" argument and outputs a "rewritten sha1 id" if the commit has been already rewritten, and "original sha1 id" otherwise; the map function can return several ids on separate lines if your commit filter emitted multiple commits.

然而,当我尝试使用它在我父过滤脚本(一bash-基于脚本)的功能不可用:

我在我的代码有这样的:

echo Finding mapping of revision $i >&2 
    map $i >&2 
    echo done >&2 

结果时处理:

Finding mapping of revision e73bf9db5c4ce2fb1970c90e3a24a2ff004ec3fe 
rewrite_svn_parent.sh: line 44: map: command not found 
done 

理想情况下,我会这样做:NEW_ID=$(map $i)但只要功能不是可用,不能做太多。

https://git-scm.com/docs/git-filter-branch

回答

0

每个不同的滤波器的运行作为eval OP:

parentstr="$(echo "$parentstr" | eval "$filter_parent")" || 

(见https://github.com/git/git/blob/master/git-filter-branch.sh#L389)。这意味着您可以访问在父shell中定义的shell函数。但在你自己的脚本中,你不再拥有它们。这意味着您必须在此shell中运行所有内容,或者找到某种方式来导出或重现筛选器分支的map(但很明显,您将在很大程度上依赖于实现)。

如果这是bash的(或者,如果你的/bin/sh是bash)的,你可以只使用:

export -f bash; bash /path/to/script 

为你的父母过滤,仍然把它写成剧本。如果没有,那么“cheat”方法(从filter-branch自身获取实现)在实践中可能很好。

相关问题