• Home
  • Raw
  • Download

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

2 # -*- coding: utf-8 -*-
4 # Use of this source code is governed by a BSD-style license that can be
31 # llvm-svn: 375505
39 # - |dir| is the directory of the LLVM checkout
40 # - |remote| is the name of the LLVM remote. Generally it's "origin".
44 class Rev(t.NamedTuple('Rev', (('branch', str), ('number', int)))): class
48 def parse(rev: str) -> 'Rev': member in Rev
49 """Parses a Rev from the given string.
51 Raises a ValueError on a failed parse.
58 if rev.startswith('r'):
60 rev_string = rev[1:]
62 match = re.match(r'\((.+), r(\d+)\)', rev)
64 raise ValueError("%r isn't a valid revision" % rev)
68 return Rev(branch=branch_name, number=int(rev_string))
70 def __str__(self) -> str:
77 def is_git_sha(xs: str) -> bool:
83 def check_output(command: t.List[str], cwd: str) -> str:
84 """Shorthand for subprocess.check_output. Auto-decodes any stdout."""
91 encoding='utf-8',
97 sha: str) -> int:
98 """Translates a sha to a revision number (e.g., "llvm-svn: 1234").
103 ['git', 'log', '-n1', '--format=%B', sha],
106 last_line = commit_message.strip().splitlines()[-1]
107 svn_match = re.match(r'^llvm-svn: (\d+)$', last_line)
111 f"No llvm-svn line found for {sha}, which... shouldn't happen?")
116 def translate_sha_to_rev(llvm_config: LLVMConfig, sha_or_ref: str) -> Rev:
117 """Translates a sha or git ref to a Rev."""
123 ['git', 'rev-parse', sha_or_ref],
129 ['git', 'merge-base', base_llvm_sha, sha],
138 'rev-list',
139 '--count',
140 '--first-parent',
146 return Rev(branch=MAIN_BRANCH, number=count + base_llvm_revision)
149 # - |merge_base| is |sha| (we have a guaranteed llvm-svn number on |sha|)
150 # - |merge_base| is neither (we have a guaranteed llvm-svn number on
155 return Rev(branch=MAIN_BRANCH, number=merge_base_number)
160 'rev-list',
161 '--count',
162 '--first-parent',
170 ['git', 'branch', '-r', '--contains', sha],
196 return Rev(branch=candidates[0], number=revision_number)
200 separator: str) -> t.Iterable[t.Tuple[str, str]]:
220 # pylint: disable=stop-iteration-return
237 def translate_prebase_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str: argument
238 """Translates a Rev to a SHA.
240 This function assumes that the given rev refers to a commit that's an
243 # Because reverts may include reverted commit messages, we can't just |-n1|
246 looking_for = f'llvm-svn: {rev.number}'
249 'git', 'log', '--grep', f'^{looking_for}$', f'--format=%H%n%B{separator}',
258 encoding='utf-8',
263 last_line = message.splitlines()[-1]
270 raise ValueError(f'No commit with revision {rev} found')
273 def translate_rev_to_sha(llvm_config: LLVMConfig, rev: Rev) -> str: argument
274 """Translates a Rev to a SHA.
276 Raises a ValueError if the given Rev doesn't exist in the given config.
278 branch, number = rev
282 return translate_prebase_rev_to_sha(llvm_config, rev)
287 ['git', 'merge-base', base_llvm_sha, f'{llvm_config.remote}/{branch}'],
297 # Alternatively, we could |git log --format=%H|, but git is *super* fast
298 # about rev walking/counting locally compared to long |log|s, so we walk back
301 ['git', 'rev-parse', f'{llvm_config.remote}/{branch}'],
306 commit_number = number - base_revision_number
310 'rev-list',
311 '--count',
312 '--first-parent',
319 commits_behind_head = revs_between - commit_number
322 f'Revision {rev} is past {llvm_config.remote}/{branch}. Try updating '
326 ['git', 'rev-parse', f'{branch_head_sha}~{commits_behind_head}'],
333 def find_root_llvm_dir(root_dir: str = '.') -> str:
339 ['git', 'rev-parse', '--show-toplevel'],
345 def main(argv: t.List[str]) -> None:
348 '--llvm_dir',
352 '--upstream',
357 '--sha', help='A git SHA (or ref) to convert to a rev')
358 sha_or_rev.add_argument('--rev', help='A rev to convert into a sha')
366 parser.error("Couldn't autodetect an LLVM tree; please use --llvm_dir")
374 rev = translate_sha_to_rev(config, opts.sha)
375 print(rev)
377 sha = translate_rev_to_sha(config, Rev.parse(opts.rev))