-options = [make_option('-m', '--mail',
- help = 'import the patch from a standard e-mail file',
- action = 'store_true'),
- make_option('-n', '--name',
- help = 'use NAME as the patch name'),
- make_option('-s', '--series',
- help = 'import a series of patches',
- action = 'store_true'),
- make_option('-i', '--ignore',
- help = 'ignore the applied patches in the series',
- action = 'store_true'),
- make_option('-b', '--base',
- help = 'use BASE instead of HEAD for file importing'),
- make_option('-e', '--edit',
- help = 'invoke an editor for the patch description',
- action = 'store_true'),
- make_option('-p', '--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 __end_descr(line):
- return re.match('---\s*$', line) or re.match('diff -', line) or \
- re.match('Index: ', line)
-
-def __parse_description(descr):
- """Parse the patch description and return the new description and
- author information (if any).
- """
- subject = body = ''
- authname = authemail = authdate = None
-
- descr_lines = [line.rstrip() for line in descr.split('\n')]
- if not descr_lines:
- raise CmdException, "Empty patch description"
-
- lasthdr = 0
- end = len(descr_lines)
-
- # Parse the patch header
- for pos in range(0, end):
- if not descr_lines[pos]:
- continue
- # check for a "From|Author:" line
- if re.match('\s*(?:from|author):\s+', descr_lines[pos], re.I):
- auth = re.findall('^.*?:\s+(.*)$', descr_lines[pos])[0]
- authname, authemail = name_email(auth)
- lasthdr = pos + 1
- continue
- # check for a "Date:" line
- if re.match('\s*date:\s+', descr_lines[pos], re.I):
- authdate = re.findall('^.*?:\s+(.*)$', descr_lines[pos])[0]
- lasthdr = pos + 1
- continue
- if subject:
- break
- # get the subject
- subject = descr_lines[pos]
- lasthdr = pos + 1
-
- # get the body
- if lasthdr < end:
- body = reduce(lambda x, y: x + '\n' + y, descr_lines[lasthdr:], '')
-
- return (subject + body, authname, authemail, authdate)
-
-def __parse_mail(filename = None):
- """Parse the input file in a mail format and return (description,
- authname, authemail, authdate)
+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