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: git am can't import patches with the UTF8 BOM
Date: Thu, 15 Oct 2009 10:51:48 -0700	[thread overview]
Message-ID: <85b5c3130910151051h799770b9yd0e56472125426cf@mail.gmail.com> (raw)

Hi,

this happens to me very often when someone sends a patch using windows
(and I use linux):

$ git am ~/Desktop/0001-1664-nonsymbolic-systems-may-need-basis-recalculatio.patch
Patch format detection failed.

and the problem is that the patch contains the byte-order mark (BOM)
at the beginning:

$ hexdump -C ~/Desktop/0001-1664-nonsymbolic-systems-may-need-basis-recalculatio.patch
| less
00000000  ef bb bf 46 72 6f 6d 20  39 31 37 63 30 39 36 32  |...From 917c0962|
00000010  32 38 35 30 37 37 31 66  38 33 33 62 35 66 39 34  |2850771f833b5f94|
00000020  30 36 65 30 64 65 37 33  30 35 61 34 30 38 66 65  |06e0de7305a408fe|
00000030  20 4d 6f 6e 20 53 65 70  20 31 37 20 30 30 3a 30  | Mon Sep 17 00:0|
00000040  30 3a 30 30 20 32 30 30  31 0a 46 72 6f 6d 3a 20  |0:00 2001.From: |

e.g. it's the "ef bb bf" as can be checked on the wikipedia:

http://en.wikipedia.org/wiki/Byte-order_mark#Representations_of_byte_order_marks_by_encoding

for utf-8.

So either the windows version of git should not send the BOM in the
first place, or the linux version of git should be able to handle it.
Which of those should be fixed?

Thanks,
Ondrej

P.S. I currently use this simple python script to strip it:

------------------------
#!/usr/bin/python
"""
Fixes a bogus git patch.

Sometimes a patch that people submit to sympy contains the UTF-8 byte-order
mark (BOM), which are 3 character at the beginning, that cause "git am" to fail
when applying it. The solution is to remove them, which is the purpose of this
script. See this link for more info:

http://en.wikipedia.org/wiki/Byte-order_mark

Usage:

  git-fix-patch some.patch > some_fixed.patch

you can also rewrite the original file with the fix (inplace) by:

  git-fix-patch -s some.patch

"""

from textwrap import fill
import os
import re
from optparse import OptionParser

def main():
    parser = OptionParser(usage="[options] args")
    parser.add_option("-s", "--save", dest="save", action="store_true",
            default=False,
            help="Rewrite the original file with the fixed patch")
    options, args = parser.parse_args()
    if len(args) != 1:
        parser.print_help()
        return

    filename = args[0]
    s = open(filename).read()
    start = s.find("From")
    if start > 10:
        raise Exception("Uknown format of the git patch")

    # strip the bogus characters at the beginning of the file
    s = s[start:]

    # either save to a file or dump to stdout:
    if options.save:
        outfile = filename
        open(outfile, "w").write(s)
    else:
        print s

if __name__ == '__main__':
    main()
-----------------------

                 reply	other threads:[~2009-10-15 17:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=85b5c3130910151051h799770b9yd0e56472125426cf@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).