def update_tags(index, entries): """ Update the Git-repo tag (possibly by removing it) of patches. """ for entry in entries: with Patch(open(entry.name, mode="r+b")) as patch: message = "Failed to update tag \"%s\" in patch \"%s\". This " \ "tag is not found." if entry.dest_head == git_sort.remotes[0]: tag_name = "Patch-mainline" try: patch.change(tag_name, index.describe(entry.dest.index)) except KeyError: raise exc.KSNotFound(message % ( tag_name, entry.name, )) except git_sort.GSError as err: raise exc.KSError("Failed to update tag \"%s\" in patch " "\"%s\". %s" % ( tag_name, entry.name, str(err), )) patch.remove("Git-repo") else: tag_name = "Git-repo" try: patch.change(tag_name, repr(entry.new_url)) except KeyError: raise exc.KSNotFound(message % ( tag_name, entry.name, ))
def parse_section_header(line): """ Parse a series.conf line to identify if it's a comment denoting the beginning of a subsystem section. In that case, return the Head object it corresponds to. """ oot_text = git_sort.oot.rev line = line.strip() if not line.startswith("# "): raise exc.KSNotFound() line = line[2:] if line == oot_text: return git_sort.oot elif line.lower() == series_conf.start_text: raise exc.KSNotFound() words = line.split(None, 3) if len(words) > 2: raise exc.KSError( "Section comment \"%s\" in series.conf could not be parsed. " "series.conf is invalid." % (line, )) args = [git_sort.RepoURL(words[0])] if len(words) == 2: args.append(words[1]) head = git_sort.Head(*args) if head not in git_sort.remotes: raise exc.KSError( "Section comment \"%s\" in series.conf does not match any Head in " "variable \"remotes\". series.conf is invalid." % (line, )) return head
def split(series): before = [] inside = [] after = [] whitespace = [] comments = [] current = before for line in series: l = line.strip() if l == "": if comments: current.extend(comments) comments = [] whitespace.append(line) continue elif l.startswith("#"): if whitespace: current.extend(whitespace) whitespace = [] comments.append(line) if current == before and l.lower() == "# %s" % (start_text, ): current = inside elif current == inside and l.lower() == "# %s" % (end_text, ): current = after else: if comments: current.extend(comments) comments = [] if whitespace: current.extend(whitespace) whitespace = [] current.append(line) if comments: current.extend(comments) comments = [] if whitespace: current.extend(whitespace) whitespace = [] if current is before: raise exc.KSNotFound("Sorted subseries not found.") current.extend(comments) current.extend(whitespace) return ( before, inside, after, )
def find_commit_in_series(commit, series): """ Caller must chdir to where the entries in series can be found. """ for name in filter_series(series): patch = tag.Patch(name) found = False if commit in [firstword(value) for value in patch.get("Git-commit")]: found = True yield patch patch.close() if found: return raise exc.KSNotFound()
def find_commit(commit, series, mode="rb"): """ Caller must chdir to where the entries in series can be found. """ for name in filter_series(series): patch = Patch(open(name, mode="rb")) found = False if commit in [firstword(value) for value in patch.get("Git-commit") if value]: found = True yield name, patch patch.writeback() if found: return raise exc.KSNotFound()
def find_commit(commit, series, mode="rb"): """ commit: unabbreviated git commit id series: list of lines from series.conf mode: mode to open the patch files in, should be "rb" or "r+b" Caller must chdir to where the entries in series can be found. Returns patch.Patch instances """ for name in filter_series(series): patch = Patch(open(name, mode=mode)) found = False if commit in [ firstword(value) for value in patch.get("Git-commit") if value ]: found = True yield name, patch patch.writeback() if found: return raise exc.KSNotFound()