scripts/git-add-note.py |  115 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

New commits:
commit 760d10bf52431be5341b0adf0913d29f6d85cdfe
Author:     Xisco Fauli <[email protected]>
AuthorDate: Mon Jul 20 13:38:34 2026 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Jul 20 13:38:34 2026 +0200

    Add script to track commits from collaboraoffice/online via notes
    
    Change-Id: I9f8804ce1ef8fbd71353ac88bb2c863b53f0aa86

diff --git a/scripts/git-add-note.py b/scripts/git-add-note.py
new file mode 100755
index 00000000..ffc17e5f
--- /dev/null
+++ b/scripts/git-add-note.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python3
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at https://mozilla.org/MPL/2.0/.
+#
+
+"""
+Use this script to check which commits from collaboraoffice/online
+has been already cherry-picked
+"""
+
+from typing import List
+import subprocess
+import sys
+
+
+def from_pipe(argv: List[str]) -> str:
+    """Executes argv as a command and returns its stdout."""
+    result = subprocess.check_output(argv)
+    return result.strip().decode("utf-8")
+
+def get_change_id(git_cat_file: subprocess.Popen, hash_string: str) -> str:
+    """Looks up the change-id for a git hash."""
+    git_cat_file.stdin.write((hash_string + "
").encode("utf-8"))
+    git_cat_file.stdin.flush()
+    first_line = git_cat_file.stdout.readline().decode("utf-8")
+    size = first_line.strip().split(" ")[2]
+    commit_msg = git_cat_file.stdout.read(int(size)).decode("utf-8")
+    git_cat_file.stdout.readline()
+    for line in commit_msg.split("
"):
+        if "Change-Id:" in line:
+            return line
+    return ""
+
+def add_note(hash_string: str, msg: str) -> None:
+    """Call git notes add"""
+    subprocess.Popen(['git', 'notes', 'add', '-m', msg , hash_string], 
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    print("Adding \"" + msg + "\" to " + hash_string)
+
+def main() -> None:
+    merge_base = from_pipe(["git", "merge-base", "collaboraoffice/online", 
"master"])
+
+    to_change_ids = {}
+    to_hash_string = from_pipe(["git", "rev-list", merge_base + "..master"])
+
+    to_hashes = []
+    if to_hash_string:
+        to_hashes = to_hash_string.split("
")
+    git_cat_file = subprocess.Popen(['git', 'cat-file', '--batch'], 
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    for to_hash in to_hashes:
+        to_change_ids[get_change_id(git_cat_file, to_hash)] = to_hash
+
+    if sys.version_info >= (3, 7):
+        sys.stdout.reconfigure(encoding='utf-8')
+
+    from_hashes = []
+    buffer = from_pipe(["git", "rev-list", 
"e89689b011ac8ce0d3af910e7c0a5eeaa3bfe3a8..collaboraoffice/online"])
+    # If there are no commits, we want an empty list, not a list with one 
empty item.
+    if buffer:
+        from_hashes = buffer.split("
")
+
+    with open("not-cherry-picked-commits.txt", "w", encoding="utf-8") as f:
+        for from_hash in from_hashes:
+            note = ""
+            try:
+                note = subprocess.check_output(['git', 'notes', 'show', 
from_hash], stderr=subprocess.PIPE)
+            except subprocess.CalledProcessError:
+                pass
+
+            # nothing to do, there is already a note
+            if note:
+                continue
+
+            # It's already cherry-picked
+            changeid = get_change_id(git_cat_file, from_hash)
+            if changeid in to_change_ids:
+                add_note(from_hash, "Auto: cherry-picked in " + 
to_change_ids[changeid])
+                continue
+
+            changed_files = from_pipe(["git", "show", "--name-only", 
"--format=", from_hash])
+            bInEngine = False
+            bNotEngine = False
+            for changed_file in changed_files.split('
'):
+                if changed_file.startswith("engine/"):
+                    bInEngine = True
+                else:
+                    bNotEngine = True
+
+            if bNotEngine:
+                if not bInEngine:
+                    add_note(from_hash, "Auto: changes are not in engine/. No 
need to cherry-pick it")
+                else:
+                    add_note(from_hash, "Auto: COOL related commit. No need to 
cherry-pick it")
+                continue
+
+            pretty = from_pipe(["git", "--no-pager", "log", "-1", 
"--format=format:%h%x09%an%x09%s%x0a", from_hash])
+            if 'loplugin' in pretty:
+                add_note(from_hash, "Auto: loplugin commit. No need to 
cherry-pick it")
+                continue
+
+            if 'excludelist' in pretty:
+                add_note(from_hash, "Auto: excludelist commit. No need to 
cherry-pick it")
+                continue
+
+            f.write(pretty + "
")
+
+    git_cat_file.stdin.close()
+    git_cat_file.terminate()
+
+
+if __name__ == '__main__':
+    main()
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to