Lines Matching +full:llvm +full:- +full:strip
3 # Use of this source code is governed by a BSD-style license that can be
6 """Maps LLVM git SHAs to synthetic revision numbers and back.
30 # llvm-svn: 375505
38 # The first element is the first non-`llvm-svn` commit that exists. Later ones
49 # Represents an LLVM git checkout:
50 # - |dir| is the directory of the LLVM checkout
51 # - |remote| is the name of the LLVM remote. Generally it's "origin".
58 """Represents a LLVM 'revision', a shorthand identifies a LLVM commit."""
61 def parse(rev: str) -> "Rev":
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:
141 ["git", "rev-parse", "--revs-only", sha_or_ref, "--"],
144 sha = sha.strip()
148 ["git", "merge-base", base_sha, sha, "--"],
151 merge_base = merge_base.strip()
156 "rev-list",
157 "--count",
158 "--first-parent",
160 "--",
164 count = int(result.strip())
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
180 "rev-list",
181 "--count",
182 "--first-parent",
184 "--",
189 revision_number = merge_base_number + int(distance_from_base.strip())
191 ["git", "branch", "-r", "--contains", sha],
199 branch = branch.strip()
225 ) -> Iterable[Tuple[str, str]]:
245 # pylint: disable=stop-iteration-return
250 sha = sha.strip()
255 if line.strip() == separator:
262 def translate_prebase_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str:
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]
292 if last_line.strip() == looking_for:
309 ) -> str:
313 llvm_config: LLVM config to use.
329 commits_behind_baseline = parent_rev - want_rev
335 "rev-list",
336 "--count",
337 "--first-parent",
339 "--",
344 commits_between_parent_and_child.strip()
352 commits_behind_baseline = child_rev - want_rev
360 "rev-parse",
361 "--revs-only",
366 return result.strip()
369 def translate_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str:
377 ["git", "rev-parse", "--revs-only", f"{llvm_config.remote}/{branch}"],
379 ).strip()
385 "merge-base",
391 main_merge_point = main_merge_point.strip()
434 def find_root_llvm_dir(root_dir: str = ".") -> str:
435 """Finds the root of an LLVM directory starting at |root_dir|.
440 ["git", "rev-parse", "--show-toplevel"],
443 return result.strip()
446 def main(argv: List[str]) -> None:
449 "--llvm_dir",
450 help="LLVM directory to consult for git history, etc. Autodetected "
451 "if cwd is inside of an LLVM tree",
454 "--upstream",
456 help="LLVM upstream's remote name. Defaults to %(default)s.",
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"