• Home
  • Raw
  • Download

Lines Matching +full:commit +full:- +full:message

5 # This source code is licensed under the BSD-style license found in the
11 pick_doc_commits.py --main=origin/main --release=origin/release/5.5
14 filter them down to the docs-only commits that should be cherrypicked. It will
34 # Controlled by the --verbose flag.
38 def debug_log(message: str):
39 """Prints a message to stderr if verbosity is greater than zero."""
42 sys.stderr.write(f"VERBOSE: {message}\n")
45 def run_git(command: List[str]) -> List[str]:
54 A list of the non-empty lines printed to stdout, without trailing
66 # Remove empty and whitespace-only lines.
70 debug_log("-----BEGIN GIT OUTPUT-----")
73 debug_log("-----END GIT OUTPUT-----")
79 class Commit: class
80 """A git commit hash and its one-line message."""
82 def __init__(self, hash: str, message: str = ""):
83 """Creates a new Commit with the given hash.
86 hash: The hexadecimal hash of the commit.
87 message: The one-line summary of the commit. If empty, this method
88 will ask git for the commit message.
91 if not message:
92 # Ask git for the commit message.
93 lines = run_git(["log", "-1", "--pretty=%s", self.hash])
95 message = " ".join(lines)
96 self.message = message.strip()
99 def from_line(line: str) -> "Commit":
100 """Creates a Commit from a string of the form '<hash> [<message>]'."""
104 return Commit(hash=parts[0], message=parts[1] if len(parts) > 1 else "")
107 return f"Commit('{self.hash[:8]}', '{self.message}')"
110 return f"{self.hash[:8]} {self.message}"
113 def is_doc_only_commit(commit: Commit) -> bool: argument
114 """Returns True if the commit only touched "documentation files"."""
116 def is_doc_file(path: str) -> bool:
127 # the commit, relative to the root of the repo.
128 lines = run_git(["diff-tree", "--name-only", "-r", commit.hash])
131 non_doc_files = all_files - doc_files
136 f"{repr(commit)} touches {len(non_doc_files)} non-doc files, "
143 def print_wrapped(text: str, width: int = 80) -> None:
148 print("\n ".join(textwrap.wrap(text, width=width - 4, break_on_hyphens=False)))
151 def parse_args() -> argparse.Namespace:
156 "--main",
162 "--release",
168 "-v",
169 "--verbose",
172 help="Log extra output. Specify more times (-vv) for more output.",
186 # branch. Each hash is preceded by `+ ` if the commit has not been cherry
187 # picked onto the release branch, or `- ` if it has.
190 f"Commits on '{main_branch}' that have already been cherry-picked into '{release_branch}':"
193 print("- <none>")
196 commit = Commit.from_line(line[2:])
198 candidate_commits.append(commit)
199 elif line.startswith("- "):
200 print(f"- {commit}")
203 # Filter out and print the commits that touch non-documentation files.
205 f"Will not pick these commits on '{main_branch}' that touch non-documentation files:"
208 print("- <none>")
210 for commit in candidate_commits:
211 if is_doc_only_commit(commit):
212 doc_only_commits.append(commit)
214 print(f"- {commit}")
217 # Print the commits to cherry-pick.
220 + f"will be cherry-picked into '{release_branch}':"
223 print("- <none>")
224 for commit in doc_only_commits:
225 print(f"- {commit}")
228 # Print instructions for cherry-picking the commits.
232 branch_name = "cherrypick-" + release_branch.replace("/", "-") + "-" + suffix
239 # still copy-pasteable.
240 "git cherry-pick \\\n "
241 + " \\\n ".join([commit.hash for commit in doc_only_commits])
243 print(f"git checkout -b {branch_name}")
246 print("To verify that this worked, re-run this script with the arguments:")
248 print(f"--main={main_branch} --release={branch_name}")
250 print("It should show no doc-only commits to cherry-pick.")
254 print(f"git push --set-upstream origin {branch_name}")
265 "It looks like there are no doc-only commits "
266 + f"on '{main_branch}' to cherry-pick into '{release_branch}'."