@@ -0,0 +1,3039 @@
+#!/usr/bin/env python%0A%22%22%22%5C%0AGit patch to HG changeset patch converter.%0A%0AUSAGE: git-patch-to-hg-export.py %3C git.patch %3E hg.patch%0A%22%22%22%0A%0Afrom email.utils import parsedate_tz, mktime_tz%0Aimport re%0Aimport os%0Aimport sys%0A%0A%0Adef git_patch_to_hg(fin, fout):%0A    fout.write('# HG changeset patch%5Cn')%0A%0A    subject_re = re.compile(r'%5E(RE:)?%5Cs*(%5C%5B%5B%5E%5D%5D*%5C%5D)?%5Cs*', re.I)%0A%0A    # headers%0A    for line in fin:%0A        if line.startswith('From: '):%0A            fout.write('# User %25s' %25 line%5B6:%5D)%0A        elif line.startswith('Date: '):%0A            t = parsedate_tz(line%5B6:%5D)%0A            timestamp = mktime_tz(t)%0A            timezone = -t%5B-1%5D%0A            fout.write('# Date %25d %25d%5Cn' %25 (timestamp, timezone))%0A        elif line.startswith('Subject: '):%0A            subject = subject_re.sub('', line%5B9:%5D)%0A            fout.write(subject + '%5Cn')%0A        elif line == '%5Cn' or line == '%5Cr%5Cn':%0A            break%0A%0A    # commit message%0A    for line in fin:%0A        if line == '---%5Cn':%0A            break%0A        fout.write(line)%0A%0A    # skip over the diffstat%0A    for line in fin:%0A        if line.startswith('diff --git'):%0A            fout.write('%5Cn' + line)%0A            break%0A%0A    # diff%0A    # NOTE: there will still be an index line after each diff --git, but it%0A    # will be ignored%0A    for line in fin:%0A        fout.write(line)%0A%0A    # NOTE: the --/version will still be at the end, but it will be ignored%0A%0A%0Adef open_file():%0A    if len(sys.argv) %3E 1:%0A        if re.match('https?://', sys.argv%5B1%5D):%0A            import requests%0A            import io%0A            resp = requests.get(sys.argv%5B1%5D)%0A            return io.StringIO(resp.content) if resp.ok else io.StringIO('')%0A        elif os.path.exists(sys.argv%5B1%5D):%0A            return open(sys.argv%5B1%5D)%0A    return sys.stdin%0A%0A%0Aif __name__ == %22__main__%22:%0A    patch_fd = open_file()%0A    git_patch_to_hg(patch_fd, sys.stdout)%0A%0A%0A__author__ = %22Mark Lodato %3Clodatom@gmail.com%3E%22%0A%0A__license__ = %22%22%22%0AThis is the MIT license: http://www.opensource.org/licenses/mit-license.php%0A%0ACopyright (c) 2009 Mark Lodato%0A%0APermission is hereby granted, free of charge, to any person obtaining a copy%0Aof this software and associated documentation files (the %22Software%22), to%0Adeal in the Software without restriction, including without limitation the%0Arights to use, copy, modify, merge, publish, distribute, sublicense, and/or%0Asell copies of the Software, and to permit persons to whom the Software is%0Afurnished to do so, subject to the following conditions:%0A%0AThe above copyright notice and this permission notice shall be included in%0Aall copies or substantial portions of the Software.%0A%0ATHE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0AIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0AFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0AAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0ALIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING%0AFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS%0AIN THE SOFTWARE.%0A%22%22%22%0A

Add git-patch-to-hg-export.py