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

Re: importing mercurial patch

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 11, 2008, 14:41 UTC
Message-ID
<alpine.DEB.1.00.0811111454330.30769@pacific.mpi-cbg.de>
In-Reply-To
<85b5c3130811110418l11be8084sf0f47a1095755747@mail.gmail.com>
Hi,
On Tue, 11 Nov 2008, Ondrej Certik wrote:
> But imho if git supported mercurial patches, life would be a lot easier.
Mine would not be.

BTW I had to be online (which is not always the case when I read email) to access the pastebin, which made it more of a hassle to look at it than I deem necessary. Besides, it is bad because in 3 days, that pastie will be gone. Not nice.

So here is it, for the pleasure of others:
	# HG changeset patch
	# User Vinzent Steinberg <vinzent.steinberg@gmail.com>
	# Date 1226338168 -3600
	# Node ID 23efeaf89f7089d94307526ec0536eb6f4382213
	# Parent  dab6435e04fd083d66bbfa897cbe15ab9660b9e6
	<commit subject>
	<commit body>
	diff -r <commit name> -r <commit name> <filename>
	--- a/<filename> <date>
	--- b/<filename> <date>
	@@ <line range pair> @@
	...

So what I suggest is that you familiarize yourself with builtin-mailsplit.c. Basically you'd need to enhance the is_from_line() function to check this:

	const char *hg_patch_preamble = "# HG changeset patch\n";
	if (len >= strlen(hg_patch_preamble) && !memcmp(line, 
			hg_patch_preamble, strlen(hg_patch_preamble))
		return 1;

Then you need to familiarize yourself with builtin-mailinfo.c. In function mailinfo(), you'd need to work on this:

        /* process the email header */
        while (read_one_header_line(&line, fin))
                check_header(&line, p_hdr_data, 1);

I'd suggest to make the function read_one_header_line() into a handle_one_header_line(), and replace the while loop with this:

	if (!strbuf_getline(&line, fin)) {
		if (!strcmp(line.buf, "# HG changeset patch\n"))
			while (handle_one_hg_header_line(&line, 
					p_hdr_data, fin))
				strbuf_getline(&line, fin);
		else
			while (handle_one_header_line(&line, fin)) {
				check_header(&line, p_hdr_data, 1);
				strbuf_getline(&line, fin);
			}
	}
Implementing handle_one_hg_header_line() should be a breeze:
	static int handle_one_hg_header_line(struct strbuf *line,
			struct strbuf *hdr_data[], FILE *in)
	{
		if (line.buf[0] != '#') {
			strbuf_addbuf(hdr_data[1], line);
			return 0; /* no more headers */
		}
		if (!prefixcmp(line.buf, "# User "))
			strbuf_addstr(hdr_data[0], line.buf + 7);
		else if (!prefixcmp(line.buf, "# Date "))
			strbuf_addstr(hdr_data[2], line.buf + 7);
		return 1;
	}

Okay, this is all utterly untested, and you probably need to trim the newlines from the lines first, and maybe you need to replace the hdr_data[] entries instead of adding to them, but now you have a starting point.

Hth, Dscho

Previous: Ondrej CertikNext: Ondrej Certik
Message 5 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.