+
+def __import_series(filename, options):
+ """Import a series of patches
+ """
+ applied = crt_series.get_applied()
+
+ if filename:
+ f = file(filename)
+ patchdir = os.path.dirname(filename)
+ else:
+ f = sys.stdin
+ patchdir = ''
+
+ for line in f:
+ patch = re.sub('#.*$', '', line).strip()
+ if not patch:
+ continue
+ if options.ignore and patch in applied:
+ print 'Ignoring already applied patch "%s"' % patch
+ continue
+
+ patchfile = os.path.join(patchdir, patch)
+ __import_patch(patch, patchfile, options)
+
+def func(parser, options, args):
+ """Import a GNU diff file as a new patch
+ """
+ if len(args) > 1:
+ parser.error('incorrect number of arguments')
+
+ check_local_changes()
+ check_conflicts()
+ check_head_top_equal()
+
+ if len(args) == 1:
+ filename = args[0]
+ else:
+ filename = None
+
+ if options.series:
+ __import_series(filename, options)
+ else:
+ if options.name:
+ patch = options.name
+ elif filename:
+ patch = os.path.basename(filename)
+ else:
+ raise CmdException, 'Unknown patch name'
+
+ __import_patch(patch, filename, options)
+