-from stgit import stack, git
-
-
-help = 'import a GNU diff file as a new patch'
-usage = """%prog [options] [<file>|<commit>]
-
-Create a new patch and import the given GNU diff file (defaulting to
-the standard input) or a given commit object into it. By default, the
-file name is used as the patch name but this can be overriden with the
-'--name' option.
-
-The patch file can either be a normal file with the description at the
-top or it can have standard mail format, the Subject, From and Date
-headers being used for generating the patch information. The patch
-description has to be separated from the data with a '---' line. For a
-normal file, if no author information is given, the first
-'Signed-off-by:' line is used.
-
-When a commit object is imported, the log and author information are
-those of the commit object. Passing the '--reverse' option will cancel
-an existing commit object."""
-
-options = [make_option('-m', '--mail',
- help = 'import the patch from a standard e-mail file',
- action = 'store_true'),
- make_option('-c', '--commit',
- help = 'import a commit object as a patch',
- action = 'store_true'),
- make_option('--reverse',
- help = 'reverse the commit object before importing',
- action = 'store_true'),
- make_option('-n', '--name',
- help = 'use NAME as the patch name'),
- make_option('-e', '--edit',
- help = 'invoke an editor for the patch description',
- action = 'store_true'),
- make_option('-s', '--showpatch',
- help = 'show the patch content in the editor buffer',
- action = 'store_true'),
- make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
- help = 'use "NAME <EMAIL>" as the author details'),
- make_option('--authname',
- help = 'use AUTHNAME as the author name'),
- make_option('--authemail',
- help = 'use AUTHEMAIL as the author e-mail'),
- make_option('--authdate',
- help = 'use AUTHDATE as the author date'),
- make_option('--commname',
- help = 'use COMMNAME as the committer name'),
- make_option('--commemail',
- help = 'use COMMEMAIL as the committer e-mail')]
-
-
-def __parse_mail(filename = None):
- """Parse the input file in a mail format and return (description,
- authname, authemail, authdate)
+from stgit.out import *
+from stgit import argparse, stack, git
+
+name = 'import'
+help = 'Import a GNU diff file as a new patch'
+kind = 'patch'
+usage = ['[options] [<file>|<url>]']
+description = """
+Create a new patch and apply the given GNU diff file (or the standard
+input). By default, the file name is used as the patch name but this
+can be overridden with the '--name' option. The patch can either be a
+normal file with the description at the top or it can have standard
+mail format, the Subject, From and Date headers being used for
+generating the patch information. The command can also read series and
+mbox files.
+
+If a patch does not apply cleanly, the failed diff is written to the
+.stgit-failed.patch file and an empty StGIT patch is added to the
+stack.
+
+The patch description has to be separated from the data with a '---'
+line."""
+
+args = [argparse.files]
+options = [
+ opt('-m', '--mail', action = 'store_true',
+ short = 'Import the patch from a standard e-mail file'),
+ opt('-M', '--mbox', action = 'store_true',
+ short = 'Import a series of patches from an mbox file'),
+ opt('-s', '--series', action = 'store_true',
+ short = 'Import a series of patches', long = """
+ Import a series of patches from a series file or a tar archive."""),
+ opt('-u', '--url', action = 'store_true',
+ short = 'Import a patch from a URL'),
+ opt('-n', '--name',
+ short = 'Use NAME as the patch name'),
+ opt('-p', '--strip', type = 'int', metavar = 'N',
+ short = 'Remove N leading slashes from diff paths (default 1)'),
+ opt('-t', '--stripname', action = 'store_true',
+ short = 'Strip numbering and extension from patch name'),
+ opt('-i', '--ignore', action = 'store_true',
+ short = 'Ignore the applied patches in the series'),
+ opt('--replace', action = 'store_true',
+ short = 'Replace the unapplied patches in the series'),
+ opt('-b', '--base', args = [argparse.commit],
+ short = 'Use BASE instead of HEAD for file importing'),
+ opt('--reject', action = 'store_true',
+ short = 'leave the rejected hunks in corresponding *.rej files'),
+ opt('-e', '--edit', action = 'store_true',
+ short = 'Invoke an editor for the patch description'),
+ opt('-d', '--showdiff', action = 'store_true',
+ short = 'Show the patch content in the editor buffer'),
+ opt('-a', '--author', metavar = '"NAME <EMAIL>"',
+ short = 'Use "NAME <EMAIL>" as the author details'),
+ opt('--authname',
+ short = 'Use AUTHNAME as the author name'),
+ opt('--authemail',
+ short = 'Use AUTHEMAIL as the author e-mail'),
+ opt('--authdate',
+ short = 'Use AUTHDATE as the author date'),
+ ] + argparse.sign_options()
+
+directory = DirectoryHasRepository(log = True)
+
+def __strip_patch_name(name):
+ stripped = re.sub('^[0-9]+-(.*)$', '\g<1>', name)
+ stripped = re.sub('^(.*)\.(diff|patch)$', '\g<1>', stripped)
+
+ return stripped
+
+def __replace_slashes_with_dashes(name):
+ stripped = name.replace('/', '-')
+
+ return stripped
+
+def __create_patch(filename, message, author_name, author_email,
+ author_date, diff, options):
+ """Create a new patch on the stack