From a3323158e708a9a932122f98b19079745d33c6ca Mon Sep 17 00:00:00 2001 From: Mingyu Li Date: Wed, 11 Dec 2024 02:05:56 -0600 Subject: [PATCH] add batch script --- .../find_moved_or_renamed_commit_batch.sh | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh diff --git a/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh b/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh new file mode 100644 index 00000000..ff076a15 --- /dev/null +++ b/auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# This script takes a batch of (FUNCTION_NAME, FILENAME, START_COMMIT) sets from a file +# and identifies the commit where each function was modified. + +# Usage: +# ./find_moved_or_renamed_commit.sh +# +# The batch file should have one set of parameters per line, in the following format: +# FUNCTION_NAME FILENAME START_COMMIT + +BATCH_FILE="$1" + +if [ -z "$BATCH_FILE" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ ! -f "$BATCH_FILE" ]; then + echo "Error: File '$BATCH_FILE' not found!" + exit 1 +fi + +# Ensure we're in the root directory of the repository +cd "$(git rev-parse --show-toplevel)" || exit 1 + +echo "Processing batch input from $BATCH_FILE ..." +echo + +while IFS= read -r line; do + # Skip empty lines or lines starting with '#' + if [[ -z "$line" || "$line" =~ ^# ]]; then + continue + fi + + # Extract parameters from line + FUNCTION_NAME=$(echo "$line" | awk '{print $1}') + FILENAME=$(echo "$line" | awk '{print $2}') + START_COMMIT=$(echo "$line" | awk '{print $3}') + + if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then + echo "Skipping malformed line: $line" + continue + fi + + echo "----------------------------------------" + echo "Checking for function renames or file renames/moves for:" + echo "FUNCTION_NAME: $FUNCTION_NAME" + echo "FILENAME: $FILENAME" + echo "START_COMMIT: $START_COMMIT" + echo "----------------------------------------" + + METHOD_REGEX="(public|protected|private|static|\\s)+\\s+.*\\s+$FUNCTION_NAME\\s*\\(.*\\)" + + git log "$START_COMMIT"..HEAD \ + --follow \ + --find-renames \ + -G"$METHOD_REGEX" \ + -p \ + --name-status \ + --reverse \ + --color \ + --decorate \ + -- "$FILENAME" | less -R + + echo +done < "$BATCH_FILE"