def __create_commit(repository, tree, parents, options, message = ''): """Return a new Commit object.""" cd = git.CommitData( tree = tree, parents = parents, message = message, author = git.Person.author(), committer = git.Person.committer()) cd = common.update_commit_data(cd, options) return repository.commit(cd)
def func(parser, options, args): """Create a new patch.""" stack = directory.repository.current_stack if stack.repository.default_index.conflicts(): raise CmdException( 'Cannot create a new patch -- resolve conflicts first') # Choose a name for the new patch -- or None, which means make one # up later when we've gotten hold of the commit message. if len(args) == 0: name = None elif len(args) == 1: name = args[0] if not stack.patches.is_name_valid(name): raise CmdException('Invalid patch name: "%s"' % name) elif name in stack.patches: raise CmdException('%s: patch already exists' % name) else: parser.error('incorrect number of arguments') if options.verbose: verbose = options.verbose else: verbose = config.getbool('stgit.new.verbose') or False cd = CommitData( tree=stack.head.data.tree, parents=[stack.head], message='', author=Person.author(), committer=Person.committer(), ) cd = update_commit_data( stack.repository, cd, message=options.message, author=options.author(cd.author), trailers=options.trailers, edit=(not options.save_template and options.message is None), verbose=verbose, ) if options.save_template: options.save_template(cd.message) return utils.STGIT_SUCCESS if not options.no_verify: cd = run_commit_msg_hook(stack.repository, cd) if name is None: name = stack.patches.make_name(cd.message_str) # Write the new patch. check_head_top_equal(stack) trans = StackTransaction(stack) trans.patches[name] = stack.repository.commit(cd) trans.applied.append(name) return trans.execute('new: %s' % name)
def __create_commit(repository, tree, parents, options, message=''): """Return a new Commit object.""" cd = git.CommitData(tree=tree, parents=parents, message=message, author=git.Person.author(), committer=git.Person.committer()) cd = common.update_commit_data(cd, options) return repository.commit(cd)
def func(parser, options, args): """Create a new patch.""" stack = directory.repository.current_stack if stack.repository.default_index.conflicts(): raise CmdException( 'Cannot create a new patch -- resolve conflicts first') # Choose a name for the new patch -- or None, which means make one # up later when we've gotten hold of the commit message. if len(args) == 0: name = None elif len(args) == 1: name = args[0] if stack.patches.exists(name): raise CmdException('%s: patch already exists' % name) elif not stack.patches.is_name_valid(name): raise CmdException('Invalid patch name: "%s"' % name) else: parser.error('incorrect number of arguments') cd = CommitData( tree=stack.head.data.tree, parents=[stack.head], message='', author=Person.author(), committer=Person.committer(), ) cd = update_commit_data(cd, options) if options.save_template: options.save_template(cd.message.encode('utf-8')) return utils.STGIT_SUCCESS if not options.no_verify: cd = run_commit_msg_hook(stack.repository, cd) if name is None: name = utils.make_patch_name(cd.message, stack.patches.exists) assert stack.patches.is_name_valid(name) # Write the new patch. stack.repository.default_iw trans = StackTransaction(stack, 'new: %s' % name) trans.patches[name] = stack.repository.commit(cd) trans.applied.append(name) return trans.run()
def __create_commit(repository, tree, parents, options, message=''): """Return a new Commit object.""" cd = CommitData( tree=tree, parents=parents, message=message, author=Person.author(), committer=Person.committer(), ) cd = update_commit_data( cd, message=options.message, author=options.author(cd.author), sign_str=options.sign_str, edit=options.message is None, ) return repository.commit(cd)
def func(parser, options, args): """Create a new patch.""" stack = directory.repository.current_stack if stack.repository.default_index.conflicts(): raise common.CmdException( 'Cannot create a new patch -- resolve conflicts first') # Choose a name for the new patch -- or None, which means make one # up later when we've gotten hold of the commit message. if len(args) == 0: name = None elif len(args) == 1: name = args[0] if stack.patches.exists(name): raise common.CmdException('%s: patch already exists' % name) else: parser.error('incorrect number of arguments') cd = gitlib.CommitData( tree = stack.head.data.tree, parents = [stack.head], message = '', author = gitlib.Person.author(), committer = gitlib.Person.committer()) cd = common.update_commit_data(cd, options) # run the commit-msg hook cd = cd.set_message(edit.run_commit_msg_hook(stack.repository, cd.message)) if options.save_template: options.save_template(cd.message) return utils.STGIT_SUCCESS if name == None: name = utils.make_patch_name(cd.message, lambda name: stack.patches.exists(name)) # Write the new patch. iw = stack.repository.default_iw trans = transaction.StackTransaction(stack, 'new') trans.patches[name] = stack.repository.commit(cd) trans.applied.append(name) return trans.run()
def __create_patch(filename, message, author_name, author_email, author_date, diff, options): """Create a new patch on the stack """ stack = directory.repository.current_stack if options.name: name = options.name if not stack.patches.is_name_valid(name): raise CmdException('Invalid patch name: %s' % name) elif filename: name = os.path.basename(filename) else: name = '' if options.stripname: name = __strip_patch_name(name) if not name: if options.ignore or options.replace: def unacceptable_name(name): return False else: unacceptable_name = stack.patches.exists name = make_patch_name(message, unacceptable_name) else: # fix possible invalid characters in the patch name name = re.sub(r'[^\w.]+', '-', name).strip('-') assert stack.patches.is_name_valid(name) if options.ignore and name in stack.patchorder.applied: out.info('Ignoring already applied patch "%s"' % name) return out.start('Importing patch "%s"' % name) author = Person( author_name, author_email, Date.maybe(author_date), ) author = options.author(author) try: if not diff: out.warn('No diff found, creating empty patch') tree = stack.head.data.tree else: iw = stack.repository.default_iw iw.apply( diff, quiet=False, reject=options.reject, strip=options.strip ) tree = iw.index.write_tree() cd = CommitData( tree=tree, parents=[stack.head], author=author, message=message, ) cd = update_commit_data( cd, message=None, author=None, sign_str=options.sign_str, edit=options.edit, ) commit = stack.repository.commit(cd) trans = StackTransaction(stack, 'import: %s' % name) try: if options.replace and name in stack.patchorder.unapplied: trans.delete_patches(lambda pn: pn == name, quiet=True) trans.patches[name] = commit trans.applied.append(name) except TransactionHalted: pass trans.run() finally: out.done()
def __create_patch(filename, message, patch_name, author_name, author_email, author_date, diff, options): """Create a new patch on the stack""" stack = directory.repository.current_stack if patch_name: name = patch_name elif options.name: name = options.name elif filename: name = os.path.basename(filename) else: name = '' if options.stripname: # Removing leading numbers and trailing extension name = re.sub( r'''^ (?:[0-9]+-)? # Optional leading patch number (.*?) # Patch name group (non-greedy) (?:\.(?:diff|patch))? # Optional .diff or .patch extension $ ''', r'\g<1>', name, flags=re.VERBOSE, ) need_unique = not (options.ignore or options.replace) if name: name = stack.patches.make_name(name, unique=need_unique, lower=False) else: name = stack.patches.make_name(message, unique=need_unique, lower=True) if options.ignore and name in stack.patchorder.applied: out.info('Ignoring already applied patch "%s"' % name) return out.start('Importing patch "%s"' % name) author = options.author( Person( author_name, author_email, Date.maybe(author_date), )) try: if not diff: out.warn('No diff found, creating empty patch') tree = stack.head.data.tree else: iw = stack.repository.default_iw iw.apply( diff, quiet=False, reject=options.reject, strip=options.strip, context_lines=options.context_lines, ) tree = iw.index.write_tree() cd = CommitData( tree=tree, parents=[stack.head], author=author, message=message, ) cd = update_commit_data( stack.repository, cd, message=None, author=None, trailers=options.trailers, edit=options.edit, ) commit = stack.repository.commit(cd) trans = StackTransaction(stack) try: if options.replace and name in stack.patchorder.unapplied: trans.delete_patches(lambda pn: pn == name, quiet=True) trans.patches[name] = commit trans.applied.append(name) except TransactionHalted: pass trans.execute('import: %s' % name) finally: out.done()