Lines Matching +full:- +full:- +full:repo
3 # ====- code-format-helper, runs code formatters from the ci or in a hook --*- python -*--==#
7 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 # ==--------------------------------------------------------------------------------------==#
21 the coding style of LLVM. It can also be installed as a pre-commit git hook to
25 For C/C++ code it uses clang-format and for Python code it uses darker (which
34 ln -s $(pwd)/llvm/utils/git/code-format-helper.py .git/hooks/pre-commit
36 You can control the exact path to clang-format or darker with the following
44 repo: str = None
51 def __init__(self, args: argparse.Namespace = None) -> None:
55 self.repo = args.repo
63 COMMENT_TAG = "<!--LLVM CODE FORMAT COMMENT: {fmt}-->"
69 def comment_tag(self) -> str:
73 def instructions(self) -> str:
76 def has_tool(self) -> bool:
79 def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
82 def pr_comment_text_for_diff(self, diff: str) -> str:
111 def find_comment(self, pr: any) -> any:
117 def update_pr(self, comment_text: str, args: FormatArgs, create_new: bool) -> None:
121 repo = github.Github(args.token).get_repo(args.repo)
122 pr = repo.get_issue(args.issue_number).as_pull_request()
140 def run(self, changed_files: List[str], args: FormatArgs) -> bool:
141 changed_files = [arg for arg in changed_files if "third-party" not in arg]
143 should_update_gh = args.token is not None and args.repo is not None
175 name = "clang-format"
179 def instructions(self) -> str:
182 def should_include_extensionless_file(self, path: str) -> bool:
185 def filter_changed_files(self, changed_files: List[str]) -> List[str]:
196 def clang_fmt_path(self) -> str:
199 return "git-clang-format"
201 def has_tool(self) -> bool:
202 cmd = [self.clang_fmt_path, "-h"]
210 def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
215 cf_cmd = [self.clang_fmt_path, "--diff"]
221 # Gather the extension of all modified files and pass them explicitly to git-clang-format.
222 # This prevents git-clang-format from applying its own filtering rules on top of ours.
228 ) # Exclude periods since git-clang-format takes extensions without them
229 cf_cmd.append("--extensions")
232 cf_cmd.append("--")
239 sys.stdout.write(proc.stderr.decode("utf-8"))
246 print(proc.stdout.decode("utf-8"))
247 return proc.stdout.decode("utf-8")
257 def instructions(self) -> str:
260 def filter_changed_files(self, changed_files: List[str]) -> List[str]:
270 def darker_fmt_path(self) -> str:
275 def has_tool(self) -> bool:
276 cmd = [self.darker_fmt_path, "--version"]
284 def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
290 "--check",
291 "--diff",
294 darker_cmd += ["-r", f"{args.start_rev}...{args.end_rev}"]
303 sys.stdout.write(proc.stderr.decode("utf-8"))
310 print(proc.stdout.decode("utf-8"))
311 return proc.stdout.decode("utf-8")
313 sys.stdout.write(proc.stdout.decode("utf-8"))
322 def instructions(self) -> str:
325 def filter_changed_files(self, changed_files: List[str]) -> List[str]:
333 def has_tool(self) -> bool:
336 def pr_comment_text_for_diff(self, diff: str) -> str:
354 def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str]:
358 regex = "([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)"
359 cmd = ["git", "diff", "-U0", "--pickaxe-regex", "-S", regex]
372 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
380 # diff --git a/file b/file
381 for file in re.split("^diff --git ", stdout, 0, re.MULTILINE):
393 files = "\n".join(" - " + f for f in files)
398 [Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields `undef`. You should use `poison` values for placeholders instead.
435 cmd = ["git", "diff", "--cached", "--name-only", "--diff-filter=d"]
437 output = proc.stdout.decode("utf-8")
453 "Pre-commit format hook failed, rerun with FORMAT_HOOK_VERBOSE=1 environment for verbose output"
468 "--token", type=str, required=True, help="GitHub authentiation token"
471 "--repo",
473 default=os.getenv("GITHUB_REPOSITORY", "llvm/llvm-project"),
474 help="The GitHub repository that we are working with in the form of <owner>/<repo> (e.g. llvm/llvm-project)",
476 parser.add_argument("--issue-number", type=int, required=True)
478 "--start-rev",
484 "--end-rev", type=str, required=True, help="Compute changes to this revision"
487 "--changed-files",
492 "--write-comment-to-file",