|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Script to generate a mapping of commit hashes to commit messages from the rl-tools submodule |
| 5 | + |
| 6 | +OUTPUT_FILE="commit_messages.json" |
| 7 | + |
| 8 | +echo "Generating commit message mapping from rl-tools submodule..." |
| 9 | + |
| 10 | +# Check if rl-tools directory exists |
| 11 | +if [ ! -d "rl-tools" ]; then |
| 12 | + echo "Error: rl-tools directory not found" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +# Use Python to properly escape JSON |
| 17 | +python3 << 'PYTHON_SCRIPT' > "${OUTPUT_FILE}" |
| 18 | +import subprocess |
| 19 | +import json |
| 20 | +import sys |
| 21 | +
|
| 22 | +try: |
| 23 | + # Get all commits from the rl-tools submodule |
| 24 | + result = subprocess.run( |
| 25 | + ['git', '-C', 'rl-tools', 'log', '--all', '--abbrev=7', '--pretty=format:%h%x00%s'], |
| 26 | + capture_output=True, |
| 27 | + text=True, |
| 28 | + check=True |
| 29 | + ) |
| 30 | + |
| 31 | + # Parse the output |
| 32 | + commits = {} |
| 33 | + for line in result.stdout.strip().split('\n'): |
| 34 | + if not line: |
| 35 | + continue |
| 36 | + parts = line.split('\x00', 1) |
| 37 | + if len(parts) == 2: |
| 38 | + hash_val, message = parts |
| 39 | + commits[hash_val] = message |
| 40 | + |
| 41 | + # Output as properly formatted JSON |
| 42 | + print(json.dumps(commits, indent=2, ensure_ascii=False)) |
| 43 | + |
| 44 | +except subprocess.CalledProcessError as e: |
| 45 | + print(f"Error running git command: {e}", file=sys.stderr) |
| 46 | + print("{}", file=sys.stdout) # Output empty JSON on error |
| 47 | + sys.exit(1) |
| 48 | +except Exception as e: |
| 49 | + print(f"Error: {e}", file=sys.stderr) |
| 50 | + print("{}", file=sys.stdout) # Output empty JSON on error |
| 51 | + sys.exit(1) |
| 52 | +PYTHON_SCRIPT |
| 53 | + |
| 54 | +# Count number of commits |
| 55 | +COMMIT_COUNT=$(grep -c '":' "${OUTPUT_FILE}" || echo "0") |
| 56 | + |
| 57 | +echo "Generated ${OUTPUT_FILE} with ${COMMIT_COUNT} commits" |
| 58 | +echo "File size: $(du -h ${OUTPUT_FILE} | cut -f1)" |
| 59 | + |
0 commit comments