def update_patch_description(repo, cd, text, contains_diff): """Update the given L{CommitData<stgit.lib.git.CommitData>} with the given text description, which may contain author name and time stamp in addition to a new commit message. If C{contains_diff} is true, it may also contain a replacement diff. Return a pair: the new L{CommitData<stgit.lib.git.CommitData>}; and the diff text if it didn't apply, or C{None} otherwise.""" (message, authname, authemail, authdate, diff) = common.parse_patch(text, contains_diff) author = cd.author if authname is not None: author = author.set_name(authname) if authemail is not None: author = author.set_email(authemail) if authdate is not None: author = author.set_date(Date(authdate)) cd = cd.set_message(message).set_author(author) failed_diff = None if diff and not re.match(br'---\s*\Z', diff, re.MULTILINE): tree = repo.apply(cd.parent.data.tree, diff, quiet=False) if tree is None: failed_diff = diff else: cd = cd.set_tree(tree) return cd, failed_diff
def __import_file(filename, options, patch=None): """Import a patch from a file or standard input """ pname = None if filename: (f, pname) = __get_handle_and_name(filename) else: f = os.fdopen(sys.__stdin__.fileno(), 'rb') if patch: pname = patch elif not pname: pname = filename if options.mail: try: msg = message_from_binary_file(f) except Exception as ex: raise CmdException('error parsing the e-mail file: %s' % str(ex)) (message, author_name, author_email, author_date, diff) = parse_mail(msg) else: patch_str = f.read() (message, author_name, author_email, author_date, diff) = parse_patch(patch_str, contains_diff=True) if filename: f.close() __create_patch(pname, message, author_name, author_email, author_date, diff, options)
def __import_file(filename, options): """Import a patch from a file or standard input""" if filename: f, filename = __get_handle_and_name(filename) else: f = os.fdopen(sys.__stdin__.fileno(), 'rb') patch_data = f.read() if filename: f.close() message, patch_name, author_name, author_email, author_date, diff = parse_patch( patch_data, contains_diff=True, fail_on_empty_description=False) __create_patch( filename, message, patch_name, author_name, author_email, author_date, diff, options, )
def update_patch_description(repo, cd, text, contains_diff): """Create commit with updated description. The given :class:`stgit.lib.git.CommitData` is updated with the given description, which may contain author name and time stamp in addition to a new commit message. If ``contains_diff`` is true, it may also contain a replacement diff. :returns: tuple of the new :class:`CommitData<stgit.lib.git.CommitData>` and the diff test if it did not apply or None otherwise """ (message, authname, authemail, authdate, diff) = common.parse_patch(text, contains_diff) author = cd.author if authname is not None: author = author.set_name(authname) if authemail is not None: author = author.set_email(authemail) if authdate is not None: author = author.set_date(Date(authdate)) cd = cd.set_message(message).set_author(author) failed_diff = None if diff and not re.match(br'---\s*\Z', diff, re.MULTILINE): tree = repo.apply(cd.parent.data.tree, diff, quiet=False) if tree is None: failed_diff = diff else: cd = cd.set_tree(tree) return cd, failed_diff
def __import_file(filename, options, patch=None): """Import a patch from a file or standard input""" pname = None if filename: (f, pname) = __get_handle_and_name(filename) else: f = os.fdopen(sys.__stdin__.fileno(), 'rb') if patch: pname = patch elif not pname: pname = filename (message, author_name, author_email, author_date, diff) = parse_patch(f.read(), contains_diff=True) if filename: f.close() __create_patch(pname, message, author_name, author_email, author_date, diff, options)
def update_patch_description(repo, cd, text, contains_diff): """Update the given L{CommitData<stgit.lib.git.CommitData>} with the given text description, which may contain author name and time stamp in addition to a new commit message. If C{contains_diff} is true, it may also contain a replacement diff. Return a pair: the new L{CommitData<stgit.lib.git.CommitData>}; and the diff text if it didn't apply, or C{None} otherwise.""" (message, authname, authemail, authdate, diff ) = common.parse_patch(text, contains_diff) a = cd.author for val, setter in [(authname, 'set_name'), (authemail, 'set_email'), (git.Date.maybe(authdate), 'set_date')]: if val != None: a = getattr(a, setter)(val) cd = cd.set_message(run_commit_msg_hook(repo, message)).set_author(a) failed_diff = None if diff: tree = repo.apply(cd.parent.data.tree, diff, quiet = False) if tree == None: failed_diff = diff else: cd = cd.set_tree(tree) return cd, failed_diff
def update_patch_description(repo, cd, text, contains_diff): """Update the given L{CommitData<stgit.lib.git.CommitData>} with the given text description, which may contain author name and time stamp in addition to a new commit message. If C{contains_diff} is true, it may also contain a replacement diff. Return a pair: the new L{CommitData<stgit.lib.git.CommitData>}; and the diff text if it didn't apply, or C{None} otherwise.""" (message, authname, authemail, authdate, diff) = common.parse_patch(text, contains_diff) a = cd.author for val, setter in [(authname, 'set_name'), (authemail, 'set_email'), (git.Date.maybe(authdate), 'set_date')]: if val is not None: a = getattr(a, setter)(val) cd = cd.set_message(message).set_author(a) failed_diff = None if diff: tree = repo.apply(cd.parent.data.tree, diff, quiet=False) if tree is None: failed_diff = diff else: cd = cd.set_tree(tree) return cd, failed_diff