2017-06-02 109 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自身獲取實現)在實踐中可能很好。

相關問題