@@ -59,8 +59,8 @@ check_file_for_pg_changes() {
5959 local file=$1
6060 local diff_output=$( git diff $BASE_COMMIT ..$HEAD_COMMIT -- " $file " )
6161
62- # Check if file contains PG_REGISTER ( in either old or new version)
63- if ! echo " $diff_output " | grep -q " PG_REGISTER" ; then
62+ # Check if file contains PG_REGISTER in current version
63+ if ! git show $HEAD_COMMIT : " $file " 2> /dev/null | grep -q " PG_REGISTER" ; then
6464 return 0
6565 fi
6666
@@ -93,53 +93,75 @@ check_file_for_pg_changes() {
9393
9494 echo " 📋 Found: $struct_type (version $version )"
9595
96- # Check if this struct's typedef was modified
96+ # Check if this struct's typedef was modified in ANY changed file
9797 local struct_pattern=" typedef struct ${struct_type% _t} _s"
98- # Isolate struct body from diff, remove comments and empty lines, then check for remaining changes
99- local struct_body_diff=$( echo " $diff_output " | sed -n " /${struct_pattern} /,/\}.*${struct_type} ;/p" )
98+ local struct_body_diff=" "
99+ local struct_found_in=" "
100+
101+ # Search all changed files for this struct definition
102+ while IFS= read -r changed_file; do
103+ [ -z " $changed_file " ] && continue
104+
105+ local file_diff=$( git diff $BASE_COMMIT ..$HEAD_COMMIT -- " $changed_file " )
106+ local struct_in_file=$( echo " $file_diff " | sed -n " /${struct_pattern} /,/\}.*${struct_type} ;/p" )
107+
108+ if [ -n " $struct_in_file " ]; then
109+ struct_body_diff=" $struct_in_file "
110+ struct_found_in=" $changed_file "
111+ echo " 🔍 Found struct definition in $changed_file "
112+ break
113+ fi
114+ done <<< " $CHANGED_FILES"
115+
100116 local struct_changes=$( echo " $struct_body_diff " | grep -E " ^[-+]" \
101117 | grep -v -E " ^[-+]\s*(typedef struct|}|//|\*)" \
102118 | sed -E ' s://.*$::' \
103119 | sed -E ' s:/\*.*\*/::' \
104120 | tr -d ' [:space:]' )
105121
106122 if [ -n " $struct_changes " ]; then
107- echo " ⚠️ Struct definition modified"
123+ echo " ⚠️ Struct definition modified in $struct_found_in "
108124
109- # Check if version was incremented in this diff
125+ # Check if version was incremented in PG_REGISTER
110126 local old_version=$( echo " $diff_output " | grep " ^-.*PG_REGISTER.*$struct_type " | grep -oP ' ,\s*\K\d+(?=\s*\))' || echo " " )
111127 local new_version=$( echo " $diff_output " | grep " ^+.*PG_REGISTER.*$struct_type " | grep -oP ' ,\s*\K\d+(?=\s*\))' || echo " " )
112128
129+ # Find line number of PG_REGISTER for error reporting
130+ local line_num=$( git show $HEAD_COMMIT :" $file " | grep -n " PG_REGISTER.*$struct_type " | cut -d: -f1 | head -1)
131+
113132 if [ -n " $old_version " ] && [ -n " $new_version " ]; then
133+ # PG_REGISTER was modified - check if version increased
114134 if [ " $new_version " -le " $old_version " ]; then
115135 echo " ❌ Version NOT incremented ($old_version → $new_version )"
116-
117- # Find line number of PG_REGISTER
118- local line_num=$( git show $HEAD_COMMIT :" $file " | grep -n " PG_REGISTER.*$struct_type " | cut -d: -f1 | head -1)
119-
120- # Add to issues list
121136 cat >> $ISSUES_FILE << EOF
122137### \` $struct_type \` ($file :$line_num )
123- - **Struct modified:** Field changes detected
138+ - **Struct modified:** Field changes detected in $struct_found_in
124139- **Version status:** ❌ Not incremented (version $version )
125- - **Recommendation:** Review changes and increment version if needed
140+ - **Recommendation:** Increment version from $old_version to $(( $old_version + 1 ))
126141
127142EOF
128143 else
129144 echo " ✅ Version incremented ($old_version → $new_version )"
130145 fi
131- elif [ -z " $old_version " ] || [ -z " $new_version " ]; then
132- # Couldn't determine version change, but struct was modified
133- echo " ⚠️ Could not determine if version was incremented"
134-
135- local line_num=$( git show $HEAD_COMMIT :" $file " | grep -n " PG_REGISTER.*$struct_type " | cut -d: -f1 | head -1)
146+ elif [ -z " $old_version " ] && [ -z " $new_version " ]; then
147+ # PG_REGISTER wasn't modified but struct was - THIS IS THE BUG!
148+ echo " ❌ PG_REGISTER not modified, version still $version "
149+ cat >> $ISSUES_FILE << EOF
150+ ### \` $struct_type \` ($file :$line_num )
151+ - **Struct modified:** Field changes detected in $struct_found_in
152+ - **Version status:** ❌ Not incremented (still version $version )
153+ - **Recommendation:** Increment version to $(( $version + 1 )) in $file
136154
155+ EOF
156+ else
157+ # One exists but not the other - unusual edge case
158+ echo " ⚠️ Unusual version change pattern detected"
137159 cat >> $ISSUES_FILE << EOF
138160### \` $struct_type \` ($file :$line_num )
139- - **Struct modified:** Field changes detected
140- - **Version status:** ⚠️ Unable to verify version increment
161+ - **Struct modified:** Field changes detected in $struct_found_in
162+ - **Version status:** ⚠️ Unusual change pattern (old: ${old_version :- none} , new: ${new_version :- none} )
141163- **Current version:** $version
142- - **Recommendation:** Verify version was incremented if struct layout changed
164+ - **Recommendation:** Manually verify version increment
143165
144166EOF
145167 fi
@@ -150,11 +172,46 @@ EOF
150172 done <<< " $pg_registers"
151173}
152174
153- # Check each changed file
175+ # Build list of files to check (changed files + companions with PG_REGISTER)
176+ echo " 🔍 Building file list including companions with PG_REGISTER..."
177+ FILES_TO_CHECK=" "
178+ ALREADY_ADDED=" "
179+
154180while IFS= read -r file; do
155- check_file_for_pg_changes " $file "
181+ [ -z " $file " ] && continue
182+
183+ # Add this file to check list
184+ if ! echo " $ALREADY_ADDED " | grep -qw " $file " ; then
185+ FILES_TO_CHECK=" $FILES_TO_CHECK$file " $' \n '
186+ ALREADY_ADDED=" $ALREADY_ADDED $file "
187+ fi
188+
189+ # Determine companion file (.c <-> .h)
190+ local companion=" "
191+ if [[ " $file " == * .c ]]; then
192+ companion=" ${file% .c} .h"
193+ elif [[ " $file " == * .h ]]; then
194+ companion=" ${file% .h} .c"
195+ fi
196+
197+ # If companion exists and contains PG_REGISTER, add it to check list
198+ if [ -n " $companion " ]; then
199+ if git show $HEAD_COMMIT :" $companion " 2> /dev/null | grep -q " PG_REGISTER" ; then
200+ if ! echo " $ALREADY_ADDED " | grep -qw " $companion " ; then
201+ echo " 📎 Adding $companion (companion of $file with PG_REGISTER)"
202+ FILES_TO_CHECK=" $FILES_TO_CHECK$companion " $' \n '
203+ ALREADY_ADDED=" $ALREADY_ADDED $companion "
204+ fi
205+ fi
206+ fi
156207done <<< " $CHANGED_FILES"
157208
209+ # Check each file (including companions)
210+ while IFS= read -r file; do
211+ [ -z " $file " ] && continue
212+ check_file_for_pg_changes " $file "
213+ done <<< " $FILES_TO_CHECK"
214+
158215# Check if any issues were found
159216if [ -s $ISSUES_FILE ]; then
160217 echo " "
0 commit comments