def guess_from_comments(repo_dir, upstream, comments): commits = {} pull_requests = [] for c in comments: if not c.has_key('text') or c.get('text', None) == None or c.get('text', '') == '': continue for r in commit_regex: c_txt = c['text'] matches = r.finditer(c_txt) for m in matches: d = m.groupdict() if d.has_key('id'): commit_id = d['id'] if git.git_object_type(repo_dir, commit_id) == 'commit': if git.get_rev(repo_dir, commit_id) and git.commit_on_branch(repo_dir, commit_id, upstream): if not commits.has_key(commit_id): commits[commit_id] = [] # The reason should include the person's real name! reason = "%s made a comment which matched the pattern %s:\n%s\n%s" % ( c['creator']['name'], r.pattern, "-"*80, c_txt) commits[commit_id].append(reason) elif d.has_key('pr'): try: pr_num = int(d['pr'], 10) except ValueError: pass if not pr_num in pull_requests: pull_requests.append(pr_num) for pr_num in pull_requests: guess_from_pr(repo_dir, upstream, pr_num) return commits
def merge(repo_dir, gaia_url, branch_to, branch_from): git.delete_gaia(repo_dir) t = util.time_start() if os.path.exists(repo_dir): print "Updating Gaia" git.update_gaia(repo_dir, gaia_url) print "Updated Gaia in %0.2f seconds" % util.time_end(t) else: print "Creating Gaia" git.create_gaia(repo_dir, gaia_url) # This is sadly broken print "Created Gaia in %0.2f seconds" % util.time_end(t) print "Merging %s into branch %s" % (branch_from, branch_to) if not branch_to in git.branches(repo_dir): print >> sys.stderr, "Asking to merge into a branch that doesn't exist (%s)" % branch_to return None if not branch_from in git.branches(repo_dir): print >> sys.stderr, "Asking to merge from a branch that doesn't exist (%s)" % branch_from return None git.checkout(repo_dir, branch_to) start_commit = git.get_rev(repo_dir) git.merge(repo_dir, branch_from, strategy="recursive") end_commit = git.get_rev(repo_dir) print "Merge range is %s..%s" % (start_commit[:7], end_commit[:7]) print git.log(repo_dir, "%s..%s" % (start_commit, end_commit), pretty="oneline") print "Dry Run push" git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=True) info = git.push(repo_dir, remote="origin", branches=[branch_to]) print "Would be pusing to %s" % info["url"] for branch in info["branches"].keys(): s, e = info["branches"][branch] print " %s: %s..%s" % (branch, s, e) if util.ask_yn("Push for realises?"): info = git.push(repo_dir, remote="origin", branches=[branch_to], dry_run=False) print "Pushed to %s" % info["url"] for branch in info["branches"].keys(): s, e = info["branches"][branch] print " %s: %s..%s" % (branch, s, e) comment(repo_dir, branch_to, "%s..%s" % (start_commit, end_commit))
def merge_script(repo_dir, commit, branches): full_commit = git.get_rev(repo_dir, commit) s=[" git checkout %s" % branches[0]] master_num = git.determine_cherry_pick_master_number(repo_dir, commit, 'master') if not master_num: master_num = "" s.append(" git cherry-pick -x %s %s" % (master_num, full_commit)) s.append(" <RESOLVE MERGE CONFLICTS>") s.append(" git commit") for branch in branches[1:]: s.append(" git checkout %s" % branch) s.append(" git cherry-pick -x $(git log -n1 %s --pretty=%%H)" % branches[0]) return "\n".join(s)
def add_commit(repo_dir, upstream, commits, commit): if not git.valid_id(commit): print "This sha1 is not a valid commit id: %s" % commit return try: on_branch = git.commit_on_branch(repo_dir, commit, upstream) except: on_branch = False if not on_branch: print "Commit %s is not on upstream branch '%s'" % (commit, upstream) return try: full_rev = git.get_rev(repo_dir, id=commit) except git.GitError, e: full_rev = None