usage = """%prog [options] [<dir>]
Export the applied patches into a given directory (defaults to
-'patches') in a standard unified GNU diff format. A file (defaulting
-to '.git/patchexport.tmpl') can be used as a template for the patch
-format. The following variables are supported in the template file:
+'patches') in a standard unified GNU diff format. A template file
+(defaulting to '.git/patchexport.tmpl or
+/usr/share/stgit/templates/patchexport.tmpl') can be used for the
+patch format. The following variables are supported in the template
+file:
%(description)s - patch description
%(diffstat)s - the diff statistics
help = 'Use FILE as a template'),
make_option('-r', '--range',
metavar = '[PATCH1][:[PATCH2]]',
- help = 'export patches between PATCH1 and PATCH2')]
+ help = 'export patches between PATCH1 and PATCH2'),
+ make_option('-b', '--branch',
+ help = 'use BRANCH instead of the default one')]
def func(parser, options, args):
if len(args) == 0:
- dirname = 'patches'
+ dirname = 'patches-%s' % crt_series.get_branch()
elif len(args) == 1:
dirname = args[0]
else:
parser.error('incorrect number of arguments')
- if git.local_changes():
+ if not options.branch and git.local_changes():
print 'Warning: local changes in the tree. ' \
'You might want to commit them first'
if start in applied:
start_idx = applied.index(start)
else:
- raise CmdException, 'Patch "%s" not applied' % start
+ if start in unapplied:
+ raise CmdException, 'Patch "%s" not applied' % start
+ else:
+ raise CmdException, 'Patch "%s" does not exist' % start
+
if stop in applied:
stop_idx = applied.index(stop) + 1
else:
- raise CmdException, 'Patch "%s" not applied' % stop
+ if stop in unapplied:
+ raise CmdException, 'Patch "%s" not applied' % stop
+ else:
+ raise CmdException, 'Patch "%s" does not exist' % stop
if start_idx >= stop_idx:
raise CmdException, 'Incorrect patch range order'
if zpadding < 2:
zpadding = 2
+ # get the template
+ if options.template:
+ patch_tmpl_list = [options.template]
+ else:
+ patch_tmpl_list = []
+
+ patch_tmpl_list += [os.path.join(git.base_dir, 'patchexport.tmpl'),
+ os.path.join(sys.prefix,
+ 'share/stgit/templates/patchexport.tmpl')]
+ tmpl = ''
+ for patch_tmpl in patch_tmpl_list:
+ if os.path.isfile(patch_tmpl):
+ tmpl = file(patch_tmpl).read()
+ break
+
patch_no = 1;
for p in patches:
pname = p
pfile = os.path.join(dirname, pname)
print >> series, pname
- # get the template
- if options.template:
- patch_tmpl = options.template
- else:
- patch_tmpl = os.path.join(git.base_dir, 'patchexport.tmpl')
- if os.path.isfile(patch_tmpl):
- tmpl = file(patch_tmpl).read()
- else:
- tmpl = ''
-
# get the patch description
patch = crt_series.get_patch(p)
tmpl_dict = {'description': patch.get_description().rstrip(),
- 'diffstat': git.diffstat(rev1 = git_id('%s/bottom' % p),
- rev2 = git_id('%s/top' % p)),
+ 'diffstat': git.diffstat(rev1 = patch.get_bottom(),
+ rev2 = patch.get_top()),
'authname': patch.get_authname(),
'authemail': patch.get_authemail(),
'authdate': patch.get_authdate(),
f.write(descr)
# write the diff
- git.diff(rev1 = git_id('%s/bottom' % p),
- rev2 = git_id('%s/top' % p),
+ git.diff(rev1 = patch.get_bottom(),
+ rev2 = patch.get_top(),
out_fd = f)
f.close()
patch_no += 1