|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Script to find kernel: commits from the latest git subtree squashed merge |
| 4 | +# |
| 5 | +# This script automatically detects the latest squashed subtree merge commit, |
| 6 | +# extracts the commit range from the squash message, then finds all kernel: |
| 7 | +# prefixed commits in that range. |
| 8 | +# |
| 9 | +# Usage: ./check_subtree_kernel_commits.sh |
| 10 | +# |
| 11 | +# The script looks for squashed subtree merges in: libbitcoinkernel-sys/bitcoin |
| 12 | + |
| 13 | +set -e |
| 14 | + |
| 15 | +# Color codes |
| 16 | +RED='\033[0;31m' |
| 17 | +GREEN='\033[0;32m' |
| 18 | +YELLOW='\033[1;33m' |
| 19 | +BLUE='\033[0;34m' |
| 20 | +NC='\033[0m' # No Color |
| 21 | + |
| 22 | +# Hardcoded subtree directory |
| 23 | +SUBTREE_DIR="libbitcoinkernel-sys/bitcoin" |
| 24 | +# Hardcoded github url |
| 25 | +GITHUB_URL="https://github.com/bitcoin/bitcoin" |
| 26 | + |
| 27 | + |
| 28 | +# Check if we're in a git repository |
| 29 | +if ! git rev-parse --git-dir > /dev/null 2>&1; then |
| 30 | + echo -e "${RED}Error: Not in a git repository${NC}" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Function to extract subtree upstream commit from a merge commit |
| 35 | +extract_upstream_commit() { |
| 36 | + local commit_hash="$1" |
| 37 | + local commit_msg |
| 38 | + commit_msg=$(git log -1 --format=%B "$commit_hash") |
| 39 | + |
| 40 | + # Extract from squashed format: "Squashed 'path/' changes from START..END" |
| 41 | + # Extract the END part after ".." |
| 42 | + local upstream |
| 43 | + upstream=$(echo "$commit_msg" | sed -n "s/.*Squashed.*changes from [0-9a-f]\{12\}\.\.\([0-9a-f]\{12\}\).*/\1/p") |
| 44 | + |
| 45 | + echo "$upstream" |
| 46 | +} |
| 47 | + |
| 48 | +# Function to extract previous upstream commit from squashed merge |
| 49 | +extract_previous_upstream() { |
| 50 | + local commit_hash="$1" |
| 51 | + local commit_msg |
| 52 | + commit_msg=$(git log -1 --format=%B "$commit_hash") |
| 53 | + |
| 54 | + # Extract from squashed format: "Squashed 'path/' changes from START..END" |
| 55 | + # Extract the START part before ".." |
| 56 | + local previous |
| 57 | + previous=$(echo "$commit_msg" | sed -n "s/.*Squashed.*changes from \([0-9a-f]\{12\}\)\.\..*/\1/p") |
| 58 | + |
| 59 | + echo "$previous" |
| 60 | +} |
| 61 | + |
| 62 | +# Function to get kernel commits in a range |
| 63 | +get_kernel_commits() { |
| 64 | + local start_commit="$1" |
| 65 | + local end_commit="$2" |
| 66 | + |
| 67 | + git log "${start_commit}..${end_commit}" --grep="^kernel:" -i --oneline --no-merges 2>/dev/null || true |
| 68 | +} |
| 69 | + |
| 70 | +# Function to display kernel commits with details |
| 71 | +display_kernel_commits() { |
| 72 | + local commits="$1" |
| 73 | + |
| 74 | + if [ -z "$commits" ]; then |
| 75 | + echo -e "${RED}No commits found with 'kernel:' prefix${NC}" |
| 76 | + return |
| 77 | + fi |
| 78 | + |
| 79 | + local count |
| 80 | + count=$(echo "$commits" | wc -l) |
| 81 | + echo -e "${GREEN}Found ${count} commit(s) with 'kernel:' prefix${NC}" |
| 82 | + echo "" |
| 83 | + |
| 84 | + echo "$commits" | while IFS= read -r line; do |
| 85 | + local commit_hash |
| 86 | + commit_hash=$(echo "$line" | awk '{print $1}') |
| 87 | + |
| 88 | + echo -e "${YELLOW}Commit: ${commit_hash}${NC}" |
| 89 | + |
| 90 | + # Get full commit message |
| 91 | + local full_message |
| 92 | + full_message=$(git log -1 --format=%B "$commit_hash") |
| 93 | + echo "Message: $full_message" |
| 94 | + |
| 95 | + # Get author and date |
| 96 | + local author |
| 97 | + author=$(git log -1 --format="%an" "$commit_hash") |
| 98 | + local date |
| 99 | + date=$(git log -1 --format="%ad" --date=short "$commit_hash") |
| 100 | + echo "Author: $author" |
| 101 | + echo "Date: $date" |
| 102 | + |
| 103 | + # Show files changed |
| 104 | + echo "Files changed:" |
| 105 | + git show --name-only --format="" "$commit_hash" | sed 's/^/ /' |
| 106 | + |
| 107 | + echo "" |
| 108 | + echo "---" |
| 109 | + echo "" |
| 110 | + done |
| 111 | + |
| 112 | + echo "" |
| 113 | + echo -e "${GREEN}Total: ${count} kernel-related commit(s)${NC}" |
| 114 | +} |
| 115 | + |
| 116 | +# Function to check merge |
| 117 | +check_merge() { |
| 118 | + local merge_commit="$1" |
| 119 | + |
| 120 | + echo -e "${BLUE}Checking merge commit ${merge_commit:0:8}...${NC}" |
| 121 | + |
| 122 | + # Extract the upstream commit from the merge |
| 123 | + local upstream_commit |
| 124 | + upstream_commit=$(extract_upstream_commit "$merge_commit") |
| 125 | + |
| 126 | + # Extract the previous upstream commit from the merge |
| 127 | + local previous_upstream |
| 128 | + previous_upstream=$(extract_previous_upstream "$merge_commit") |
| 129 | + |
| 130 | + local compare_url="${GITHUB_URL}/compare/${previous_upstream}...${upstream_commit}" |
| 131 | + |
| 132 | + |
| 133 | + # Display range info |
| 134 | + local merge_date |
| 135 | + merge_date=$(git log -1 --format="%ai" "$merge_commit") |
| 136 | + echo "" |
| 137 | + echo -e "${GREEN}=== Subtree Merge Information ===${NC}" |
| 138 | + echo "Merge commit: ${merge_commit}" |
| 139 | + echo "Merge date: $merge_date" |
| 140 | + echo "Previous upstream: ${previous_upstream:0:8}" |
| 141 | + echo "New upstream: ${upstream_commit:0:8}" |
| 142 | + echo "Range: ${previous_upstream:0:8}..${upstream_commit:0:8}" |
| 143 | + echo "" |
| 144 | + echo -e "${BLUE}GitHub Compare:${NC}" |
| 145 | + echo "$compare_url" |
| 146 | + echo "" |
| 147 | + |
| 148 | + # Get kernel commits |
| 149 | + local kernel_commits |
| 150 | + kernel_commits=$(get_kernel_commits "$previous_upstream" "$upstream_commit") |
| 151 | + |
| 152 | + # Display results |
| 153 | + display_kernel_commits "$kernel_commits" |
| 154 | +} |
| 155 | + |
| 156 | +# Main execution |
| 157 | +echo -e "${BLUE}Finding latest subtree merge for ${SUBTREE_DIR}...${NC}" |
| 158 | + |
| 159 | +# Get the latest squashed merge commit |
| 160 | +MERGE_COMMIT=$(git log -1 --format=%H --grep="Squashed.*'${SUBTREE_DIR}/'.*changes from") |
| 161 | + |
| 162 | +if [ -z "$MERGE_COMMIT" ]; then |
| 163 | + echo -e "${RED}No subtree merge found for ${SUBTREE_DIR}${NC}" |
| 164 | + exit 1 |
| 165 | +fi |
| 166 | + |
| 167 | +check_merge "$MERGE_COMMIT" |
0 commit comments