2

我有一个基本源文件base.hs,我使用它来创建同一程序(、、、)的不同foo.hs扩展bar.hs版本baz.hs。现在我想为每个修改版本创建一个补丁文件,但补丁应该累积以获得一个包含所有扩展的程序。

基础.hs

-- @@BEGIN_IMPORTS@@
-- @@END_IMPORTS@@

main = do
    -- @@BEGIN_EXTENSIONS@@
    -- @@END_EXTENSIONS@@
    putStrLn "Hello World"

foo.hs(注意它基本上是同一个文件)

-- @@BEGIN_IMPORTS@@
import Foo
-- @@END_IMPORTS@@

main = do
    -- @@BEGIN_EXTENSIONS@@
    putStrLn foo
    -- @@END_EXTENSIONS@@
    putStrLn "Hello World"

bar.hs

-- @@BEGIN_IMPORTS@@
import Bar
-- @@END_IMPORTS@@

main = do
    -- @@BEGIN_EXTENSIONS@@
    putStrLn bar
    -- @@END_EXTENSIONS@@
    putStrLn "Hello World"

baz.hs

-- @@BEGIN_IMPORTS@@
import Baz
-- @@END_IMPORTS@@

main = do
    -- @@BEGIN_EXTENSIONS@@
    putStrLn baz
    -- @@END_EXTENSIONS@@
    putStrLn "Hello World"

=>

扩展的.hs

-- @@BEGIN_IMPORTS@@
import Foo
import Bar
import Baz
-- @@END_IMPORTS@@

main = do
    -- @@BEGIN_EXTENSIONS@@
    putStrLn foo
    putStrLn bar
    putStrLn baz
    -- @@END_EXTENSIONS@@
    putStrLn "Hello World"

差异+补丁?

我知道diffpatch实用程序,但问题是如果我应用多个补丁,它们会相互抵消(因此我会得到baz.hs)。

不工作

diff -c base.hs foo.hs > foo.hs.c3
diff -c base.hs bar.hs > bar.hs.c3
diff -c base.hs baz.hs > baz.hs.c3
patch -o base_foo.hs base.hs foo.hs.c3
patch -o base_foo_bar.hs base_foo.hs bar.hs.c3
patch -o base_foo_bar_baz.hs base_foo_bar.hs baz.hs.c3

综合吗?

我也知道,combinediff但这仅在按顺序应用补丁时才有效,因此我需要从base_foo.hs.

差异3?

Diff + patch - Sum 而不是 replace是指diff3实用程序(patchutils包),但我似乎没有使所需的行为正常工作,而且我不知道这对多个补丁有何帮助。

不工作

touch null
diff3 foo.hs.c3 null bar.hs.c3 > foo_bar.hs.c3
patch -o base_foo_bar.hs base.hs foo_bar.hs.c3

(这里的想法是结合来自空文件的差异)

不工作

diff3 -m foo.hs.c3 base.hs bar.hs.c3 > base_foo_bar.hs

(显然它会产生一个包含所有三个版本的大冲突文件)

杂项?

我也有使用 git 等 SCM 的合并工具的想法,但显然它们只能用于提交,但我的文件不在版本控制中。

我目前的解决方案是通过插入代码片段,perl -pi -e但这相当费力且容易出错。

4

1 回答 1

0
# diffs can be created beforehand

diff base.hs foo.hs > foo.hs.diff
diff base.hs bar.hs > bar.hs.diff
diff base.hs baz.hs > baz.hs.diff

# *creating a mybase.hs here which is slightly different (like "Hello Mars")*

# the follow steps need to be done for every run

patch -o myfoo.hs mybase.hs foo.hs.diff
patch -o mybar.hs mybase.hs bar.hs.diff 
patch -o mybaz.hs mybase.hs baz.hs.diff

# we create a temp file here because it seems that merge-file and the stream operator '>'
# operate on the same file immediately
cp mybase.hs mybase_union.hs
git merge-file -p --union myfoo.hs mybase.hs mybase_union.hs         > mybase_union_foo.hs
git merge-file -p --union mybar.hs mybase.hs mybase_union_foo.hs     > mybase_union_foo_bar.hs
git merge-file -p --union mybaz.hs mybase.hs mybase_union_foo_bar.hs > mybase_union_foo_bar_baz.hs
cp mybase_union_foo_bar_baz.hs mybase_extended.hs

谢谢阿梅尔!

于 2013-09-19T13:31:27.230 回答