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

Re: importing mercurial patch

From
Ondrej Certik <ondrej@certik.cz>
Date
Nov 11, 2008, 10:59 UTC
Message-ID
<85b5c3130811110259x5d659f7ah74e7774773bdcc58@mail.gmail.com>
In-Reply-To
<85b5c3130811110258h53d389co97a3c33e10667ae8@mail.gmail.com>
On Tue, Nov 11, 2008 at 11:58 AM, Ondrej Certik <ondrej@certik.cz> wrote:
Show 40 quoted lines
> 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?

Just to make it clear --- I will of course use sh or C with git, I only used Python above because that's the language I know the best.

Ondrej
Previous: Ondrej CertikNext: Johannes Schindelin
Message 2 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.