• Home
  • Raw
  • Download

Lines Matching +full:rev +full:- +full:parse

3 # Use of this source code is governed by a BSD-style license that can be
30 # llvm-svn: 375505
38 # The first element is the first non-`llvm-svn` commit that exists. Later ones
50 # - |dir| is the directory of the LLVM checkout
51 # - |remote| is the name of the LLVM remote. Generally it's "origin".
57 class Rev(NamedTuple("Rev", (("branch", str), ("number", int)))): class
61 def parse(rev: str) -> "Rev": member in Rev
62 """Parses a Rev from the given string.
64 Raises a ValueError on a failed parse.
71 if rev.startswith("r"):
73 rev_string = rev[1:]
75 match = re.match(r"\((.+), r(\d+)\)", rev)
77 raise ValueError("%r isn't a valid revision" % rev)
81 return Rev(branch=branch_name, number=int(rev_string))
83 def __str__(self) -> str:
90 def is_git_sha(xs: str) -> bool:
99 def check_output(command: List[str], cwd: Union[Path, str]) -> str:
100 """Shorthand for subprocess.check_output. Auto-decodes any stdout."""
107 encoding="utf-8",
114 ) -> int:
115 """Translates a sha to a revision number (e.g., "llvm-svn: 1234").
120 ["git", "log", "-n1", "--format=%B", sha, "--"],
123 last_line = commit_message.strip().splitlines()[-1]
124 svn_match = re.match(r"^llvm-svn: (\d+)$", last_line)
128 f"No llvm-svn line found for {sha}, which... shouldn't happen?"
134 def translate_sha_to_rev(llvm_config: LLVMConfig, sha_or_ref: str) -> Rev:
135 """Translates a sha or git ref to a Rev."""
141 ["git", "rev-parse", "--revs-only", sha_or_ref, "--"],
148 ["git", "merge-base", base_sha, sha, "--"],
156 "rev-list",
157 "--count",
158 "--first-parent",
160 "--",
165 return Rev(branch=MAIN_BRANCH, number=count + base_rev)
168 # - |merge_base| is |sha| (we have a guaranteed llvm-svn number on |sha|)
169 # - |merge_base| is neither (we have a guaranteed llvm-svn number on
175 return Rev(branch=MAIN_BRANCH, number=merge_base_number)
180 "rev-list",
181 "--count",
182 "--first-parent",
184 "--",
191 ["git", "branch", "-r", "--contains", sha],
220 return Rev(branch=candidates[0], number=revision_number)
225 ) -> Iterable[Tuple[str, str]]:
245 # pylint: disable=stop-iteration-return
262 def translate_prebase_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str: argument
263 """Translates a Rev to a SHA.
265 This function assumes that the given rev refers to a commit that's an
268 # Because reverts may include reverted commit messages, we can't just |-n1|
271 looking_for = f"llvm-svn: {rev.number}"
276 "--grep",
278 f"--format=%H%n%B{separator}",
287 encoding="utf-8",
291 last_line = message.splitlines()[-1]
298 raise ValueError(f"No commit with revision {rev} found")
309 ) -> str:
316 child_sha: A child of `parent_sha` to find a rev on.
329 commits_behind_baseline = parent_rev - want_rev
335 "rev-list",
336 "--count",
337 "--first-parent",
339 "--",
352 commits_behind_baseline = child_rev - want_rev
360 "rev-parse",
361 "--revs-only",
369 def translate_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str: argument
370 """Translates a Rev to a SHA.
372 Raises a ValueError if the given Rev doesn't exist in the given config.
374 branch, number = rev
377 ["git", "rev-parse", "--revs-only", f"{llvm_config.remote}/{branch}"],
385 "merge-base",
404 return translate_prebase_rev_to_sha(llvm_config, rev)
431 assert False, "Couldn't find a base SHA for a rev on main?"
434 def find_root_llvm_dir(root_dir: str = ".") -> str:
440 ["git", "rev-parse", "--show-toplevel"],
446 def main(argv: List[str]) -> None:
449 "--llvm_dir",
454 "--upstream",
460 "--sha", help="A git SHA (or ref) to convert to a rev"
462 sha_or_rev.add_argument("--rev", help="A rev to convert into a sha")
471 "Couldn't autodetect an LLVM tree; please use --llvm_dir"
480 rev = translate_sha_to_rev(config, opts.sha)
481 print(rev)
483 sha = translate_rev_to_sha(config, Rev.parse(opts.rev))