从网上得到一GIT binary patch文件, 却没办法把它恢复出来. google后发现可以用mercurial的hg工具还apply.
以下是在ubuntu下实际操作记录.
1) 先安装mercurial
sudo apt-get install mercurial
2) 用hg创建一个临时的代码库
hg init
3) vi .hg/hgrc 增加下面的内容,不然在后面的操作中会报"abort: no username supplied (see "hg help config")"的错误
[ui]
username = j <a.b.com>
4) 预先建一空文件, 否则会报"unable to find 'xxx' for patching"的错误
touch rt2860.bin
hg add rt2860.bin
5) 打补丁,得到想要的文件
hg import -f a.patch
通过分析hg的代码(python写的)发现"GIT binary patch"文件就是一经过base85编码的zip文件.
将其中的代码抽出来做一个小脚本, 就不需要上面那么麻烦了.
通过查阅网上资料,用python写了个小程序显示解码的过程.
附python2.4写的例程
# vim: set ts=8 sw=4 sts=4 et ai:
# Example base85 decoder, Walter Doekes 2012
import sys
import zlib
en85 = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z',
'!', '#', '$', '%', '&', '(', ')', '*', '+', '-',
';', '<', '=', '>', '?', '@', '^', '_', '