importing mercurial patch
- From
Ondrej Certik <ondrej@certik.cz>
- Date
- Nov 11, 2008, 10:58 UTC
- Message-ID
- <85b5c3130811110258h53d389co97a3c33e10667ae8@mail.gmail.com>
Hi,
I'd like git to be able to import mercurial-exported patches. This short Python program does it:
------------------------------------- #! /usr/bin/python
import os import sys import re import tempfile
def run(cmd):
print cmd
os.system(cmd)patch = sys.argv[1]
p = open(patch).read()
author = re.search("# User (.+)", p).groups()[0]
p = p.split("\n")
while not p[0].startswith("# Parent"):
del p[0]
i = 1
while not p[i].startswith("diff -r "):
i += 1
commit_message = "\n".join(p[1:i])
_, filename = tempfile.mkstemp()
f = open(filename, "w")
f.write(commit_message)
f.close()run("git apply %s" % patch) run("git ci -a --author='%s' -F %s" % (author, filename) ) ---------------------
How should this be implemented in git? Should I try to extend "git-am.sh" to handle it?
For better imagination, this is how the patch looks like:
http://paste.debian.net/21210/
Thanks for any feedback, Ondrej