def generate_patches(repo, start, end, outdir, options): """ Generate patch files from git """ gbp.log.info("Generating patches from git (%s..%s)" % (start, end)) patches = [] commands = {} for treeish in [start, end]: if not repo.has_treeish(treeish): raise GbpError('Invalid treeish object %s' % treeish) start_sha1 = repo.rev_parse("%s^0" % start) try: end_commit = end except GitRepositoryError: # In case of plain tree-ish objects, assume current branch head is the # last commit end_commit = "HEAD" end_commit_sha1 = repo.rev_parse("%s^0" % end_commit) start_sha1 = repo.rev_parse("%s^0" % start) if not is_ancestor(repo, start_sha1, end_commit_sha1): raise GbpError("Start commit '%s' not an ancestor of end commit " "'%s'" % (start, end_commit)) # Check for merge commits, squash if merges found merges = repo.get_commits(start, end_commit, options=['--merges']) if merges: # Shorten SHA1s start_sha1 = repo.rev_parse(start, short=7) merge_sha1 = repo.rev_parse(merges[0], short=7) patch_fn = format_diff(outdir, None, repo, start_sha1, merge_sha1) if patch_fn: gbp.log.info("Merge commits found! Diff between %s..%s written " "into one monolithic diff" % (start_sha1, merge_sha1)) patches.append(patch_fn) start = merge_sha1 # Generate patches for commit in reversed(repo.get_commits(start, end_commit)): info = repo.get_commit_info(commit) (cmds, info['body']) = parse_gbp_commands(info, 'gbp-rpm', ('ignore'), ('if', 'ifarch')) if 'ignore' not in cmds: patch_fn = format_patch(outdir, repo, info, patches, options.patch_numbers) if patch_fn: commands[os.path.basename(patch_fn)] = cmds else: gbp.log.info('Ignoring commit %s' % info['id']) # Generate diff to the tree-ish object if end_commit != end: gbp.log.info("Generating diff file %s..%s" % (end_commit, end)) patch_fn = format_diff(outdir, None, repo, end_commit, end, options.patch_export_ignore_path) if patch_fn: patches.append(patch_fn) return [os.path.relpath(p) for p in patches], commands
def generate_patches(repo, start, end, outdir, options): """ Generate patch files from git """ gbp.log.info("Generating patches from git (%s..%s)" % (start, end)) patches = [] commands = {} for treeish in [start, end]: if not repo.has_treeish(treeish): raise GbpError('Invalid treeish object %s' % treeish) start_sha1 = repo.rev_parse("%s^0" % start) try: end_commit = end except GitRepositoryError: # In case of plain tree-ish objects, assume current branch head is the # last commit end_commit = "HEAD" end_commit_sha1 = repo.rev_parse("%s^0" % end_commit) start_sha1 = repo.rev_parse("%s^0" % start) if not is_ancestor(repo, start_sha1, end_commit_sha1): raise GbpError("Start commit '%s' not an ancestor of end commit " "'%s'" % (start, end_commit)) # Check for merge commits, squash if merges found merges = repo.get_commits(start, end_commit, options=['--merges']) if merges: # Shorten SHA1s start_sha1 = repo.rev_parse(start, short=7) merge_sha1 = repo.rev_parse(merges[0], short=7) patch_fn = format_diff(outdir, None, repo, start_sha1, merge_sha1) if patch_fn: gbp.log.info("Merge commits found! Diff between %s..%s written " "into one monolithic diff" % (start_sha1, merge_sha1)) patches.append(patch_fn) start = merge_sha1 # Generate patches for commit in reversed(repo.get_commits(start, end_commit)): info = repo.get_commit_info(commit) (cmds, info['body']) = parse_gbp_commands(info, 'gbp-rpm', ('ignore'), ('if', 'ifarch')) if not 'ignore' in cmds: patch_fn = format_patch(outdir, repo, info, patches, options.patch_numbers) if patch_fn: commands[os.path.basename(patch_fn)] = cmds else: gbp.log.info('Ignoring commit %s' % info['id']) # Generate diff to the tree-ish object if end_commit != end: gbp.log.info("Generating diff file %s..%s" % (end_commit, end)) patch_fn = format_diff(outdir, None, repo, end_commit, end, options.patch_export_ignore_path) if patch_fn: patches.append(patch_fn) return patches, commands