git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ondrej Certik" <ondrej@certik.cz>
To: "Git Mailing List" <git@vger.kernel.org>
Subject: Re: importing mercurial patch
Date: Wed, 12 Nov 2008 00:36:19 +0100	[thread overview]
Message-ID: <85b5c3130811111536q774ad33fk76da59cf90c264df@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.1.00.0811111454330.30769@pacific.mpi-cbg.de>

Hi Johannes!

On Tue, Nov 11, 2008 at 3:41 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> 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.

Because you don't use Mercurial, or is there also some other reason?

> 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.

You are right, sorry about that.

>
> 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.

Thanks a lot for the detailed help, I'll give it a shot and report
back in couple days, hopefully with a working patch. :)

Ondrej

      reply	other threads:[~2008-11-11 23:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-11 10:58 importing mercurial patch Ondrej Certik
2008-11-11 10:59 ` Ondrej Certik
2008-11-11 12:00 ` Johannes Schindelin
2008-11-11 12:18   ` Ondrej Certik
2008-11-11 14:41     ` Johannes Schindelin
2008-11-11 23:36       ` Ondrej Certik [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85b5c3130811111536q774ad33fk76da59cf90c264df@mail.gmail.com \
    --to=ondrej@certik.cz \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).