git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Next: Ondrej Certik
Message 1 of 6 in “importing mercurial patch”
  1. Ondrej CertikNov 11, 2008
  2. Ondrej CertikNov 11, 2008
  3. Johannes SchindelinNov 11, 2008
  4. Ondrej CertikNov 11, 2008
  5. Johannes SchindelinNov 11, 2008
  6. Ondrej CertikNov 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.