From 88b8f3efc88e0964b214c8eda74f26d3bebcafba Mon Sep 17 00:00:00 2001 From: Mingyu Li Date: Tue, 3 Dec 2024 02:19:55 -0600 Subject: [PATCH 1/4] find_moved_or_renamed_commit --- .../find_moved_or_renamed_commit.sh | 38 +++++++++++++++++ auto-find-moved-or-renamed/readme.md | 41 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh create mode 100644 auto-find-moved-or-renamed/readme.md diff --git a/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh new file mode 100755 index 000000000..0a6c50425 --- /dev/null +++ b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# This script identifies the commit where a specified function was modified, +# starting from a given commit, and handles cases where the function or file +# might have been renamed or moved. + +# Usage: +# ./find_moved_or_renamed_commit.sh + +# Parameters: +FUNCTION_NAME="$1" +FILENAME="$2" # Relative Path +START_COMMIT="$3" + +if [ -z "$FUNCTION_NAME" ] || [ -z "$FILENAME" ] || [ -z "$START_COMMIT" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Ensure we're in the root directory of the repository +cd "$(git rev-parse --show-toplevel)" + +METHOD_REGEX="(public|protected|private|static|\s)+\s+.*\s+$FUNCTION_NAME\s*\(.*\)" + +echo "Checking for function renames or file renames/moves..." + +# Track file renames: See commits where the file was renamed. +# Track function changes: See commits where the function was modified, or removed. +git log "$START_COMMIT"..HEAD \ + --follow \ + --find-renames \ + -G"$METHOD_REGEX" \ + -p \ + --name-status \ + --reverse \ + --color \ + --decorate \ + -- "$FILENAME" | less -R \ No newline at end of file diff --git a/auto-find-moved-or-renamed/readme.md b/auto-find-moved-or-renamed/readme.md new file mode 100644 index 000000000..c8070fc56 --- /dev/null +++ b/auto-find-moved-or-renamed/readme.md @@ -0,0 +1,41 @@ +# Overview +This automation script is designed to identify the specific commit that moved or renamed a test function or test file from the ones recorded in the IDOFT repository. + +# Instructions +1. Copy and paste `find_moved_or_renamed_commit.sh` to the Repo you are working on. +2. `git checkout xxx` (replace xxx with the commit hash that the flake test was detected in IDOFT) +3. Find and copy the **Relative Path** of the given testing file, it should contain the given FUNCTION_NAME. (Paste it somewhere, this is the FILENAME that will be used later) +4. `git checkout master` (or whichever branch you want that has the latest commit) +5. Execute the script by running: + +``` bash +chmod +x find_moved_or_renamed_commit.sh` +./find_moved_or_renamed_commit.sh +``` + +## Examples + +### A Row in IDOFT +``` +https://github.com/apache/ignite-3,a1aa7fd4e2398c72827777ec5417d67915ff4da3,modules/configuration,org.apache.ignite.internal.configuration.asm.ConfigurationAsmGeneratorTest.testConstructInternalConfig,ID,MovedOrRenamed,,https://github.com/apache/ignite-3/commit/b48ddcba7cd2bd3b9a053ae131c25b44a0400e27 +``` + +### Execute +``` +./find_moved_or_renamed_commit.sh testConstructInternalConfig modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java a1aa7fd4e2398c72827777ec5417d67915ff4da3 +``` + +### Output +``` +commit b48ddcba7cd2bd3b9a053ae131c25b44a0400e27 +Author: Aleksandr Pakhomov +Date: Wed Apr 26 20:02:34 2023 +0400 + + IGNITE-19152 Use schema information in LocalFileConfigurationStorage (#1988) + + --------- + + Co-authored-by: Ivan Bessonov + +D modules/configuration/src/test/java/org/apache/ignite/internal/configuration/asm/ConfigurationAsmGeneratorTest.java +``` \ No newline at end of file From a3323158e708a9a932122f98b19079745d33c6ca Mon Sep 17 00:00:00 2001 From: Mingyu Li Date: Wed, 11 Dec 2024 02:05:56 -0600 Subject: [PATCH 2/4] 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 000000000..ff076a15d --- /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" From 95c7fcef465cb667b9f3aae8e41dc5134535aeaa Mon Sep 17 00:00:00 2001 From: Mingyu Li Date: Wed, 11 Dec 2024 02:30:02 -0600 Subject: [PATCH 3/4] update --- .../find_moved_or_renamed_commit_batch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index ff076a15d..4f900d5af 100644 --- 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 @@ -4,7 +4,7 @@ # and identifies the commit where each function was modified. # Usage: -# ./find_moved_or_renamed_commit.sh +# ./find_moved_or_renamed_commit_batch.sh # # The batch file should have one set of parameters per line, in the following format: # FUNCTION_NAME FILENAME START_COMMIT From 6190a98e968e89b640fc19bdd9b2484ff62fc6ae Mon Sep 17 00:00:00 2001 From: Mingyu Li Date: Wed, 11 Dec 2024 02:35:46 -0600 Subject: [PATCH 4/4] output to a file --- .../find_moved_or_renamed_commit.sh | 2 +- .../find_moved_or_renamed_commit_batch.sh | 29 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh index 0a6c50425..5e05df7a4 100755 --- a/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh +++ b/auto-find-moved-or-renamed/find_moved_or_renamed_commit.sh @@ -35,4 +35,4 @@ git log "$START_COMMIT"..HEAD \ --reverse \ --color \ --decorate \ - -- "$FILENAME" | less -R \ No newline at end of file + -- "$FILENAME" > outputfile.log \ No newline at end of file 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 index 4f900d5af..759a40123 100644 --- 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 @@ -24,8 +24,11 @@ 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 +OUTPUT_FILE="batch_output.log" +> "$OUTPUT_FILE" # Clear the file at the start of each run + +echo "Processing batch input from $BATCH_FILE ..." | tee -a "$OUTPUT_FILE" +echo | tee -a "$OUTPUT_FILE" while IFS= read -r line; do # Skip empty lines or lines starting with '#' @@ -33,22 +36,22 @@ while IFS= read -r line; do continue fi - # Extract parameters from line + # Extract parameters from the 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" + echo "Skipping malformed line: $line" | tee -a "$OUTPUT_FILE" 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 "----------------------------------------" + echo "----------------------------------------" | tee -a "$OUTPUT_FILE" + echo "Checking for function renames or file renames/moves for:" | tee -a "$OUTPUT_FILE" + echo "FUNCTION_NAME: $FUNCTION_NAME" | tee -a "$OUTPUT_FILE" + echo "FILENAME: $FILENAME" | tee -a "$OUTPUT_FILE" + echo "START_COMMIT: $START_COMMIT" | tee -a "$OUTPUT_FILE" + echo "----------------------------------------" | tee -a "$OUTPUT_FILE" METHOD_REGEX="(public|protected|private|static|\\s)+\\s+.*\\s+$FUNCTION_NAME\\s*\\(.*\\)" @@ -61,7 +64,9 @@ while IFS= read -r line; do --reverse \ --color \ --decorate \ - -- "$FILENAME" | less -R + -- "$FILENAME" >> "$OUTPUT_FILE" - echo + echo | tee -a "$OUTPUT_FILE" done < "$BATCH_FILE" + +echo "All results have been logged to $OUTPUT_FILE." \ No newline at end of file