Exemplo n.º 1
0
def handle_commit(args,
                  msg,
                  branch,
                  treename,
                  kernelobjdir,
                  tmpdir,
                  wgitdir,
                  backport_rev,
                  kernel_rev,
                  prev_kernel_rev=None,
                  defconfig=None,
                  env={},
                  commit_failure=True,
                  append_shortlog=None):
    log = []

    def logwrite(l):
        log.append(l)

    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        bpid = gentree.Bp_Identity(integrate=False,
                                   kconfig_prefix='CPTCFG_',
                                   project_prefix='',
                                   project_dir=wdir,
                                   target_dir=wdir,
                                   target_dir_name='',
                                   kconfig_source_var='$BACKPORT_DIR')
        failure = gentree.process(kernelobjdir,
                                  open(args.copy_list, 'r'),
                                  bpid=bpid,
                                  git_revision=kernel_rev,
                                  base_name=tree,
                                  logwrite=logwrite,
                                  verbose=True,
                                  git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL,
                                                             failure)
            for l in log:
                print(l)
            newline = ''
            append_shortlog = None
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree,
                                                    prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'],
                   tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig,
                           os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        if not failure or commit_failure:
            if append_shortlog:
                files = []
                for d in git.status(tree=wdir):
                    files.extend(d[1:])
                if files:
                    msg += '\n' + append_shortlog[2] + '\n\n'
                    msg += git.shortlog(append_shortlog[0],
                                        append_shortlog[1],
                                        tree=kernelobjdir,
                                        files=files)
                else:
                    msg += "\nNo commits changed the generated code.\n\n"

            msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
                'newline': newline,
                'PREFIX': PREFIX,
                'bprev': backport_rev,
                'tree': treename,
                'krev': kernel_rev,
            }

            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure
     print("too many commits (%d)!" % len(commits))
     sys.exit(10)
 prev_commits = {}
 p = prev
 for commit in commits:
     prev_commits[commit] = p
     p = commit
 for commit in commits:
     print('updating to commit %s' % commit)
     env = git.commit_env_vars(commit, tree=kernelobjdir)
     if prev_commits[commit] == prev:
         # committing multiple commits
         msg = git.commit_message(commit, kernelobjdir)
         try:
             # add information about commits that went into this
             shortlog = git.shortlog(prev, '%s^2' % commit,
                                     tree=kernelobjdir)
             msg += "\nCommits in this merge:\n\n" + shortlog
         except git.ExecutionError as e:
             # will fail if it wasn't a merge commit
             pass
     else:
         # multiple commits
         env = backport_author_env
         msg = "update multiple kernel commits\n\nCommits taken:\n\n"
         msg += git.shortlog(prev, commit, tree=kernelobjdir)
     failure = handle_commit(args, msg, branch, tree, kernelobjdir, branch_tmpdir,
                             wgitdir, backport_rev, commit, env=env,
                             prev_kernel_rev=prev, defconfig=defconfig,
                             commit_failure=not catch_up_from_failure)
     if not failure:
         prev = commit
Exemplo n.º 3
0
def handle_commit(args, msg, branch, treename, kernelobjdir, tmpdir, wgitdir, backport_rev, kernel_rev,
                  prev_kernel_rev=None, defconfig=None, env={}, commit_failure=True,
                  append_shortlog=None):
    log = []
    def logwrite(l):
        log.append(l)
    wdir = os.path.join(tmpdir, kernel_rev)
    os.makedirs(wdir)
    env = env.copy()
    env.update({
        'GIT_COMMITTER_NAME': SCRIPT_GIT_NAME,
        'GIT_COMMITTER_EMAIL': SCRIPT_GIT_EMAIL,
    })
    try:
        bpid = gentree.Bp_Identity(integrate = False,
                                   kconfig_prefix = 'CPTCFG_',
                                   project_prefix = '',
                                   project_dir = wdir,
                                   target_dir = wdir,
                                   target_dir_name = '',
                                   kconfig_source_var = '$BACKPORT_DIR')
        failure = gentree.process(kernelobjdir, open(args.copy_list, 'r'),
                                  bpid=bpid, git_revision=kernel_rev,
                                  base_name=tree, logwrite=logwrite,
                                  verbose=True, git_tracked_version=True)

        newline = '\n'
        if failure:
            env.update({
                'GIT_AUTHOR_NAME': SCRIPT_GIT_NAME,
                'GIT_AUTHOR_EMAIL': SCRIPT_GIT_EMAIL,
            })
            msg = 'Failed to create backport\n\n%s%s: %s' % (PREFIX, FAIL, failure)
            for l in log:
                print(l)
            newline=''
            append_shortlog=None
            if prev_kernel_rev:
                msg += '\n%s%s-last-success: %s' % (PREFIX, tree, prev_kernel_rev)

        os.rename(wgitdir, os.path.join(wdir, '.git'))

        if not failure:
            git.rm(opts=['--ignore-unmatch', '-q', '--cached', '-r', '.'], tree=wdir)
            if defconfig:
                os.symlink('defconfigs/%s' % defconfig, os.path.join(wdir, 'defconfig'))
            git.add('.', tree=wdir)
        else:
            git.reset(opts=['-q'], tree=wdir)

        if not failure or commit_failure:
            if append_shortlog:
                files = []
                for d in git.status(tree=wdir):
                    files.extend(d[1:])
                if files:
                    msg += '\n' + append_shortlog[2] + '\n\n'
                    msg += git.shortlog(append_shortlog[0], append_shortlog[1],
                                        tree=kernelobjdir, files=files)
                else:
                    msg += "\nNo commits changed the generated code.\n\n"

            msg += '''%(newline)s
%(PREFIX)sbackport: %(bprev)s
%(PREFIX)s%(tree)s: %(krev)s
''' % {
            'newline': newline,
            'PREFIX': PREFIX,
            'bprev': backport_rev,
            'tree': treename,
            'krev': kernel_rev,
          }

            git.commit(msg, tree=wdir, env=env, opts=['-q', '--allow-empty'])
            git.push(opts=['-f', '-q', 'origin', branch], tree=wdir)
        os.rename(os.path.join(wdir, '.git'), wgitdir)
    finally:
        if os.path.isdir(wdir):
            shutil.rmtree(wdir)

    return failure
Exemplo n.º 4
0
     sys.exit(10)
 prev_commits = {}
 p = prev
 for commit in commits:
     prev_commits[commit] = p
     p = commit
 for commit in commits:
     print('updating to commit %s' % commit)
     env = git.commit_env_vars(commit, tree=kernelobjdir)
     if prev_commits[commit] == prev:
         # committing multiple commits
         msg = git.commit_message(commit, kernelobjdir)
         try:
             # add information about commits that went into this
             shortlog = git.shortlog(prev,
                                     '%s^2' % commit,
                                     tree=kernelobjdir)
             msg += "\nCommits in this merge:\n\n" + shortlog
         except git.ExecutionError as e:
             # will fail if it wasn't a merge commit
             pass
     else:
         # multiple commits
         env = backport_author_env
         msg = "update multiple kernel commits\n\nCommits taken:\n\n"
         msg += git.shortlog(prev,
                             commit,
                             tree=kernelobjdir)
     failure = handle_commit(
         args,
         msg,