-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88b8f3e
commit a332315
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
auto-find-moved-or-renamed/find_moved_or_renamed_commit_batch.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <BATCH_FILE> | ||
# | ||
# 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 <BATCH_FILE>" | ||
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" |