]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
dropped_commits: track git ranges rather than re-doing work
authorSasha Levin <sashal@kernel.org>
Mon, 4 Nov 2024 11:06:40 +0000 (06:06 -0500)
committerSasha Levin <sashal@kernel.org>
Mon, 4 Nov 2024 13:48:37 +0000 (08:48 -0500)
Signed-off-by: Sasha Levin <sashal@kernel.org>
scripts/dropped_commits
scripts/dropped_commits.sh

index a40c18727beba9c563b3a6c2ce355fac2fc434d0..f9f7ea5272460d240662f29ee3b0582e19a3f42a 100644 (file)
 4.19 0a75bd58f00b827008645f516b08b7fe63c21555
 4.19 0a3bcd478972b202206fd8a250d58e99e57501fd
 4.19 0a1f7a6d7f25d840f88e3fa256ec7b2cf31288d1
-0e713d1416cdd1d2329f2bcebe20138edba624a1
+64d6a383527ecd89b2dc9e3f00da28d6d9c33c5b
index da5c2b73b698f1c11a87d2b8d82dbbfbeaa6b576..7fdcd9e9744d6df34798467d1a02b6fbb2a0e78e 100755 (executable)
@@ -24,13 +24,9 @@ is_readded() {
     local ver="$1"
     local upstream_id="$2"
     
-    # Look for any file in releases/{ver}.* that contains the upstream id
-    while read -r file; do
-        if grep -q "$upstream_id" "$file" 2>/dev/null; then
-            return 0  # Found a match
-        fi
-    done < <(find "releases" -type f -path "releases/${ver}.*" 2>/dev/null)
-    return 1  # No match found
+    # Direct grep on releases/${ver}.* pattern
+    grep -q "$upstream_id" releases/${ver}.* 2>/dev/null
+    return $?
 }
 
 # Function to check if entry already exists in dropped_commits
@@ -43,6 +39,37 @@ is_known_drop() {
     return $?
 }
 
+# Function to get the commit range to process
+get_commit_range() {
+    local dropped_commits="$1"
+    
+    if [ ! -f "$dropped_commits" ] || [ ! -s "$dropped_commits" ]; then
+        echo "Processing full history" >&2
+        echo ""  # Return empty string to indicate full history
+        return 0
+    fi
+    
+    # Get the last line and trim whitespace
+    last_line=$(tail -n 1 "$dropped_commits" | tr -d '[:space:]')
+    
+    # Check if last_line is empty
+    if [ -z "$last_line" ]; then
+        echo "Last line is empty, processing full history" >&2
+        echo ""
+        return 0
+    fi
+    
+    # Check if the last line is a valid commit
+    if echo "$last_line" | grep -qE '^[0-9a-f]{40}$' && git rev-parse --verify "$last_line^{commit}" >/dev/null 2>&1; then
+        echo "Processing commits from $last_line..HEAD" >&2
+        echo "$last_line..HEAD"
+        return 0
+    fi
+    
+    echo "Last line is not a valid commit, processing full history" >&2
+    echo ""
+}
+
 # Function to process a single commit
 process_commit() {
     local ver="$1"
@@ -50,6 +77,9 @@ process_commit() {
     local tmpfile="$3"
     local dropped_commits="$4"
     
+    # Skip empty commits
+    [ -z "$commit" ] && return
+    
     # Get the files deleted in this commit
     git show --diff-filter=D --name-only --pretty="" "$commit" -- "queue-${ver}" | \
     while IFS= read -r file; do
@@ -93,6 +123,9 @@ process_repo() {
     mkdir -p scripts
     touch "$dropped_commits"
     
+    # Get commit range to process
+    local commit_range=$(get_commit_range "$dropped_commits")
+    
     # Process versions and collect new entries
     exec 3>"$tmpfile"
     while IFS= read -r ver; do
@@ -101,8 +134,16 @@ process_repo() {
         
         echo "Processing version $ver..." >&2
         
-        # Get all commits that deleted files
-        commits=$(git log --diff-filter=D --format="%H" -- "queue-${ver}")
+        # Get all commits that deleted files - commit range before --
+        local git_log_cmd="git log --diff-filter=D --format=%H"
+        if [ -n "$commit_range" ]; then
+            git_log_cmd="$git_log_cmd $commit_range"
+        fi
+        git_log_cmd="$git_log_cmd -- queue-${ver}"
+        
+        # Execute git log and ensure non-empty output
+        commits=$(eval "$git_log_cmd") || continue
+        [ -z "$commits" ] && continue
         
         # Process commits in parallel
         echo "$commits" | \
@@ -114,9 +155,15 @@ process_repo() {
     
     # Create new sorted file with unique entries
     {
-        cat "$dropped_commits"
+        if [ -s "$dropped_commits" ]; then
+            # Keep all but the last line (old commit hash)
+            head -n -1 "$dropped_commits"
+        fi
         cat "$tmpfile"
-    } | sort -V -k1,1 -k2,2 | uniq > "${tmpfile}.sorted"
+    } | sort -rV -k1,1 -k2,2 | uniq > "${tmpfile}.sorted"
+    
+    # Add current HEAD commit as the last line
+    git rev-parse HEAD >> "${tmpfile}.sorted"
     
     # Only update if there are changes
     if ! cmp -s "${tmpfile}.sorted" "$dropped_commits"; then