file:
%(description)s - patch description
+ %(shortdescr)s - the first line of the patch description
+ %(longdescr)s - the rest of the patch description, after the first line
%(diffstat)s - the diff statistics
%(authname)s - author's name
%(authemail)s - author's e-mail
make_option('-d', '--diff',
help = 'append .diff to the patch names',
action = 'store_true'),
+ make_option('-p', '--patch',
+ help = 'append .patch to the patch names',
+ action = 'store_true'),
make_option('-t', '--template', metavar = 'FILE',
help = 'Use FILE as a template'),
make_option('-r', '--range',
metavar = '[PATCH1][:[PATCH2]]',
help = 'export patches between PATCH1 and PATCH2'),
make_option('-b', '--branch',
- help = 'use BRANCH instead of the default one')]
+ help = 'use BRANCH instead of the default one'),
+ make_option('-s', '--stdout',
+ help = 'dump the patches to the standard output',
+ action = 'store_true')]
def func(parser, options, args):
print 'Warning: local changes in the tree. ' \
'You might want to commit them first'
- if not os.path.isdir(dirname):
- os.makedirs(dirname)
- series = file(os.path.join(dirname, 'series'), 'w+')
+ if not options.stdout:
+ if not os.path.isdir(dirname):
+ os.makedirs(dirname)
+ series = file(os.path.join(dirname, 'series'), 'w+')
applied = crt_series.get_applied()
unapplied = crt_series.get_unapplied()
patches = applied[start_idx:stop_idx]
num = len(patches)
+ if num == 0:
+ raise CmdException, 'No patches applied'
+
zpadding = len(str(num))
if zpadding < 2:
zpadding = 2
break
# note the base commit for this series
- base_commit = crt_series.get_patch(patches[0]).get_bottom()
- print >> series, '# This series applies on GIT commit %s' % base_commit
+ if not options.stdout:
+ base_commit = crt_series.get_patch(patches[0]).get_bottom()
+ print >> series, '# This series applies on GIT commit %s' % base_commit
patch_no = 1;
for p in patches:
pname = p
if options.diff:
pname = '%s.diff' % pname
+ elif options.patch:
+ pname = '%s.patch' % pname
if options.numbered:
pname = '%s-%s' % (str(patch_no).zfill(zpadding), pname)
pfile = os.path.join(dirname, pname)
- print >> series, pname
+ if not options.stdout:
+ print >> series, pname
# get the patch description
patch = crt_series.get_patch(p)
+ descr = patch.get_description().strip()
+ descr_lines = descr.split('\n')
+
+ short_descr = descr_lines[0].rstrip()
+ long_descr = reduce(lambda x, y: x + '\n' + y,
+ descr_lines[1:], '').strip()
+
tmpl_dict = {'description': patch.get_description().rstrip(),
+ 'shortdescr': short_descr,
+ 'longdescr': long_descr,
'diffstat': git.diffstat(rev1 = patch.get_bottom(),
rev2 = patch.get_top()),
'authname': patch.get_authname(),
except TypeError:
raise CmdException, 'Only "%(name)s" variables are ' \
'supported in the patch template'
- f = open(pfile, 'w+')
- f.write(descr)
+ if options.stdout:
+ f = sys.stdout
+ else:
+ f = open(pfile, 'w+')
+
+ if options.stdout and num > 1:
+ print '-------------------------------------------------------------------------------'
+ print patch.get_name()
+ print '-------------------------------------------------------------------------------'
+
+ # write description
+ f.write(descr)
# write the diff
git.diff(rev1 = patch.get_bottom(),
rev2 = patch.get_top(),
out_fd = f)
- f.close()
+ if not options.stdout:
+ f.close()
patch_no += 1
- series.close()
+ if not options.stdout:
+ series.close()