def from_email(self, msg): p = email.parser.Parser() self.message = p.parsestr(msg) if 'Git-commit' in self.message: self.commit = self.message['Git-commit'] msg_from = self.message.get_unixfrom() if msg_from is not None: m = re.match("From (\S{40})", msg_from) if m: msg_commit = m.group(1) if not self.commit or \ re.match("^%s.*" % self.commit, msg_commit) is not None: self.commit = msg_commit self.find_repo() if not self.repo: f = self.find_repo() if self.repo in self.mainline_repo_list: self.in_mainline = True elif self.repo and not self.message['Git-repo']: r = self.repourl if not r: r = PatchOps.get_git_repo_url(self.repo) if r and r not in self.mainline_repo_list: self.message.add_header('Git-repo', r) self.repourl = r if self.commit and not self.message['Git-commit']: self.message.add_header('Git-commit', self.commit) if self.in_mainline: tag = PatchOps.get_tag(self.commit, self.repo) if tag and tag == "undefined": tag = PatchOps.get_next_tag(self.repo) if tag: if 'Patch-mainline' in self.message: self.message.replace_header('Patch-mainline', tag) else: self.message.add_header('Patch-mainline', tag) elif self.message['Git-commit'] and self.repourl and \ re.search("git.kernel.org", self.repourl): if 'Patch-mainline' in self.message: self.message.replace_header('Patch-mainline', "Queued in subsystem maintainer repo") else: self.message.add_header('Patch-mainline', "Queued in subsystem maintainer repo") self.handle_merge()
def find_commit(self): for repo in self.repo_list: commit = PatchOps.get_commit(self.commit, repo, self.force) if commit is not None: self.repo = repo self.from_email(commit) return True return False
def get_pathname(self, dir=None, prefix="", suffix=""): if self.message and self.message['Subject']: fn = PatchOps.safe_filename(self.message['Subject']) fn = "%s%s%s" % (prefix, fn, suffix) if dir: fn = dir + os.sep + fn return fn else: raise InvalidPatchException("Patch contains no Subject line")
def files(self): diffstat = PatchOps.get_diffstat(self.body()) f = [] for line in diffstat.splitlines(): m = re.search("#? (\S+) \| ", line) if m: f.append(m.group(1)) if not f: return None return f
def find_repo(self): if self.message['Git-repo'] or self.in_mainline: return True if self.message['X-Git-Url']: self.parse_commitdiff_header() return True if self.commit: commit = None for repo in self.repo_list: commit = PatchOps.get_commit(self.commit, repo, self.force) if commit: r = self.repourl if not r: r = PatchOps.get_git_repo_url(self.repo) if r and r in self.mainline_repo_list: self.in_mainline = True else: self.repo = repo return True return False
def add_diffstat(self): for line in self.message.get_payload().splitlines(): if re.search("[0-9]+ files? changed, [0-9]+ insertion", line): return diffstat = PatchOps.get_diffstat(self.body()) text = "" switched = False need_sep = True body = "" for line in self.header().splitlines(): if re.match("^---$", line) and not switched: need_sep = False if need_sep: diffstat = "---\n" + diffstat else: diffstat = "\n" + diffstat diffstat += "\n" header = self.header().rstrip() + "\n" self.message.set_payload(header + diffstat + self.body())