def func(parser, options, args): """Show the files modified by a patch (or the current patch) """ if options.bare and options.stat: raise CmdException('Cannot specify both --bare and --stat') if len(args) == 0: patch = 'HEAD' elif len(args) == 1: patch = args[0] else: parser.error('incorrect number of arguments') rev1 = git_id(crt_series, '%s^' % patch) rev2 = git_id(crt_series, '%s' % patch) if options.stat: output = gitlib.diffstat( git.diff(rev1=rev1, rev2=rev2, diff_flags=options.diff_flags)) elif options.bare: output = git.barefiles(rev1, rev2) else: output = git.files(rev1, rev2, diff_flags=options.diff_flags) if output: if not output.endswith('\n'): output += '\n' out.stdout_raw(output)
def func(parser, options, args): """Show the tree diff """ args = git.ls_files(args) directory.cd_to_topdir() if options.revs: rev_list = options.revs.split('..') rev_list_len = len(rev_list) if rev_list_len == 1: rev1 = rev_list[0] rev2 = None elif rev_list_len == 2: rev1 = rev_list[0] rev2 = rev_list[1] else: parser.error('incorrect parameters to -r') else: rev1 = 'HEAD' rev2 = None if not options.stat: options.diff_flags.extend(color_diff_flags()) diff_str = git.diff(args, rev1 and git_id(crt_series, rev1), rev2 and git_id(crt_series, rev2), diff_flags=options.diff_flags) if options.stat: out.stdout_raw(gitlib.diffstat(diff_str) + '\n') else: if diff_str: pager(diff_str)
def func(parser, options, args): """Show the tree diff """ args = git.ls_files(args) directory.cd_to_topdir() if options.revs: rev_list = options.revs.split('..') rev_list_len = len(rev_list) if rev_list_len == 1: rev1 = rev_list[0] rev2 = None elif rev_list_len == 2: rev1 = rev_list[0] rev2 = rev_list[1] else: parser.error('incorrect parameters to -r') else: rev1 = 'HEAD' rev2 = None if not options.stat: options.diff_flags.extend(color_diff_flags()) diff_str = git.diff(args, rev1 and git_id(crt_series, rev1), rev2 and git_id(crt_series, rev2), diff_flags = options.diff_flags) if options.stat: out.stdout_raw(gitlib.diffstat(diff_str) + '\n') else: if diff_str: pager(diff_str)
def __build_cover(tmpl, msg_id, options, patches): """Build the cover message (series description) to be sent via SMTP """ sender = __get_sender() if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = str(len(patches)) patch_nr_str = '0'.zfill(len(total_nr_str)) if len(patches) > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' tmpl_dict = {'sender': sender, # for backward template compatibility 'maintainer': sender, # for backward template compatibility 'endofheaders': '', # for backward template compatibility 'date': '', 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'shortlog': stack.shortlog(crt_series.get_patch(p) for p in reversed(patches)), 'diffstat': gitlib.diffstat(git.diff( rev1 = git_id(crt_series, '%s^' % patches[0]), rev2 = git_id(crt_series, '%s' % patches[-1]), diff_flags = options.diff_flags))} try: msg_string = tmpl % tmpl_dict except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err
def edit_file(series, line, comment, show_patch=True): fname = '.stgitmsg.txt' tmpl = templates.get_template('patchdescr.tmpl') f = file(fname, 'w+') if line: print >> f, line elif tmpl: print >> f, tmpl, else: print >> f print >> f, __comment_prefix, comment print >> f, __comment_prefix, \ 'Lines prefixed with "%s" will be automatically removed.' \ % __comment_prefix print >> f, __comment_prefix, \ 'Trailing empty lines will be automatically removed.' if show_patch: print >> f, __patch_prefix # series.get_patch(series.get_current()).get_top() git.diff([], series.get_patch(series.get_current()).get_bottom(), None, f) #Vim modeline must be near the end. print >> f, __comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:' f.close() call_editor(fname) f = file(fname, 'r+') __clean_comments(f) f.seek(0) result = f.read() f.close() os.remove(fname) return result
def func(parser, options, args): """Show the patches modifying a file """ if not args: files = [path for (stat, path) in git.tree_status(verbose=True)] # git.tree_status returns absolute paths else: files = git.ls_files(args) directory.cd_to_topdir() if not files: raise CmdException('No files specified or no local changes') applied = crt_series.get_applied() if not applied: raise CmdException('No patches applied') revs = git.modifying_revs(files, crt_series.get_base(), crt_series.get_head()) revs.reverse() # build the patch/revision mapping rev_patch = dict() for name in applied: patch = crt_series.get_patch(name) rev_patch[patch.get_top()] = patch # print the patch names diff_lines = [] for rev in revs: patch = rev_patch[rev] if options.diff: diff_lines.extend([ b'-' * 79, patch.get_name().encode('utf-8'), b'-' * 79, patch.get_description().encode('utf-8'), b'---', b'', git.diff(files, patch.get_bottom(), patch.get_top()), ]) else: out.stdout(patch.get_name()) if options.diff: pager(b'\n'.join(diff_lines))
def edit_file(series, line, comment, show_patch=True): fname = '.stgitmsg.txt' tmpl = templates.get_template('patchdescr.tmpl') with open(fname, 'w+') as f: if line: print(line, file=f) elif tmpl: print(tmpl, end=' ', file=f) else: print(file=f) print(__comment_prefix, comment, file=f) print(__comment_prefix, 'Lines prefixed with "%s" will be automatically removed.' % __comment_prefix, file=f) print(__comment_prefix, 'Trailing empty lines will be automatically removed.', file=f) if show_patch: print(__patch_prefix, file=f) # series.get_patch(series.get_current()).get_top() diff_str = git.diff( rev1=series.get_patch(series.get_current()).get_bottom()) f.write(diff_str) # Vim modeline must be near the end. print( __comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:', file=f, ) call_editor(fname) with open(fname, 'r+') as f: __clean_comments(f) f.seek(0) result = f.read() os.remove(fname) return result
def func(parser, options, args): """Show the patches modifying a file """ if not args: files = [path for (stat,path) in git.tree_status(verbose = True)] # git.tree_status returns absolute paths else: files = git.ls_files(args) directory.cd_to_topdir() if not files: raise CmdException('No files specified or no local changes') applied = crt_series.get_applied() if not applied: raise CmdException('No patches applied') revs = git.modifying_revs(files, crt_series.get_base(), crt_series.get_head()) revs.reverse() # build the patch/revision mapping rev_patch = dict() for name in applied: patch = crt_series.get_patch(name) rev_patch[patch.get_top()] = patch # print the patch names diff_output = '' for rev in revs: if rev in rev_patch: patch = rev_patch[rev] if options.diff: diff_output += diff_tmpl \ % (patch.get_name(), patch.get_description(), git.diff(files, patch.get_bottom(), patch.get_top())) else: out.stdout(patch.get_name()) if options.diff: pager(diff_output)
def func(parser, options, args): """Show the tree diff """ if options.revs: rev_list = options.revs.split('..') rev_list_len = len(rev_list) if rev_list_len == 1: rev = rev_list[0] if rev.endswith('/'): # the whole patch rev = strip_suffix('/', rev) if rev.endswith('/'): rev = strip_suffix('/', rev) rev1 = rev + '//bottom' rev2 = rev + '//top' else: rev1 = rev_list[0] rev2 = None elif rev_list_len == 2: rev1 = rev_list[0] rev2 = rev_list[1] else: parser.error('incorrect parameters to -r') else: rev1 = 'HEAD' rev2 = None if options.diff_opts: diff_flags = options.diff_opts.split() else: diff_flags = [] if options.stat: out.stdout_raw(git.diffstat(args, git_id(rev1), git_id(rev2)) + '\n') else: diff_str = git.diff(args, git_id(rev1), git_id(rev2), diff_flags=diff_flags) if diff_str: pager(diff_str)
def edit_file(series, line, comment, show_patch = True): fname = '.stgitmsg.txt' tmpl = templates.get_template('patchdescr.tmpl') f = file(fname, 'w+') if line: print >> f, line elif tmpl: print >> f, tmpl, else: print >> f print >> f, __comment_prefix, comment print >> f, __comment_prefix, \ 'Lines prefixed with "%s" will be automatically removed.' \ % __comment_prefix print >> f, __comment_prefix, \ 'Trailing empty lines will be automatically removed.' if show_patch: print >> f, __patch_prefix # series.get_patch(series.get_current()).get_top() diff_str = git.diff(rev1 = series.get_patch(series.get_current()).get_bottom()) f.write(diff_str) #Vim modeline must be near the end. print >> f, __comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:' f.close() call_editor(fname) f = file(fname, 'r+') __clean_comments(f) f.seek(0) result = f.read() f.close() os.remove(fname) return result
def func(parser, options, args): """Show the patches modifying a file """ if not args: files = [stat[1] for stat in git.tree_status(verbose=True)] else: files = args if not files: raise CmdException, 'No files specified or no local changes' applied = crt_series.get_applied() if not applied: raise CmdException, 'No patches applied' revs = git.modifying_revs(files, crt_series.get_base(), crt_series.get_head()) revs.reverse() # build the patch/revision mapping rev_patch = dict() for name in applied: patch = crt_series.get_patch(name) rev_patch[patch.get_top()] = patch # print the patch names diff_output = '' for rev in revs: if rev in rev_patch: patch = rev_patch[rev] if options.diff: diff_output += diff_tmpl \ % (patch.get_name(), patch.get_description(), git.diff(files, patch.get_bottom(), patch.get_top())) else: out.stdout(patch.get_name()) if options.diff: pager(diff_output)
def func(parser, options, args): """Show the tree diff """ if options.revs: rev_list = options.revs.split('..') rev_list_len = len(rev_list) if rev_list_len == 1: rev = rev_list[0] if rev.endswith('/'): # the whole patch rev = strip_suffix('/', rev) if rev.endswith('/'): rev = strip_suffix('/', rev) rev1 = rev + '//bottom' rev2 = rev + '//top' else: rev1 = rev_list[0] rev2 = None elif rev_list_len == 2: rev1 = rev_list[0] rev2 = rev_list[1] else: parser.error('incorrect parameters to -r') else: rev1 = 'HEAD' rev2 = None if options.diff_opts: diff_flags = options.diff_opts.split() else: diff_flags = [] if options.stat: out.stdout_raw(git.diffstat(args, git_id(rev1), git_id(rev2)) + '\n') else: diff_str = git.diff(args, git_id(rev1), git_id(rev2), diff_flags = diff_flags ) if diff_str: pager(diff_str)
def edit_file(series, line, comment, show_patch = True): fname = '.stgitmsg.txt' tmpl = templates.get_template('patchdescr.tmpl') with open(fname, 'w+') as f: if line: print(line, file=f) elif tmpl: print(tmpl, end=' ', file=f) else: print(file=f) print(__comment_prefix, comment, file=f) print(__comment_prefix, 'Lines prefixed with "%s" will be automatically removed.' % __comment_prefix, file=f) print(__comment_prefix, 'Trailing empty lines will be automatically removed.', file=f) if show_patch: print(__patch_prefix, file=f) # series.get_patch(series.get_current()).get_top() diff_str = git.diff(rev1 = series.get_patch(series.get_current()).get_bottom()) f.write(diff_str) #Vim modeline must be near the end. print(__comment_prefix, 'vi: set textwidth=75 filetype=diff nobackup:', file=f) call_editor(fname) with open(fname, 'r+') as f: __clean_comments(f) f.seek(0) result = f.read() os.remove(fname) return result
def func(parser, options, args): """Show the files modified by a patch (or the current patch) """ if len(args) == 0: patch = 'HEAD' elif len(args) == 1: patch = args[0] else: parser.error('incorrect number of arguments') rev1 = git_id(crt_series, '%s^' % patch) rev2 = git_id(crt_series, '%s' % patch) if options.stat: output = gitlib.diffstat(git.diff(rev1 = rev1, rev2 = rev2, diff_flags = options.diff_flags)) elif options.bare: output = git.barefiles(rev1, rev2) else: output = git.files(rev1, rev2, diff_flags = options.diff_flags) if output: if not output.endswith('\n'): output += '\n' out.stdout_raw(output)
except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err except TypeError: raise CmdException, 'Only "%(name)s" variables are ' \ 'supported in the patch template' if options.stdout: f = sys.stdout else: f = open(pfile, 'w+') if options.stdout and num > 1: print '-' * 79 print patch.get_name() print '-' * 79 # write description f.write(descr) # write the diff git.diff(rev1=patch.get_bottom(), rev2=patch.get_top(), out_fd=f, diff_flags=diff_flags) if not options.stdout: f.close() patch_no += 1 if not options.stdout: series.close()
def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): """Build the message to be sent via SMTP """ p = crt_series.get_patch(patch) descr = p.get_description().strip() descr_lines = descr.split('\n') short_descr = descr_lines[0].rstrip() long_descr = '\n'.join(descr_lines[1:]).lstrip() authname = p.get_authname(); authemail = p.get_authemail(); commname = p.get_commname(); commemail = p.get_commemail(); sender = __get_sender() fromauth = '%s <%s>' % (authname, authemail) if fromauth != sender: fromauth = 'From: %s\n\n' % fromauth else: fromauth = '' if options.version: version_str = ' %s' % options.version else: version_str = '' if options.prefix: prefix_str = options.prefix + ' ' else: confprefix = config.get('stgit.mail.prefix') if confprefix: prefix_str = confprefix + ' ' else: prefix_str = '' if options.diff_opts: diff_flags = options.diff_opts.split() else: diff_flags = [] total_nr_str = str(total_nr) patch_nr_str = str(patch_nr).zfill(len(total_nr_str)) if not options.unrelated and total_nr > 1: number_str = ' %s/%s' % (patch_nr_str, total_nr_str) else: number_str = '' tmpl_dict = {'patch': patch, 'sender': sender, # for backward template compatibility 'maintainer': sender, 'shortdescr': short_descr, 'longdescr': long_descr, # for backward template compatibility 'endofheaders': '', 'diff': git.diff(rev1 = git_id('%s//bottom' % patch), rev2 = git_id('%s//top' % patch), diff_flags = diff_flags ), 'diffstat': git.diffstat(rev1 = git_id('%s//bottom'%patch), rev2 = git_id('%s//top' % patch)), # for backward template compatibility 'date': '', 'version': version_str, 'prefix': prefix_str, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'fromauth': fromauth, 'authname': authname, 'authemail': authemail, 'authdate': p.get_authdate(), 'commname': commname, 'commemail': commemail} # change None to '' for key in tmpl_dict: if not tmpl_dict[key]: tmpl_dict[key] = '' try: msg_string = tmpl % tmpl_dict except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err
except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err except TypeError: raise CmdException, 'Only "%(name)s" variables are ' \ 'supported in the patch template' if options.stdout: f = sys.stdout else: f = open(pfile, 'w+') if options.stdout and num > 1: print '-'*79 print patch.get_name() print '-'*79 # write description f.write(descr) # write the diff git.diff(rev1 = patch.get_bottom(), rev2 = patch.get_top(), out_fd = f, diff_flags = diff_flags ) if not options.stdout: f.close() patch_no += 1 if not options.stdout: series.close()
def __build_message(tmpl, patch, patch_nr, total_nr, msg_id, ref_id, options): """Build the message to be sent via SMTP """ p = crt_series.get_patch(patch) descr = p.get_description().strip() descr_lines = descr.split('\n') short_descr = descr_lines[0].rstrip() long_descr = '\n'.join(descr_lines[1:]).lstrip() authname = p.get_authname() authemail = p.get_authemail() commname = p.get_commname() commemail = p.get_commemail() sender = __get_sender() fromauth = '%s <%s>' % (authname, authemail) if fromauth != sender: fromauth = 'From: %s\n\n' % fromauth else: fromauth = '' if options.version: version_str = ' %s' % options.version else: version_str = '' if options.prefix: prefix_str = options.prefix + ' ' else: confprefix = config.get('stgit.mail.prefix') if confprefix: prefix_str = confprefix + ' ' else: prefix_str = '' if options.diff_opts: diff_flags = options.diff_opts.split() else: diff_flags = [] total_nr_str = str(total_nr) patch_nr_str = str(patch_nr).zfill(len(total_nr_str)) if not options.unrelated and total_nr > 1: number_str = ' %s/%s' % (patch_nr_str, total_nr_str) else: number_str = '' tmpl_dict = { 'patch': patch, 'sender': sender, # for backward template compatibility 'maintainer': sender, 'shortdescr': short_descr, 'longdescr': long_descr, # for backward template compatibility 'endofheaders': '', 'diff': git.diff(rev1=git_id('%s//bottom' % patch), rev2=git_id('%s//top' % patch), diff_flags=diff_flags), 'diffstat': git.diffstat(rev1=git_id('%s//bottom' % patch), rev2=git_id('%s//top' % patch)), # for backward template compatibility 'date': '', 'version': version_str, 'prefix': prefix_str, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'fromauth': fromauth, 'authname': authname, 'authemail': authemail, 'authdate': p.get_authdate(), 'commname': commname, 'commemail': commemail } # change None to '' for key in tmpl_dict: if not tmpl_dict[key]: tmpl_dict[key] = '' try: msg_string = tmpl % tmpl_dict except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err
def __build_cover(tmpl, msg_id, options, patches): """Build the cover message (series description) to be sent via SMTP """ sender = __get_sender() if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = text(len(patches)) patch_nr_str = '0'.zfill(len(total_nr_str)) if len(patches) > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' tmpl_dict = { 'sender': sender, # for backward template compatibility 'maintainer': sender, # for backward template compatibility 'endofheaders': '', # for backward template compatibility 'date': '', 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'shortlog': stack.shortlog(crt_series.get_patch(p) for p in reversed(patches)), 'diffstat': diffstat( git.diff( rev1=git_id(crt_series, '%s^' % patches[0]), rev2=git_id(crt_series, '%s' % patches[-1]), diff_flags=options.diff_flags, )), } try: msg_bytes = templates.specialize_template(tmpl, tmpl_dict) except KeyError as err: raise CmdException('Unknown patch template variable: %s' % err) except TypeError: raise CmdException('Only "%(name)s" variables are ' 'supported in the patch template') if options.edit_cover: msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt') # The Python email message try: msg = message_from_bytes(msg_bytes) except Exception as ex: raise CmdException('template parsing error: %s' % str(ex)) extra_cc = [] if options.auto: for patch in patches: p = crt_series.get_patch(patch) if p.get_description(): descr = p.get_description().strip() extra_cc.extend(__get_signers_list(descr)) extra_cc = list(set(extra_cc)) if not options.git: __build_address_headers(msg, options, extra_cc) __build_extra_headers(msg, msg_id, options.in_reply_to) __encode_message(msg) return msg
def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id): """Build the message to be sent via SMTP """ p = crt_series.get_patch(patch) if p.get_description(): descr = p.get_description().strip() else: # provide a place holder and force the edit message option on descr = '<empty message>' options.edit_patches = True descr_lines = descr.split('\n') short_descr = descr_lines[0].strip() long_descr = '\n'.join(l.rstrip() for l in descr_lines[1:]).lstrip('\n') authname = p.get_authname(); authemail = p.get_authemail(); commname = p.get_commname(); commemail = p.get_commemail(); sender = __get_sender() fromauth = '%s <%s>' % (authname, authemail) if fromauth != sender: fromauth = 'From: %s\n\n' % fromauth else: fromauth = '' if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = str(total_nr) patch_nr_str = str(patch_nr).zfill(len(total_nr_str)) if not options.unrelated and total_nr > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' diff = git.diff(rev1 = git_id(crt_series, '%s^' % patch), rev2 = git_id(crt_series, '%s' % patch), diff_flags = options.diff_flags) tmpl_dict = {'patch': patch, 'sender': sender, # for backward template compatibility 'maintainer': sender, 'shortdescr': short_descr, 'longdescr': long_descr, # for backward template compatibility 'endofheaders': '', 'diff': diff, 'diffstat': gitlib.diffstat(diff), # for backward template compatibility 'date': '', 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'fromauth': fromauth, 'authname': authname, 'authemail': authemail, 'authdate': p.get_authdate(), 'commname': commname, 'commemail': commemail} # change None to '' for key in tmpl_dict: if not tmpl_dict[key]: tmpl_dict[key] = '' try: msg_string = tmpl % tmpl_dict except KeyError, err: raise CmdException, 'Unknown patch template variable: %s' \ % err
def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id): """Build the message to be sent via SMTP """ p = crt_series.get_patch(patch) if p.get_description(): descr = p.get_description().strip() else: # provide a place holder and force the edit message option on descr = '<empty message>' options.edit_patches = True descr_lines = descr.split('\n') short_descr = descr_lines[0].strip() long_descr = '\n'.join(l.rstrip() for l in descr_lines[1:]).lstrip('\n') authname = p.get_authname() authemail = p.get_authemail() commname = p.get_commname() commemail = p.get_commemail() sender = __get_sender() fromauth = '%s <%s>' % (authname, authemail) if fromauth != sender: fromauth = 'From: %s\n\n' % fromauth else: fromauth = '' if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = text(total_nr) patch_nr_str = text(patch_nr).zfill(len(total_nr_str)) if not options.unrelated and total_nr > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' diff = git.diff(rev1 = git_id(crt_series, '%s^' % patch), rev2 = git_id(crt_series, '%s' % patch), diff_flags = options.diff_flags) tmpl_dict = {'patch': patch, 'sender': sender, # for backward template compatibility 'maintainer': sender, 'shortdescr': short_descr, 'longdescr': long_descr, # for backward template compatibility 'endofheaders': '', 'diff': diff, 'diffstat': gitlib.diffstat(diff), # for backward template compatibility 'date': '', 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'fromauth': fromauth, 'authname': authname, 'authemail': authemail, 'authdate': p.get_authdate(), 'commname': commname, 'commemail': commemail} # change None to '' for key in tmpl_dict: if not tmpl_dict[key]: tmpl_dict[key] = '' try: msg_string = tmpl % tmpl_dict except KeyError as err: raise CmdException('Unknown patch template variable: %s' % err) except TypeError: raise CmdException('Only "%(name)s" variables are ' 'supported in the patch template') if options.edit_patches: msg_string = __edit_message(msg_string) # The Python email message try: msg = email.message_from_string(msg_string) except Exception as ex: raise CmdException('template parsing error: %s' % str(ex)) if options.auto: extra_cc = __get_signers_list(descr) else: extra_cc = [] if not options.git: __build_address_headers(msg, options, extra_cc) __build_extra_headers(msg, msg_id, ref_id) __encode_message(msg) return msg
def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id): """Build the message to be sent via SMTP """ p = crt_series.get_patch(patch) if p.get_description(): descr = p.get_description().strip() else: # provide a place holder and force the edit message option on descr = '<empty message>' options.edit_patches = True descr_lines = descr.split('\n') short_descr = descr_lines[0].strip() long_descr = '\n'.join(l.rstrip() for l in descr_lines[1:]).lstrip('\n') authname = p.get_authname() authemail = p.get_authemail() commname = p.get_commname() commemail = p.get_commemail() sender = __get_sender() fromauth = '%s <%s>' % (authname, authemail) if fromauth != sender: fromauth = 'From: %s\n\n' % fromauth else: fromauth = '' if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = text(total_nr) patch_nr_str = text(patch_nr).zfill(len(total_nr_str)) if not options.unrelated and total_nr > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' diff = git.diff( rev1=git_id(crt_series, '%s^' % patch), rev2=git_id(crt_series, '%s' % patch), diff_flags=options.diff_flags, ) tmpl_dict = { 'patch': patch, 'sender': sender, 'maintainer': sender, # for backward template compatibility 'shortdescr': short_descr, 'longdescr': long_descr, 'endofheaders': '', # for backward template compatibility 'diff': diff, 'diffstat': diffstat(diff), 'date': '', # for backward template compatibility 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'fromauth': fromauth, 'authname': authname, 'authemail': authemail, 'authdate': p.get_authdate(), 'commname': commname, 'commemail': commemail, } try: msg_bytes = templates.specialize_template(tmpl, tmpl_dict) except KeyError as err: raise CmdException('Unknown patch template variable: %s' % err) except TypeError: raise CmdException('Only "%(name)s" variables are ' 'supported in the patch template') if options.edit_patches: msg_bytes = edit_bytes(msg_bytes, '.stgitmail.txt') # The Python email message try: msg = message_from_bytes(msg_bytes) except Exception as ex: raise CmdException('template parsing error: %s' % str(ex)) if options.auto: extra_cc = __get_signers_list(descr) else: extra_cc = [] if not options.git: __build_address_headers(msg, options, extra_cc) __build_extra_headers(msg, msg_id, ref_id) __encode_message(msg) return msg
def __build_cover(tmpl, msg_id, options, patches): """Build the cover message (series description) to be sent via SMTP """ sender = __get_sender() if options.version: version_str = '%s' % options.version version_space = ' ' else: version_str = '' version_space = '' if options.prefix: prefix_str = options.prefix else: prefix_str = config.get('stgit.mail.prefix') if prefix_str: prefix_space = ' ' else: prefix_str = '' prefix_space = '' total_nr_str = text(len(patches)) patch_nr_str = '0'.zfill(len(total_nr_str)) if len(patches) > 1: number_str = '%s/%s' % (patch_nr_str, total_nr_str) number_space = ' ' else: number_str = '' number_space = '' tmpl_dict = {'sender': sender, # for backward template compatibility 'maintainer': sender, # for backward template compatibility 'endofheaders': '', # for backward template compatibility 'date': '', 'version': version_str, 'vspace': version_space, 'prefix': prefix_str, 'pspace': prefix_space, 'patchnr': patch_nr_str, 'totalnr': total_nr_str, 'number': number_str, 'nspace': number_space, 'snumber': number_str.strip(), 'shortlog': stack.shortlog(crt_series.get_patch(p) for p in reversed(patches)), 'diffstat': gitlib.diffstat(git.diff( rev1 = git_id(crt_series, '%s^' % patches[0]), rev2 = git_id(crt_series, '%s' % patches[-1]), diff_flags = options.diff_flags))} try: msg_string = tmpl % tmpl_dict except KeyError as err: raise CmdException('Unknown patch template variable: %s' % err) except TypeError: raise CmdException('Only "%(name)s" variables are ' 'supported in the patch template') if options.edit_cover: msg_string = __edit_message(msg_string) # The Python email message try: msg = email.message_from_string(msg_string) except Exception as ex: raise CmdException('template parsing error: %s' % str(ex)) extra_cc = [] if options.auto: for patch in patches: p = crt_series.get_patch(patch) if p.get_description(): descr = p.get_description().strip() extra_cc.extend(__get_signers_list(descr)) extra_cc = list(set(extra_cc)) if not options.git: __build_address_headers(msg, options, extra_cc) __build_extra_headers(msg, msg_id, options.in_reply_to) __encode_message(msg) return msg